Commit 4b78f70f authored by Douwe Maan's avatar Douwe Maan

Merge branch 'gitaly-delete-refs' into 'master'

Incorporate Gitaly's RefService.DeleteRefs RPC

Closes gitaly#740

See merge request gitlab-org/gitlab-ce!15460
parents 9414bb00 38730a2d
...@@ -398,7 +398,7 @@ group :ed25519 do ...@@ -398,7 +398,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.52.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.54.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -275,7 +275,7 @@ GEM ...@@ -275,7 +275,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.52.0) gitaly-proto (0.54.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -1034,7 +1034,7 @@ DEPENDENCIES ...@@ -1034,7 +1034,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.52.0) gitaly-proto (~> 0.54.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2) gitlab-markup (~> 1.6.2)
......
...@@ -304,8 +304,14 @@ module Gitlab ...@@ -304,8 +304,14 @@ module Gitlab
end end
def delete_all_refs_except(prefixes) def delete_all_refs_except(prefixes)
gitaly_migrate(:ref_delete_refs) do |is_enabled|
if is_enabled
gitaly_ref_client.delete_refs(except_with_prefixes: prefixes)
else
delete_refs(*all_ref_names_except(prefixes)) delete_refs(*all_ref_names_except(prefixes))
end end
end
end
# Returns an Array of all ref names, except when it's matching pattern # Returns an Array of all ref names, except when it's matching pattern
# #
......
...@@ -126,6 +126,15 @@ module Gitlab ...@@ -126,6 +126,15 @@ module Gitlab
GitalyClient.call(@repository.storage, :ref_service, :delete_branch, request) GitalyClient.call(@repository.storage, :ref_service, :delete_branch, request)
end end
def delete_refs(except_with_prefixes:)
request = Gitaly::DeleteRefsRequest.new(
repository: @gitaly_repo,
except_with_prefix: except_with_prefixes
)
GitalyClient.call(@repository.storage, :ref_service, :delete_refs, request)
end
private private
def consume_refs_response(response) def consume_refs_response(response)
......
...@@ -1783,6 +1783,32 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1783,6 +1783,32 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
describe '#delete_all_refs_except' do
let(:repository) do
Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '')
end
before do
repository.write_ref("refs/delete/a", "0b4bc9a49b562e85de7cc9e834518ea6828729b9")
repository.write_ref("refs/also-delete/b", "12d65c8dd2b2676fa3ac47d955accc085a37a9c1")
repository.write_ref("refs/keep/c", "6473c90867124755509e100d0d35ebdc85a0b6ae")
repository.write_ref("refs/also-keep/d", "0b4bc9a49b562e85de7cc9e834518ea6828729b9")
end
after do
ensure_seeds
end
it 'deletes all refs except those with the specified prefixes' do
repository.delete_all_refs_except(%w(refs/keep refs/also-keep refs/heads))
expect(repository.ref_exists?("refs/delete/a")).to be(false)
expect(repository.ref_exists?("refs/also-delete/b")).to be(false)
expect(repository.ref_exists?("refs/keep/c")).to be(true)
expect(repository.ref_exists?("refs/also-keep/d")).to be(true)
expect(repository.ref_exists?("refs/heads/master")).to be(true)
end
end
def create_remote_branch(repository, remote_name, branch_name, source_branch_name) def create_remote_branch(repository, remote_name, branch_name, source_branch_name)
source_branch = repository.branches.find { |branch| branch.name == source_branch_name } source_branch = repository.branches.find { |branch| branch.name == source_branch_name }
rugged = repository.rugged rugged = repository.rugged
......
...@@ -104,4 +104,17 @@ describe Gitlab::GitalyClient::RefService do ...@@ -104,4 +104,17 @@ describe Gitlab::GitalyClient::RefService do
expect { client.ref_exists?('reXXXXX') }.to raise_error(ArgumentError) expect { client.ref_exists?('reXXXXX') }.to raise_error(ArgumentError)
end end
end end
describe '#delete_refs' do
let(:prefixes) { %w(refs/heads refs/keep-around) }
it 'sends a delete_refs message' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:delete_refs)
.with(gitaly_request_with_params(except_with_prefix: prefixes), kind_of(Hash))
.and_return(double('delete_refs_response'))
client.delete_refs(except_with_prefixes: prefixes)
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