2017-07-21 07:36:31 +00:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class RepositoryService
|
|
|
|
def initialize(repository)
|
|
|
|
@repository = repository
|
|
|
|
@gitaly_repo = repository.gitaly_repository
|
2017-07-19 15:34:14 +00:00
|
|
|
@storage = repository.storage
|
2017-07-21 07:36:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
|
|
|
request = Gitaly::RepositoryExistsRequest.new(repository: @gitaly_repo)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :repository_exists, request, timeout: GitalyClient.fast_timeout)
|
|
|
|
|
|
|
|
response.exists
|
2017-07-19 15:34:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def garbage_collect(create_bitmap)
|
|
|
|
request = Gitaly::GarbageCollectRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
|
|
|
|
GitalyClient.call(@storage, :repository_service, :garbage_collect, request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def repack_full(create_bitmap)
|
|
|
|
request = Gitaly::RepackFullRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
|
|
|
|
GitalyClient.call(@storage, :repository_service, :repack_full, request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def repack_incremental
|
|
|
|
request = Gitaly::RepackIncrementalRequest.new(repository: @gitaly_repo)
|
|
|
|
GitalyClient.call(@storage, :repository_service, :repack_incremental, request)
|
2017-07-21 07:36:31 +00:00
|
|
|
end
|
2017-08-02 18:59:44 +00:00
|
|
|
|
|
|
|
def repository_size
|
|
|
|
request = Gitaly::RepositorySizeRequest.new(repository: @gitaly_repo)
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :repository_size, request)
|
|
|
|
response.size
|
2017-08-02 18:59:44 +00:00
|
|
|
end
|
2017-08-11 22:44:25 +00:00
|
|
|
|
|
|
|
def apply_gitattributes(revision)
|
|
|
|
request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: revision)
|
|
|
|
GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request)
|
|
|
|
end
|
2017-08-10 14:08:48 +00:00
|
|
|
|
|
|
|
def fetch_remote(remote, ssh_auth: nil, forced: false, no_tags: false)
|
|
|
|
request = Gitaly::FetchRemoteRequest.new(repository: @gitaly_repo, remote: remote, force: forced, no_tags: no_tags)
|
|
|
|
|
|
|
|
if ssh_auth&.ssh_import?
|
|
|
|
if ssh_auth.ssh_key_auth? && ssh_auth.ssh_private_key.present?
|
|
|
|
request.ssh_key = ssh_auth.ssh_private_key
|
|
|
|
end
|
|
|
|
|
|
|
|
if ssh_auth.ssh_known_hosts.present?
|
|
|
|
request.known_hosts = ssh_auth.ssh_known_hosts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
GitalyClient.call(@storage, :repository_service, :fetch_remote, request)
|
|
|
|
end
|
2017-09-28 17:07:22 +00:00
|
|
|
|
|
|
|
def create_repository
|
|
|
|
request = Gitaly::CreateRepositoryRequest.new(repository: @gitaly_repo)
|
|
|
|
GitalyClient.call(@storage, :repository_service, :create_repository, request)
|
|
|
|
end
|
2017-10-08 23:44:18 +00:00
|
|
|
|
|
|
|
def has_local_branches?
|
|
|
|
request = Gitaly::HasLocalBranchesRequest.new(repository: @gitaly_repo)
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :has_local_branches, request, timeout: GitalyClient.fast_timeout)
|
2017-10-08 23:44:18 +00:00
|
|
|
|
|
|
|
response.value
|
|
|
|
end
|
2017-11-22 10:19:42 +00:00
|
|
|
|
|
|
|
def fetch_source_branch(source_repository, source_branch, local_ref)
|
|
|
|
request = Gitaly::FetchSourceBranchRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
source_repository: source_repository.gitaly_repository,
|
|
|
|
source_branch: source_branch.b,
|
|
|
|
target_ref: local_ref.b
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:fetch_source_branch,
|
|
|
|
request,
|
|
|
|
remote_storage: source_repository.storage
|
|
|
|
)
|
|
|
|
|
|
|
|
response.result
|
|
|
|
end
|
2017-07-21 07:36:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|