Commit 60891a73 authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Incorporate RefsService.FindAllBranches Gitaly RPC

parent 5e5ee454
......@@ -403,7 +403,7 @@ gem 'sys-filesystem', '~> 1.1.6'
gem 'net-ntp'
# Gitaly GRPC client
gem 'gitaly', '~> 0.18.0'
gem 'gitaly', '~> 0.19.0'
gem 'toml-rb', '~> 0.3.15', require: false
......
......@@ -293,7 +293,7 @@ GEM
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
gherkin-ruby (0.3.2)
gitaly (0.18.0)
gitaly (0.19.0)
google-protobuf (~> 3.1)
grpc (~> 1.0)
github-linguist (4.7.6)
......@@ -1008,7 +1008,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0)
gitaly (~> 0.18.0)
gitaly (~> 0.19.0)
github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-license (~> 1.0)
......
......@@ -10,7 +10,7 @@ module Gitlab
include Gitlab::EncodingHelper
def ref_name(ref)
encode! ref.sub(/\Arefs\/(tags|heads)\//, '')
encode! ref.sub(/\Arefs\/(tags|heads|remotes)\//, '')
end
def branch_name(ref)
......
......@@ -80,10 +80,14 @@ module Gitlab
end
# Returns an Array of Branches
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/389
def branches(sort_by: nil)
branches_filter(sort_by: sort_by)
def branches
gitaly_migrate(:branches) do |is_enabled|
if is_enabled
gitaly_ref_client.branches
else
branches_filter
end
end
end
def reload_rugged
......
......@@ -10,6 +10,19 @@ module Gitlab
@storage = repository.storage
end
def branches
request = Gitaly::FindAllBranchesRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_branches, request)
response.flat_map do |message|
message.branches.map do |branch|
gitaly_commit = GitalyClient::Commit.new(@repository, branch.target)
target_commit = Gitlab::Git::Commit.decorate(gitaly_commit)
Gitlab::Git::Branch.new(@repository, branch.name, branch.target.id, target_commit)
end
end
end
def default_branch_name
request = Gitaly::FindDefaultBranchNameRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_default_branch_name, request)
......
......@@ -939,16 +939,21 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'with deleted branch with Gitaly disabled' do
before do
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(false)
end
it 'returns no results' do
ref = double()
allow(ref).to receive(:name) { 'bad-branch' }
allow(ref).to receive(:target) { raise Rugged::ReferenceError }
branches = double()
allow(branches).to receive(:each) { [ref].each }
allow(repository.rugged).to receive(:branches) { branches }
end
it { is_expected.to eq([]) }
expect(subject).to be_empty
end
end
it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RefService, :branches
end
describe '#branch_count' do
......
......@@ -6,6 +6,17 @@ describe Gitlab::GitalyClient::RefService do
let(:relative_path) { project.path_with_namespace + '.git' }
let(:client) { described_class.new(project.repository) }
describe '#branches' do
it 'sends a find_all_branches message' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:find_all_branches)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([])
client.branches
end
end
describe '#branch_names' do
it 'sends a find_all_branch_names message' do
expect_any_instance_of(Gitaly::RefService::Stub)
......
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