diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 18:38:44 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 18:38:44 +0100 |
commit | 1764e1b7cb2bffb9b4c4a69991fe2c4d21ce5459 (patch) | |
tree | b48ca1bad0532a37a19f00f0903a778109a16a3d /app/models/note.rb | |
parent | e1bc808746523309476913033b104345c06c4816 (diff) | |
download | gitlab-ce-1764e1b7cb2bffb9b4c4a69991fe2c4d21ce5459.tar.gz |
Use Gitlab::Git::DiffCollections
Diffstat (limited to 'app/models/note.rb')
-rw-r--r-- | app/models/note.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index d287e0f3c6d..1a7b2ba6d42 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -131,9 +131,11 @@ class Note < ActiveRecord::Base end def find_diff - return nil unless noteable && noteable.diffs.present? + return nil unless noteable + return @diff if defined?(@diff) - @diff ||= noteable.diffs.find do |d| + # Don't use ||= because nil is a valid value for @diff + @diff = noteable.diffs(Commit.max_diff_options).find do |d| Digest::SHA1.hexdigest(d.new_path) == diff_file_index if d.new_path end end @@ -165,20 +167,16 @@ class Note < ActiveRecord::Base def active? return true unless self.diff return false unless noteable + return @active if defined?(@active) - noteable.diffs.each do |mr_diff| - next unless mr_diff.new_path == self.diff.new_path + diffs = noteable.diffs(Commit.max_diff_options) + notable_diff = diffs.find { |d| d.new_path == self.diff.new_path } - lines = Gitlab::Diff::Parser.new.parse(mr_diff.diff.lines.to_a) + return @active = false if notable_diff.nil? - lines.each do |line| - if line.text == diff_line - return true - end - end - end - - false + parsed_lines = Gitlab::Diff::Parser.new.parse(notable_diff.diff.each_line) + # We cannot use ||= because @active may be false + @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line } end def outdated? @@ -263,7 +261,7 @@ class Note < ActiveRecord::Base end def diff_lines - @diff_lines ||= Gitlab::Diff::Parser.new.parse(diff.diff.lines) + @diff_lines ||= Gitlab::Diff::Parser.new.parse(diff.diff.each_line) end def highlighted_diff_lines |