diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-10-16 19:21:16 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-11-06 22:39:31 +0300 |
commit | ec66ef1b74fa431b18b23812a2a7cf881d1b98d8 (patch) | |
tree | 2d56631926261b642f79d4fcc1a3ce8e3d7c6844 /app/models/diff_note.rb | |
parent | 912741cfea06ead8dad95d20f2f0adb955a55732 (diff) |
Comment on any expanded diff line on MRs
Diffstat (limited to 'app/models/diff_note.rb')
-rw-r--r-- | app/models/diff_note.rb | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index 95694377fe3..80f49f151ee 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -64,6 +64,10 @@ class DiffNote < Note self.original_position.diff_refs == diff_refs end + def discussion_first_note? + self == discussion.first_note + end + private def enqueue_diff_file_creation_job @@ -76,26 +80,33 @@ class DiffNote < Note end def should_create_diff_file? - on_text? && note_diff_file.nil? && self == discussion.first_note + on_text? && note_diff_file.nil? && discussion_first_note? end def fetch_diff_file - if note_diff_file - diff = Gitlab::Git::Diff.new(note_diff_file.to_hash) - Gitlab::Diff::File.new(diff, - repository: project.repository, - diff_refs: original_position.diff_refs) - elsif created_at_diff?(noteable.diff_refs) - # We're able to use the already persisted diffs (Postgres) if we're - # presenting a "current version" of the MR discussion diff. - # So no need to make an extra Gitaly diff request for it. - # As an extra benefit, the returned `diff_file` already - # has `highlighted_diff_lines` data set from Redis on - # `Diff::FileCollection::MergeRequestDiff`. - noteable.diffs(original_position.diff_options).diff_files.first - else - original_position.diff_file(self.project.repository) - end + file = + if note_diff_file + diff = Gitlab::Git::Diff.new(note_diff_file.to_hash) + Gitlab::Diff::File.new(diff, + repository: project.repository, + diff_refs: original_position.diff_refs) + elsif created_at_diff?(noteable.diff_refs) + # We're able to use the already persisted diffs (Postgres) if we're + # presenting a "current version" of the MR discussion diff. + # So no need to make an extra Gitaly diff request for it. + # As an extra benefit, the returned `diff_file` already + # has `highlighted_diff_lines` data set from Redis on + # `Diff::FileCollection::MergeRequestDiff`. + noteable.diffs(original_position.diff_options).diff_files.first + else + original_position.diff_file(self.project.repository) + end + + # Since persisted diff files already have its content "unfolded" + # there's no need to make it pass through the unfolding process. + file&.unfold_diff_lines(position) unless note_diff_file + + file end def supported? |