summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-10-11 10:05:22 +0000
committerRémy Coutable <remy@rymai.me>2017-10-11 10:05:22 +0000
commit143ace07ad8c81e5de6f3fd926db7547e7288860 (patch)
tree4c5cac979ff872449a6bc1d751aac7a17737955f
parent22ade6e7cb2fedd7ad88f897fb501fce9f427bbd (diff)
parent06e7eeb1c22bf380ad8f3d35581ed63132adf5d6 (diff)
downloadgitlab-ce-143ace07ad8c81e5de6f3fd926db7547e7288860.tar.gz
Merge branch 'gitaly-has-local-branches' into 'master'
Use Gitaly's RepositoryService.HasLocalBranches RPC See merge request gitlab-org/gitlab-ce!14753
-rw-r--r--lib/gitlab/git/repository.rb2
-rw-r--r--lib/gitlab/gitaly_client/ref_service.rb8
-rw-r--r--lib/gitlab/gitaly_client/repository_service.rb7
-rw-r--r--spec/lib/gitlab/gitaly_client/repository_service_spec.rb11
4 files changed, 19 insertions, 9 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 0f059bef808..fa13920a3f3 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -193,7 +193,7 @@ module Gitlab
def has_local_branches?
gitaly_migrate(:has_local_branches) do |is_enabled|
if is_enabled
- gitaly_ref_client.has_local_branches?
+ gitaly_repository_client.has_local_branches?
else
has_local_branches_rugged?
end
diff --git a/lib/gitlab/gitaly_client/ref_service.rb b/lib/gitlab/gitaly_client/ref_service.rb
index 8214b7d63fa..b0c73395cb1 100644
--- a/lib/gitlab/gitaly_client/ref_service.rb
+++ b/lib/gitlab/gitaly_client/ref_service.rb
@@ -57,14 +57,6 @@ module Gitlab
branch_names.count
end
- # TODO implement a more efficient RPC for this https://gitlab.com/gitlab-org/gitaly/issues/616
- def has_local_branches?
- request = Gitaly::FindAllBranchNamesRequest.new(repository: @gitaly_repo)
- response = GitalyClient.call(@storage, :ref_service, :find_all_branch_names, request).first
-
- response&.names.present?
- end
-
def local_branches(sort_by: nil)
request = Gitaly::FindLocalBranchesRequest.new(repository: @gitaly_repo)
request.sort_by = sort_by_param(sort_by) if sort_by
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb
index fdf912214e0..cef692d3c2a 100644
--- a/lib/gitlab/gitaly_client/repository_service.rb
+++ b/lib/gitlab/gitaly_client/repository_service.rb
@@ -58,6 +58,13 @@ module Gitlab
request = Gitaly::CreateRepositoryRequest.new(repository: @gitaly_repo)
GitalyClient.call(@storage, :repository_service, :create_repository, request)
end
+
+ def has_local_branches?
+ request = Gitaly::HasLocalBranchesRequest.new(repository: @gitaly_repo)
+ response = GitalyClient.call(@storage, :repository_service, :has_local_branches, request)
+
+ response.value
+ end
end
end
end
diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
index fd5f984601e..cbc7ce1c1b0 100644
--- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
@@ -73,4 +73,15 @@ describe Gitlab::GitalyClient::RepositoryService do
client.apply_gitattributes(revision)
end
end
+
+ describe '#has_local_branches?' do
+ it 'sends a has_local_branches message' do
+ expect_any_instance_of(Gitaly::RepositoryService::Stub)
+ .to receive(:has_local_branches)
+ .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
+ .and_return(double(value: true))
+
+ expect(client.has_local_branches?).to be(true)
+ end
+ end
end