Merge branch 'gitaly-update-remote-mirror' into 'master'
Incorporate Gitaly's RemoteService.UpdateRemoteMirror RPC Closes gitaly#936 See merge request gitlab-org/gitlab-ce!16536
This commit is contained in:
commit
ae1358e483
3 changed files with 60 additions and 5 deletions
|
@ -6,7 +6,23 @@ module Gitlab
|
||||||
@ref_name = ref_name
|
@ref_name = ref_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(only_branches_matching: [], only_tags_matching: [])
|
def update(only_branches_matching: [])
|
||||||
|
@repository.gitaly_migrate(:remote_update_remote_mirror) do |is_enabled|
|
||||||
|
if is_enabled
|
||||||
|
gitaly_update(only_branches_matching)
|
||||||
|
else
|
||||||
|
rugged_update(only_branches_matching)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def gitaly_update(only_branches_matching)
|
||||||
|
@repository.gitaly_remote_client.update_remote_mirror(@ref_name, only_branches_matching)
|
||||||
|
end
|
||||||
|
|
||||||
|
def rugged_update(only_branches_matching)
|
||||||
local_branches = refs_obj(@repository.local_branches, only_refs_matching: only_branches_matching)
|
local_branches = refs_obj(@repository.local_branches, only_refs_matching: only_branches_matching)
|
||||||
remote_branches = refs_obj(@repository.remote_branches(@ref_name), only_refs_matching: only_branches_matching)
|
remote_branches = refs_obj(@repository.remote_branches(@ref_name), only_refs_matching: only_branches_matching)
|
||||||
|
|
||||||
|
@ -15,8 +31,8 @@ module Gitlab
|
||||||
|
|
||||||
delete_refs(local_branches, remote_branches)
|
delete_refs(local_branches, remote_branches)
|
||||||
|
|
||||||
local_tags = refs_obj(@repository.tags, only_refs_matching: only_tags_matching)
|
local_tags = refs_obj(@repository.tags)
|
||||||
remote_tags = refs_obj(@repository.remote_tags(@ref_name), only_refs_matching: only_tags_matching)
|
remote_tags = refs_obj(@repository.remote_tags(@ref_name))
|
||||||
|
|
||||||
updated_tags = changed_refs(local_tags, remote_tags)
|
updated_tags = changed_refs(local_tags, remote_tags)
|
||||||
@repository.push_remote_branches(@ref_name, updated_tags.keys) if updated_tags.present?
|
@repository.push_remote_branches(@ref_name, updated_tags.keys) if updated_tags.present?
|
||||||
|
@ -24,8 +40,6 @@ module Gitlab
|
||||||
delete_refs(local_tags, remote_tags)
|
delete_refs(local_tags, remote_tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def refs_obj(refs, only_refs_matching: [])
|
def refs_obj(refs, only_refs_matching: [])
|
||||||
refs.each_with_object({}) do |ref, refs|
|
refs.each_with_object({}) do |ref, refs|
|
||||||
next if only_refs_matching.present? && !only_refs_matching.include?(ref.name)
|
next if only_refs_matching.present? && !only_refs_matching.include?(ref.name)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
module GitalyClient
|
module GitalyClient
|
||||||
class RemoteService
|
class RemoteService
|
||||||
|
MAX_MSG_SIZE = 128.kilobytes.freeze
|
||||||
|
|
||||||
def initialize(repository)
|
def initialize(repository)
|
||||||
@repository = repository
|
@repository = repository
|
||||||
@gitaly_repo = repository.gitaly_repository
|
@gitaly_repo = repository.gitaly_repository
|
||||||
|
@ -38,6 +40,31 @@ module Gitlab
|
||||||
|
|
||||||
response.result
|
response.result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_remote_mirror(ref_name, only_branches_matching)
|
||||||
|
req_enum = Enumerator.new do |y|
|
||||||
|
y.yield Gitaly::UpdateRemoteMirrorRequest.new(
|
||||||
|
repository: @gitaly_repo,
|
||||||
|
ref_name: ref_name
|
||||||
|
)
|
||||||
|
|
||||||
|
current_size = 0
|
||||||
|
|
||||||
|
slices = only_branches_matching.slice_before do |branch_name|
|
||||||
|
current_size += branch_name.bytesize
|
||||||
|
|
||||||
|
next false if current_size < MAX_MSG_SIZE
|
||||||
|
|
||||||
|
current_size = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
slices.each do |slice|
|
||||||
|
y.yield Gitaly::UpdateRemoteMirrorRequest.new(only_branches_matching: slice)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
GitalyClient.call(@storage, :remote_service, :update_remote_mirror, req_enum)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,4 +44,18 @@ describe Gitlab::GitalyClient::RemoteService do
|
||||||
expect(client.fetch_internal_remote(remote_repository)).to be(true)
|
expect(client.fetch_internal_remote(remote_repository)).to be(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#update_remote_mirror' do
|
||||||
|
let(:ref_name) { 'remote_mirror_1' }
|
||||||
|
let(:only_branches_matching) { ['my-branch', 'master'] }
|
||||||
|
|
||||||
|
it 'sends an update_remote_mirror message' do
|
||||||
|
expect_any_instance_of(Gitaly::RemoteService::Stub)
|
||||||
|
.to receive(:update_remote_mirror)
|
||||||
|
.with(kind_of(Enumerator), kind_of(Hash))
|
||||||
|
.and_return(double(:update_remote_mirror_response))
|
||||||
|
|
||||||
|
client.update_remote_mirror(ref_name, only_branches_matching)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue