Commit 89a8c4f9 authored by Marc Shaw's avatar Marc Shaw

Use new and old paths instead of just the new path for diff batching

Issue: gitlab.com/gitlab-org/gitlab/-/issues/334273
MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/66873

Changelog: fixed
parent 6d4aa2d8
...@@ -395,10 +395,10 @@ class MergeRequestDiff < ApplicationRecord ...@@ -395,10 +395,10 @@ class MergeRequestDiff < ApplicationRecord
if comparison if comparison
if diff_options[:paths].blank? && !without_files? if diff_options[:paths].blank? && !without_files?
# Return the empty MergeRequestDiffBatch for an out of bound batch request # Return the empty MergeRequestDiffBatch for an out of bound batch request
break diffs_batch if diffs_batch.diff_file_paths.blank? break diffs_batch if diffs_batch.diff_paths.blank?
diff_options.merge!( diff_options.merge!(
paths: diffs_batch.diff_file_paths, paths: diffs_batch.diff_paths,
pagination_data: diffs_batch.pagination_data pagination_data: diffs_batch.pagination_data
) )
end end
......
...@@ -43,10 +43,16 @@ module Gitlab ...@@ -43,10 +43,16 @@ module Gitlab
end end
end end
# This is either the new path, otherwise the old path for the diff_file
def diff_file_paths def diff_file_paths
diff_files.map(&:file_path) diff_files.map(&:file_path)
end end
# This is both the new and old paths for the diff_file
def diff_paths
diff_files.map(&:paths).flatten.uniq
end
def pagination_data def pagination_data
@pagination_data || empty_pagination_data @pagination_data || empty_pagination_data
end end
......
...@@ -465,11 +465,13 @@ RSpec.describe MergeRequestDiff do ...@@ -465,11 +465,13 @@ RSpec.describe MergeRequestDiff do
it 'sorts diff files directory first' do it 'sorts diff files directory first' do
diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order
expect(diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options).diff_file_paths).to eq([ # There will be 11 returned, as we have to take into account for new and old paths
expect(diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options).diff_paths).to eq([
'bar/branch-test.txt', 'bar/branch-test.txt',
'custom-highlighting/test.gitlab-custom', 'custom-highlighting/test.gitlab-custom',
'encoding/iso8859.txt', 'encoding/iso8859.txt',
'files/images/wm.svg', 'files/images/wm.svg',
'files/js/commit.js.coffee',
'files/js/commit.coffee', 'files/js/commit.coffee',
'files/lfs/lfs_object.iso', 'files/lfs/lfs_object.iso',
'files/ruby/popen.rb', 'files/ruby/popen.rb',
...@@ -553,11 +555,12 @@ RSpec.describe MergeRequestDiff do ...@@ -553,11 +555,12 @@ RSpec.describe MergeRequestDiff do
it 'sorts diff files directory first' do it 'sorts diff files directory first' do
diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order
expect(diff_with_commits.diffs(diff_options).diff_file_paths).to eq([ expect(diff_with_commits.diffs(diff_options).diff_paths).to eq([
'bar/branch-test.txt', 'bar/branch-test.txt',
'custom-highlighting/test.gitlab-custom', 'custom-highlighting/test.gitlab-custom',
'encoding/iso8859.txt', 'encoding/iso8859.txt',
'files/images/wm.svg', 'files/images/wm.svg',
'files/js/commit.js.coffee',
'files/js/commit.coffee', 'files/js/commit.coffee',
'files/lfs/lfs_object.iso', 'files/lfs/lfs_object.iso',
'files/ruby/popen.rb', 'files/ruby/popen.rb',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment