summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2019-03-21 16:43:54 +0000
committerDouwe Maan <douwe@gitlab.com>2019-03-21 16:43:54 +0000
commit7d3c5d882c1ddb7a78241e326996f30d67fce4b8 (patch)
tree42dc69e644450a39fa700e3840a963bac438eec4
parent1bc4ee3f9a06a8d8fc70b97db90ca5e8e3434604 (diff)
parent8723f292552814cfe4566f213005e4e190fca456 (diff)
downloadgitlab-ce-7d3c5d882c1ddb7a78241e326996f30d67fce4b8.tar.gz
Merge branch '59147-duplicate-match-line' into 'master'
Fix duplicated bottom match line Closes #59147 See merge request gitlab-org/gitlab-ce!26402
-rw-r--r--app/serializers/diff_file_entity.rb2
-rw-r--r--changelogs/unreleased/59147-duplicate-match-line.yml5
-rw-r--r--lib/gitlab/diff/file.rb25
-rw-r--r--spec/lib/gitlab/diff/file_spec.rb7
4 files changed, 28 insertions, 11 deletions
diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb
index 13711070a46..066e30cd3bb 100644
--- a/app/serializers/diff_file_entity.rb
+++ b/app/serializers/diff_file_entity.rb
@@ -57,7 +57,7 @@ class DiffFileEntity < DiffFileBaseEntity
diff_file.diff_lines_for_serializer
end
- expose :is_fully_expanded, if: -> (diff_file, _) { Feature.enabled?(:expand_diff_full_file) && diff_file.text? } do |diff_file|
+ expose :is_fully_expanded, if: -> (diff_file, _) { Feature.enabled?(:expand_diff_full_file, default_enabled: true) && diff_file.text? } do |diff_file|
diff_file.fully_expanded?
end
diff --git a/changelogs/unreleased/59147-duplicate-match-line.yml b/changelogs/unreleased/59147-duplicate-match-line.yml
new file mode 100644
index 00000000000..378d2a40386
--- /dev/null
+++ b/changelogs/unreleased/59147-duplicate-match-line.yml
@@ -0,0 +1,5 @@
+---
+title: Fix duplicated bottom match line on merge request parallel diff view
+merge_request: 26402
+author:
+type: fixed
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index dbee47a19ee..dce80bf21de 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -158,7 +158,10 @@ module Gitlab
new_blob || old_blob
end
- attr_writer :highlighted_diff_lines
+ def highlighted_diff_lines=(value)
+ clear_memoization(:diff_lines_for_serializer)
+ @highlighted_diff_lines = value
+ end
# Array of Gitlab::Diff::Line objects
def diff_lines
@@ -314,19 +317,21 @@ module Gitlab
# This adds the bottom match line to the array if needed. It contains
# the data to load more context lines.
def diff_lines_for_serializer
- lines = highlighted_diff_lines
+ strong_memoize(:diff_lines_for_serializer) do
+ lines = highlighted_diff_lines
- return if lines.empty?
- return if blob.nil?
+ next if lines.empty?
+ next if blob.nil?
- last_line = lines.last
+ last_line = lines.last
- if last_line.new_pos < total_blob_lines(blob) && !deleted_file?
- match_line = Gitlab::Diff::Line.new("", 'match', nil, last_line.old_pos, last_line.new_pos)
- lines.push(match_line)
- end
+ if last_line.new_pos < total_blob_lines(blob) && !deleted_file?
+ match_line = Gitlab::Diff::Line.new("", 'match', nil, last_line.old_pos, last_line.new_pos)
+ lines.push(match_line)
+ end
- lines
+ lines
+ end
end
def fully_expanded?
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb
index 611c3e946ed..cc36060f864 100644
--- a/spec/lib/gitlab/diff/file_spec.rb
+++ b/spec/lib/gitlab/diff/file_spec.rb
@@ -72,6 +72,13 @@ describe Gitlab::Diff::File do
expect(diff_file.diff_lines_for_serializer.last.type).to eq('match')
end
+ context 'when called multiple times' do
+ it 'only adds bottom match line once' do
+ expect(diff_file.diff_lines_for_serializer.size).to eq(31)
+ expect(diff_file.diff_lines_for_serializer.size).to eq(31)
+ end
+ end
+
context 'when deleted' do
let(:commit) { project.commit('d59c60028b053793cecfb4022de34602e1a9218e') }
let(:diff_file) { commit.diffs.diff_file_with_old_path('files/js/commit.js.coffee') }