Commit 33e78f9e authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-gitaly-raw-changes' into 'master'

Client implementation GetRawChanges

See merge request gitlab-org/gitlab-ce!18693
parents 906d00ef 713c7fa9
...@@ -6,8 +6,16 @@ module Gitlab ...@@ -6,8 +6,16 @@ module Gitlab
attr_reader :blob_id, :blob_size, :old_path, :new_path, :operation attr_reader :blob_id, :blob_size, :old_path, :new_path, :operation
def initialize(raw_change) def initialize(raw_change)
if raw_change.is_a?(Gitaly::GetRawChangesResponse::RawChange)
@blob_id = raw_change.blob_id
@blob_size = raw_change.size
@old_path = raw_change.old_path.presence
@new_path = raw_change.new_path.presence
@operation = raw_change.operation&.downcase || :unknown
else
parse(raw_change) parse(raw_change)
end end
end
private private
......
...@@ -581,6 +581,13 @@ module Gitlab ...@@ -581,6 +581,13 @@ module Gitlab
# old_rev and new_rev are commit ID's # old_rev and new_rev are commit ID's
# the result of this method is an array of Gitlab::Git::RawDiffChange # the result of this method is an array of Gitlab::Git::RawDiffChange
def raw_changes_between(old_rev, new_rev) def raw_changes_between(old_rev, new_rev)
gitaly_migrate(:raw_changes_between) do |is_enabled|
if is_enabled
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 = [] result = []
circuit_breaker.perform do circuit_breaker.perform do
...@@ -595,6 +602,10 @@ module Gitlab ...@@ -595,6 +602,10 @@ module Gitlab
result result
end end
end
rescue ArgumentError => e
raise Gitlab::Git::Repository::GitError.new(e)
end
# Returns the SHA of the most recent common ancestor of +from+ and +to+ # Returns the SHA of the most recent common ancestor of +from+ and +to+
def merge_base(from, to) def merge_base(from, to)
......
...@@ -293,6 +293,12 @@ module Gitlab ...@@ -293,6 +293,12 @@ module Gitlab
response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request) response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request)
response.checksum.presence response.checksum.presence
end end
def raw_changes_between(from, to)
request = Gitaly::GetRawChangesRequest.new(repository: @gitaly_repo, from_revision: from, to_revision: to)
GitalyClient.call(@storage, :repository_service, :get_raw_changes, request)
end
end end
end end
end end
...@@ -1068,6 +1068,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1068,6 +1068,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
describe '#raw_changes_between' do describe '#raw_changes_between' do
shared_examples 'raw changes' do
let(:old_rev) { } let(:old_rev) { }
let(:new_rev) { } let(:new_rev) { }
let(:changes) { repository.raw_changes_between(old_rev, new_rev) } let(:changes) { repository.raw_changes_between(old_rev, new_rev) }
...@@ -1105,6 +1106,15 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1105,6 +1106,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
context 'when gitaly is enabled' do
it_behaves_like 'raw changes'
end
context 'when gitaly is disabled', :disable_gitaly do
it_behaves_like 'raw changes'
end
end
describe '#merge_base' do describe '#merge_base' do
shared_examples '#merge_base' do shared_examples '#merge_base' do
where(:from, :to, :result) do where(:from, :to, :result) do
......
...@@ -167,4 +167,15 @@ describe Gitlab::GitalyClient::RepositoryService do ...@@ -167,4 +167,15 @@ describe Gitlab::GitalyClient::RepositoryService do
client.create_from_snapshot('http://example.com?wiki=1', 'Custom xyz') client.create_from_snapshot('http://example.com?wiki=1', 'Custom xyz')
end end
end end
describe '#raw_changes_between' do
it 'sends a create_repository_from_snapshot message' do
expect_any_instance_of(Gitaly::RepositoryService::Stub)
.to receive(:get_raw_changes)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(double)
client.raw_changes_between('deadbeef', 'deadpork')
end
end
end end
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