Merge branch 'zj-repo-exists-gitaly' into 'master'

Implement GRPC call to RepositoryService

See merge request !13019
This commit is contained in:
Sean McGivern 2017-07-26 08:27:48 +00:00
commit 695f5085a1
6 changed files with 64 additions and 16 deletions

View File

@ -471,8 +471,17 @@ class Repository
end
cache_method :root_ref
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/314
def exists?
refs_directory_exists?
return false unless path_with_namespace
Gitlab::GitalyClient.migrate(:repository_exists) do |enabled|
if enabled
raw_repository.exists?
else
refs_directory_exists?
end
end
end
cache_method :exists?
@ -1095,8 +1104,6 @@ class Repository
end
def refs_directory_exists?
return false unless path_with_namespace
File.exist?(File.join(path_to_repo, 'refs'))
end

View File

@ -45,6 +45,8 @@ module Gitlab
:bare?,
to: :rugged
delegate :exists?, to: :gitaly_repository_client
# Default branch in the repository
def root_ref
@root_ref ||= gitaly_migrate(:root_ref) do |is_enabled|
@ -208,10 +210,6 @@ module Gitlab
!empty?
end
def repo_exists?
!!rugged
end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
@ -815,6 +813,10 @@ module Gitlab
@gitaly_commit_client ||= Gitlab::GitalyClient::CommitService.new(self)
end
def gitaly_repository_client
@gitaly_repository_client ||= Gitlab::GitalyClient::RepositoryService.new(self)
end
private
# Gitaly note: JV: Trying to get rid of the 'filter' option so we can implement this with 'git'.

View File

@ -57,7 +57,7 @@ module Gitlab
metadata = yield(metadata) if block_given?
stub(service, storage).send(rpc, request, metadata)
end
def self.request_metadata(storage)
encoded_token = Base64.strict_encode64(token(storage).to_s)
{ metadata: { 'authorization' => "Bearer #{encoded_token}" } }

View File

@ -0,0 +1,16 @@
module Gitlab
module GitalyClient
class RepositoryService
def initialize(repository)
@repository = repository
@gitaly_repo = repository.gitaly_repository
end
def exists?
request = Gitaly::RepositoryExistsRequest.new(repository: @gitaly_repo)
GitalyClient.call(@repository.storage, :repository_service, :exists, request).exists
end
end
end
end

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe Gitlab::GitalyClient::RepositoryService do
set(:project) { create(:empty_project) }
let(:storage_name) { project.repository_storage }
let(:relative_path) { project.path_with_namespace + '.git' }
let(:client) { described_class.new(project.repository) }
describe '#exists?' do
it 'sends an exists message' do
expect_any_instance_of(Gitaly::RepositoryService::Stub)
.to receive(:exists)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_call_original
client.exists?
end
end
end

View File

@ -956,24 +956,28 @@ describe Repository, models: true do
end
end
describe '#exists?' do
shared_examples 'repo exists check' do
it 'returns true when a repository exists' do
expect(repository.exists?).to eq(true)
end
it 'returns false when a repository does not exist' do
allow(repository).to receive(:refs_directory_exists?).and_return(false)
expect(repository.exists?).to eq(false)
end
it 'returns false when there is no namespace' do
it 'returns false if no full path can be constructed' do
allow(repository).to receive(:path_with_namespace).and_return(nil)
expect(repository.exists?).to eq(false)
end
end
describe '#exists?' do
context 'when repository_exists is disabled' do
it_behaves_like 'repo exists check'
end
context 'when repository_exists is enabled', skip_gitaly_mock: true do
it_behaves_like 'repo exists check'
end
end
describe '#has_visible_content?' do
subject { repository.has_visible_content? }