diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-25 20:59:33 +0100 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-30 23:48:51 +0100 |
commit | 1ebb781f6a5e25a5e71c77be67f4f53e9c4e72c3 (patch) | |
tree | b7a6c3e4b6514b759056bf2113a898661f81a73b /lib | |
parent | 6f32fa6628785094e7bbf94f22272abe4991d14a (diff) | |
download | gitlab-ce-1ebb781f6a5e25a5e71c77be67f4f53e9c4e72c3.tar.gz |
Migrate Git::Repository#delete_refs to Gitalyfeature/migrate-delete-refs-to-gitaly
Closes gitaly#967
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 34 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/ref_service.rb | 9 |
2 files changed, 30 insertions, 13 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 8614c1bd417..7127f7858ee 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -888,16 +888,12 @@ module Gitlab end def delete_refs(*ref_names) - instructions = ref_names.map do |ref| - "delete #{ref}\x00\x00" - end - - message, status = run_git(%w[update-ref --stdin -z]) do |stdin| - stdin.write(instructions.join) - end - - unless status.zero? - raise GitError.new("Could not delete refs #{ref_names}: #{message}") + gitaly_migrate(:delete_refs) do |is_enabled| + if is_enabled + gitaly_delete_refs(*ref_names) + else + git_delete_refs(*ref_names) + end end end @@ -2204,6 +2200,24 @@ module Gitlab remote_update(remote_name, url: url) end + def git_delete_refs(*ref_names) + instructions = ref_names.map do |ref| + "delete #{ref}\x00\x00" + end + + message, status = run_git(%w[update-ref --stdin -z]) do |stdin| + stdin.write(instructions.join) + end + + unless status.zero? + raise GitError.new("Could not delete refs #{ref_names}: #{message}") + end + end + + def gitaly_delete_refs(*ref_names) + gitaly_ref_client.delete_refs(refs: ref_names) + end + def rugged_remove_remote(remote_name) # When a remote is deleted all its remote refs are deleted too, but in # the case of mirrors we map its refs (that would usualy go under diff --git a/lib/gitlab/gitaly_client/ref_service.rb b/lib/gitlab/gitaly_client/ref_service.rb index f8e2a27f3fe..8b9a224b700 100644 --- a/lib/gitlab/gitaly_client/ref_service.rb +++ b/lib/gitlab/gitaly_client/ref_service.rb @@ -133,13 +133,16 @@ module Gitlab GitalyClient.call(@repository.storage, :ref_service, :delete_branch, request) end - def delete_refs(except_with_prefixes:) + def delete_refs(refs: [], except_with_prefixes: []) request = Gitaly::DeleteRefsRequest.new( repository: @gitaly_repo, - except_with_prefix: except_with_prefixes + refs: refs.map { |r| encode_binary(r) }, + except_with_prefix: except_with_prefixes.map { |r| encode_binary(r) } ) - GitalyClient.call(@repository.storage, :ref_service, :delete_refs, request) + response = GitalyClient.call(@repository.storage, :ref_service, :delete_refs, request) + + raise Gitlab::Git::Repository::GitError, response.git_error if response.git_error.present? end private |