Raw changes calculation is Gitaly only now
Closes https://gitlab.com/gitlab-org/gitaly/issues/1138
This commit is contained in:
parent
7c11ed8c91
commit
2ac672280b
|
@ -529,32 +529,17 @@ module Gitlab
|
|||
def raw_changes_between(old_rev, new_rev)
|
||||
@raw_changes_between ||= {}
|
||||
|
||||
@raw_changes_between[[old_rev, new_rev]] ||= begin
|
||||
return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA
|
||||
@raw_changes_between[[old_rev, new_rev]] ||=
|
||||
begin
|
||||
return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA
|
||||
|
||||
gitaly_migrate(:raw_changes_between) do |is_enabled|
|
||||
if is_enabled
|
||||
wrapped_gitaly_errors do
|
||||
gitaly_repository_client.raw_changes_between(old_rev, new_rev)
|
||||
.each_with_object([]) do |msg, arr|
|
||||
msg.raw_changes.each { |change| arr << ::Gitlab::Git::RawDiffChange.new(change) }
|
||||
end
|
||||
else
|
||||
result = []
|
||||
|
||||
circuit_breaker.perform do
|
||||
Open3.pipeline_r(git_diff_cmd(old_rev, new_rev), format_git_cat_file_script, git_cat_file_cmd) do |last_stdout, wait_threads|
|
||||
last_stdout.each_line { |line| result << ::Gitlab::Git::RawDiffChange.new(line.chomp!) }
|
||||
|
||||
if wait_threads.any? { |waiter| !waiter.value&.success? }
|
||||
raise ::Gitlab::Git::Repository::GitError, "Unabled to obtain changes between #{old_rev} and #{new_rev}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
raise Gitlab::Git::Repository::GitError.new(e)
|
||||
end
|
||||
|
|
|
@ -1043,50 +1043,40 @@ describe Gitlab::Git::Repository, seed_helper: true do
|
|||
end
|
||||
|
||||
describe '#raw_changes_between' do
|
||||
shared_examples 'raw changes' do
|
||||
let(:old_rev) { }
|
||||
let(:new_rev) { }
|
||||
let(:changes) { repository.raw_changes_between(old_rev, new_rev) }
|
||||
let(:old_rev) { }
|
||||
let(:new_rev) { }
|
||||
let(:changes) { repository.raw_changes_between(old_rev, new_rev) }
|
||||
|
||||
context 'initial commit' do
|
||||
let(:old_rev) { Gitlab::Git::BLANK_SHA }
|
||||
let(:new_rev) { '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863' }
|
||||
context 'initial commit' do
|
||||
let(:old_rev) { Gitlab::Git::BLANK_SHA }
|
||||
let(:new_rev) { '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863' }
|
||||
|
||||
it 'returns the changes' do
|
||||
expect(changes).to be_present
|
||||
expect(changes.size).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid rev' do
|
||||
let(:old_rev) { 'foo' }
|
||||
let(:new_rev) { 'bar' }
|
||||
|
||||
it 'returns an error' do
|
||||
expect { changes }.to raise_error(Gitlab::Git::Repository::GitError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid revs' do
|
||||
let(:old_rev) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' }
|
||||
let(:new_rev) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
|
||||
|
||||
it 'returns the changes' do
|
||||
expect(changes.size).to eq(9)
|
||||
expect(changes.first.operation).to eq(:modified)
|
||||
expect(changes.first.new_path).to eq('.gitmodules')
|
||||
expect(changes.last.operation).to eq(:added)
|
||||
expect(changes.last.new_path).to eq('files/lfs/picture-invalid.png')
|
||||
end
|
||||
it 'returns the changes' do
|
||||
expect(changes).to be_present
|
||||
expect(changes.size).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when gitaly is enabled' do
|
||||
it_behaves_like 'raw changes'
|
||||
context 'with an invalid rev' do
|
||||
let(:old_rev) { 'foo' }
|
||||
let(:new_rev) { 'bar' }
|
||||
|
||||
it 'returns an error' do
|
||||
expect { changes }.to raise_error(Gitlab::Git::Repository::GitError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when gitaly is disabled', :disable_gitaly do
|
||||
it_behaves_like 'raw changes'
|
||||
context 'with valid revs' do
|
||||
let(:old_rev) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' }
|
||||
let(:new_rev) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
|
||||
|
||||
it 'returns the changes' do
|
||||
expect(changes.size).to eq(9)
|
||||
expect(changes.first.operation).to eq(:modified)
|
||||
expect(changes.first.new_path).to eq('.gitmodules')
|
||||
expect(changes.last.operation).to eq(:added)
|
||||
expect(changes.last.new_path).to eq('files/lfs/picture-invalid.png')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue