diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-08-03 15:32:00 -0700 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-08-03 15:32:00 -0700 |
commit | 538e66d71c0f7125cc62ea51480668ba8b342544 (patch) | |
tree | d27f667dbe404ce406e2ac6b3a901b87ff93da47 /app/models/commit.rb | |
parent | 3ccb27c0c79ef92585a901de32339948319cf068 (diff) | |
parent | 8890376f0f72f713a7530bd7989e71442c69dc91 (diff) | |
download | gitlab-ce-538e66d71c0f7125cc62ea51480668ba8b342544.tar.gz |
Merge branch 'master' into diff-line-comment-vuejs
# Conflicts:
# app/models/discussion.rb
# db/schema.rb
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index f80f1063406..cc413448ce8 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -104,7 +104,7 @@ class Commit end def diff_line_count - @diff_line_count ||= Commit::diff_line_count(self.diffs) + @diff_line_count ||= Commit::diff_line_count(raw_diffs) @diff_line_count end @@ -123,15 +123,17 @@ class Commit # In case this first line is longer than 100 characters, it is cut off # after 80 characters and ellipses (`&hellp;`) are appended. def title - title = safe_message + full_title.length > 100 ? full_title[0..79] << "…" : full_title + end - return no_commit_message if title.blank? + # Returns the full commits title + def full_title + return @full_title if @full_title - title_end = title.index("\n") - if (!title_end && title.length > 100) || (title_end && title_end > 100) - title[0..79] << "…" + if safe_message.blank? + @full_title = no_commit_message else - title.split("\n", 2).first + @full_title = safe_message.split("\n", 2).first end end @@ -178,7 +180,18 @@ class Commit end def author - @author ||= User.find_by_any_email(author_email.downcase) + if RequestStore.active? + key = "commit_author:#{author_email.downcase}" + # nil is a valid value since no author may exist in the system + if RequestStore.store.has_key?(key) + @author = RequestStore.store[key] + else + @author = find_author_by_any_email + RequestStore.store[key] = @author + end + else + @author ||= find_author_by_any_email + end end def committer @@ -304,12 +317,24 @@ class Commit nil end + def raw_diffs(*args) + raw.diffs(*args) + end + + def diffs(diff_options = nil) + Gitlab::Diff::FileCollection::Commit.new(self, diff_options: diff_options) + end + private + def find_author_by_any_email + User.find_by_any_email(author_email.downcase) + end + def repo_changes changes = { added: [], modified: [], removed: [] } - diffs.each do |diff| + raw_diffs(deltas_only: true).each do |diff| if diff.deleted_file changes[:removed] << diff.old_path elsif diff.renamed_file || diff.new_file |