2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-21 03:36:31 -04:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class RepositoryService
|
2017-12-26 13:53:31 -05:00
|
|
|
include Gitlab::EncodingHelper
|
|
|
|
|
2019-07-16 04:33:07 -04:00
|
|
|
MAX_MSG_SIZE = 128.kilobytes
|
2018-01-22 10:46:02 -05:00
|
|
|
|
2017-07-21 03:36:31 -04:00
|
|
|
def initialize(repository)
|
|
|
|
@repository = repository
|
|
|
|
@gitaly_repo = repository.gitaly_repository
|
2017-07-19 11:34:14 -04:00
|
|
|
@storage = repository.storage
|
2017-07-21 03:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
|
|
|
request = Gitaly::RepositoryExistsRequest.new(repository: @gitaly_repo)
|
|
|
|
|
2017-11-29 04:12:12 -05:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :repository_exists, request, timeout: GitalyClient.fast_timeout)
|
|
|
|
|
|
|
|
response.exists
|
2017-07-19 11:34:14 -04:00
|
|
|
end
|
|
|
|
|
2018-03-29 19:10:43 -04:00
|
|
|
def cleanup
|
|
|
|
request = Gitaly::CleanupRequest.new(repository: @gitaly_repo)
|
2018-07-05 12:05:24 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :cleanup, request, timeout: GitalyClient.fast_timeout)
|
2018-03-29 19:10:43 -04:00
|
|
|
end
|
|
|
|
|
2017-07-19 11:34:14 -04:00
|
|
|
def garbage_collect(create_bitmap)
|
|
|
|
request = Gitaly::GarbageCollectRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :garbage_collect, request, timeout: GitalyClient.long_timeout)
|
2017-07-19 11:34:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def repack_full(create_bitmap)
|
|
|
|
request = Gitaly::RepackFullRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :repack_full, request, timeout: GitalyClient.long_timeout)
|
2017-07-19 11:34:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def repack_incremental
|
|
|
|
request = Gitaly::RepackIncrementalRequest.new(repository: @gitaly_repo)
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :repack_incremental, request, timeout: GitalyClient.long_timeout)
|
2017-07-21 03:36:31 -04:00
|
|
|
end
|
2017-08-02 14:59:44 -04:00
|
|
|
|
|
|
|
def repository_size
|
|
|
|
request = Gitaly::RepositorySizeRequest.new(repository: @gitaly_repo)
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :repository_size, request, timeout: GitalyClient.medium_timeout)
|
2017-11-29 04:12:12 -05:00
|
|
|
response.size
|
2017-08-02 14:59:44 -04:00
|
|
|
end
|
2017-08-11 18:44:25 -04:00
|
|
|
|
2019-05-27 00:38:20 -04:00
|
|
|
def get_object_directory_size
|
|
|
|
request = Gitaly::GetObjectDirectorySizeRequest.new(repository: @gitaly_repo)
|
|
|
|
response = GitalyClient.call(@storage, :repository_service, :get_object_directory_size, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
|
|
|
|
response.size
|
|
|
|
end
|
|
|
|
|
2017-08-11 18:44:25 -04:00
|
|
|
def apply_gitattributes(revision)
|
2018-02-22 04:38:37 -05:00
|
|
|
request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: encode_binary(revision))
|
2018-07-05 12:05:24 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request, timeout: GitalyClient.fast_timeout)
|
2018-07-03 11:39:08 -04:00
|
|
|
rescue GRPC::InvalidArgument => ex
|
|
|
|
raise Gitlab::Git::Repository::InvalidRef, ex
|
2017-08-11 18:44:25 -04:00
|
|
|
end
|
2017-08-10 10:08:48 -04:00
|
|
|
|
2018-03-27 08:31:15 -04:00
|
|
|
def info_attributes
|
|
|
|
request = Gitaly::GetInfoAttributesRequest.new(repository: @gitaly_repo)
|
|
|
|
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :get_info_attributes, request, timeout: GitalyClient.fast_timeout)
|
2018-11-09 13:39:43 -05:00
|
|
|
response.each_with_object([]) do |message, attributes|
|
2018-03-27 08:31:15 -04:00
|
|
|
attributes << message.attributes
|
2018-11-09 13:39:43 -05:00
|
|
|
end.join
|
2018-03-27 08:31:15 -04:00
|
|
|
end
|
|
|
|
|
2018-03-02 08:50:17 -05:00
|
|
|
def fetch_remote(remote, ssh_auth:, forced:, no_tags:, timeout:, prune: true)
|
2018-01-04 21:34:31 -05:00
|
|
|
request = Gitaly::FetchRemoteRequest.new(
|
|
|
|
repository: @gitaly_repo, remote: remote, force: forced,
|
2018-03-02 08:50:17 -05:00
|
|
|
no_tags: no_tags, timeout: timeout, no_prune: !prune
|
2018-01-04 21:34:31 -05:00
|
|
|
)
|
2017-08-10 10:08:48 -04:00
|
|
|
|
2018-11-12 05:52:48 -05:00
|
|
|
if ssh_auth&.ssh_mirror_url?
|
2017-08-10 10:08:48 -04:00
|
|
|
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
|
|
|
|
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :fetch_remote, request, timeout: GitalyClient.long_timeout)
|
2017-08-10 10:08:48 -04:00
|
|
|
end
|
2017-09-28 13:07:22 -04:00
|
|
|
|
|
|
|
def create_repository
|
|
|
|
request = Gitaly::CreateRepositoryRequest.new(repository: @gitaly_repo)
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :create_repository, request, timeout: GitalyClient.fast_timeout)
|
2017-09-28 13:07:22 -04:00
|
|
|
end
|
2017-10-08 19:44:18 -04:00
|
|
|
|
|
|
|
def has_local_branches?
|
|
|
|
request = Gitaly::HasLocalBranchesRequest.new(repository: @gitaly_repo)
|
2017-11-29 04:12:12 -05:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :has_local_branches, request, timeout: GitalyClient.fast_timeout)
|
2017-10-08 19:44:18 -04:00
|
|
|
|
|
|
|
response.value
|
|
|
|
end
|
2017-11-22 05:19:42 -05:00
|
|
|
|
2017-12-06 10:54:57 -05:00
|
|
|
def find_merge_base(*revisions)
|
|
|
|
request = Gitaly::FindMergeBaseRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 13:53:31 -05:00
|
|
|
revisions: revisions.map { |r| encode_binary(r) }
|
2017-12-06 10:54:57 -05:00
|
|
|
)
|
|
|
|
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :find_merge_base, request, timeout: GitalyClient.fast_timeout)
|
2017-12-06 10:54:57 -05:00
|
|
|
response.base.presence
|
|
|
|
end
|
|
|
|
|
2017-12-19 11:45:58 -05:00
|
|
|
def fork_repository(source_repository)
|
|
|
|
request = Gitaly::CreateForkRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
source_repository: source_repository.gitaly_repository
|
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:create_fork,
|
|
|
|
request,
|
|
|
|
remote_storage: source_repository.storage,
|
2019-09-25 20:06:07 -04:00
|
|
|
timeout: GitalyClient.long_timeout
|
2017-12-19 11:45:58 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-01-12 10:55:48 -05:00
|
|
|
def import_repository(source)
|
|
|
|
request = Gitaly::CreateRepositoryFromURLRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
url: source
|
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:create_repository_from_url,
|
|
|
|
request,
|
2019-09-25 20:06:07 -04:00
|
|
|
timeout: GitalyClient.long_timeout
|
2018-01-12 10:55:48 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-01-08 10:08:25 -05:00
|
|
|
def rebase_in_progress?(rebase_id)
|
|
|
|
request = Gitaly::IsRebaseInProgressRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
rebase_id: rebase_id.to_s
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:is_rebase_in_progress,
|
|
|
|
request,
|
2018-04-30 08:16:27 -04:00
|
|
|
timeout: GitalyClient.fast_timeout
|
2018-01-08 10:08:25 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
response.in_progress
|
|
|
|
end
|
|
|
|
|
2018-02-07 16:26:35 -05:00
|
|
|
def squash_in_progress?(squash_id)
|
|
|
|
request = Gitaly::IsSquashInProgressRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
squash_id: squash_id.to_s
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:is_squash_in_progress,
|
|
|
|
request,
|
2018-04-30 08:16:27 -04:00
|
|
|
timeout: GitalyClient.fast_timeout
|
2018-02-07 16:26:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
response.in_progress
|
|
|
|
end
|
|
|
|
|
2017-11-22 05:19:42 -05: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,
|
2019-09-25 20:06:07 -04:00
|
|
|
timeout: GitalyClient.long_timeout,
|
2017-11-22 05:19:42 -05:00
|
|
|
remote_storage: source_repository.storage
|
|
|
|
)
|
|
|
|
|
|
|
|
response.result
|
|
|
|
end
|
2017-12-07 19:27:11 -05:00
|
|
|
|
|
|
|
def fsck
|
|
|
|
request = Gitaly::FsckRequest.new(repository: @gitaly_repo)
|
2019-09-19 14:06:18 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :fsck, request, timeout: GitalyClient.long_timeout)
|
2017-12-07 19:27:11 -05:00
|
|
|
|
|
|
|
if response.error.empty?
|
|
|
|
return "", 0
|
|
|
|
else
|
|
|
|
return response.error.b, 1
|
|
|
|
end
|
|
|
|
end
|
2018-01-18 12:33:35 -05:00
|
|
|
|
|
|
|
def create_bundle(save_path)
|
2018-06-13 05:19:17 -04:00
|
|
|
gitaly_fetch_stream_to_file(
|
|
|
|
save_path,
|
2018-01-18 12:33:35 -05:00
|
|
|
:create_bundle,
|
2018-06-13 05:19:17 -04:00
|
|
|
Gitaly::CreateBundleRequest,
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.long_timeout
|
2018-01-18 12:33:35 -05:00
|
|
|
)
|
2018-06-13 05:19:17 -04:00
|
|
|
end
|
2018-01-18 12:33:35 -05:00
|
|
|
|
2018-06-13 05:19:17 -04:00
|
|
|
def backup_custom_hooks(save_path)
|
|
|
|
gitaly_fetch_stream_to_file(
|
|
|
|
save_path,
|
|
|
|
:backup_custom_hooks,
|
|
|
|
Gitaly::BackupCustomHooksRequest,
|
|
|
|
GitalyClient.default_timeout
|
|
|
|
)
|
2018-01-18 12:33:35 -05:00
|
|
|
end
|
2018-01-22 10:46:02 -05:00
|
|
|
|
|
|
|
def create_from_bundle(bundle_path)
|
2018-06-07 09:10:35 -04:00
|
|
|
gitaly_repo_stream_request(
|
|
|
|
bundle_path,
|
2018-01-22 10:46:02 -05:00
|
|
|
:create_repository_from_bundle,
|
2018-06-07 09:10:35 -04:00
|
|
|
Gitaly::CreateRepositoryFromBundleRequest,
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.long_timeout
|
2018-01-22 10:46:02 -05:00
|
|
|
)
|
|
|
|
end
|
2018-01-17 00:43:30 -05:00
|
|
|
|
2018-06-04 09:15:54 -04:00
|
|
|
def restore_custom_hooks(custom_hooks_path)
|
2018-06-07 09:10:35 -04:00
|
|
|
gitaly_repo_stream_request(
|
|
|
|
custom_hooks_path,
|
2018-06-04 09:15:54 -04:00
|
|
|
:restore_custom_hooks,
|
2018-06-07 09:10:35 -04:00
|
|
|
Gitaly::RestoreCustomHooksRequest,
|
|
|
|
GitalyClient.default_timeout
|
2018-06-04 09:15:54 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-04-03 13:57:55 -04:00
|
|
|
def create_from_snapshot(http_url, http_auth)
|
|
|
|
request = Gitaly::CreateRepositoryFromSnapshotRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
http_url: http_url,
|
|
|
|
http_auth: http_auth
|
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:create_repository_from_snapshot,
|
|
|
|
request,
|
2019-09-19 14:06:18 -04:00
|
|
|
timeout: GitalyClient.long_timeout
|
2018-04-03 13:57:55 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-11-21 12:29:18 -05:00
|
|
|
def write_ref(ref_path, ref, old_ref)
|
2018-01-17 00:43:30 -05:00
|
|
|
request = Gitaly::WriteRefRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
ref: ref_path.b,
|
2018-11-21 12:29:18 -05:00
|
|
|
revision: ref.b
|
2018-01-17 00:43:30 -05:00
|
|
|
)
|
|
|
|
request.old_revision = old_ref.b unless old_ref.nil?
|
|
|
|
|
2018-11-21 12:28:34 -05:00
|
|
|
GitalyClient.call(@storage, :repository_service, :write_ref, request, timeout: GitalyClient.fast_timeout)
|
2018-01-17 00:43:30 -05:00
|
|
|
end
|
2018-01-26 03:00:22 -05:00
|
|
|
|
2018-07-04 08:42:24 -04:00
|
|
|
def set_config(entries)
|
|
|
|
return if entries.empty?
|
|
|
|
|
|
|
|
request = Gitaly::SetConfigRequest.new(repository: @gitaly_repo)
|
|
|
|
entries.each do |key, value|
|
|
|
|
request.entries << build_set_config_entry(key, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:set_config,
|
|
|
|
request,
|
|
|
|
timeout: GitalyClient.fast_timeout
|
|
|
|
)
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_config(keys)
|
|
|
|
return if keys.empty?
|
|
|
|
|
|
|
|
request = Gitaly::DeleteConfigRequest.new(repository: @gitaly_repo, keys: keys)
|
|
|
|
|
|
|
|
GitalyClient.call(
|
2018-01-26 03:00:22 -05:00
|
|
|
@storage,
|
|
|
|
:repository_service,
|
2018-07-04 08:42:24 -04:00
|
|
|
:delete_config,
|
2018-01-26 03:00:22 -05:00
|
|
|
request,
|
|
|
|
timeout: GitalyClient.fast_timeout
|
|
|
|
)
|
|
|
|
|
2018-07-04 08:42:24 -04:00
|
|
|
nil
|
2018-01-26 03:00:22 -05:00
|
|
|
end
|
2018-03-01 09:30:41 -05:00
|
|
|
|
|
|
|
def license_short_name
|
|
|
|
request = Gitaly::FindLicenseRequest.new(repository: @gitaly_repo)
|
|
|
|
|
|
|
|
response = GitalyClient.call(@storage, :repository_service, :find_license, request, timeout: GitalyClient.fast_timeout)
|
|
|
|
|
|
|
|
response.license_short_name.presence
|
|
|
|
end
|
2018-04-05 14:27:09 -04:00
|
|
|
|
|
|
|
def calculate_checksum
|
|
|
|
request = Gitaly::CalculateChecksumRequest.new(repository: @gitaly_repo)
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request, timeout: GitalyClient.fast_timeout)
|
2018-04-05 14:27:09 -04:00
|
|
|
response.checksum.presence
|
2018-04-25 17:33:00 -04:00
|
|
|
rescue GRPC::DataLoss => e
|
|
|
|
raise Gitlab::Git::Repository::InvalidRepository.new(e)
|
2018-04-05 14:27:09 -04:00
|
|
|
end
|
2018-05-02 04:12:15 -04:00
|
|
|
|
|
|
|
def raw_changes_between(from, to)
|
|
|
|
request = Gitaly::GetRawChangesRequest.new(repository: @gitaly_repo, from_revision: from, to_revision: to)
|
|
|
|
|
2018-07-05 12:05:24 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :get_raw_changes, request, timeout: GitalyClient.fast_timeout)
|
2018-05-02 04:12:15 -04:00
|
|
|
end
|
2018-05-04 09:53:01 -04:00
|
|
|
|
|
|
|
def search_files_by_name(ref, query)
|
|
|
|
request = Gitaly::SearchFilesByNameRequest.new(repository: @gitaly_repo, ref: ref, query: query)
|
2018-07-05 12:05:24 -04:00
|
|
|
GitalyClient.call(@storage, :repository_service, :search_files_by_name, request, timeout: GitalyClient.fast_timeout).flat_map(&:files)
|
2018-05-04 09:53:01 -04:00
|
|
|
end
|
|
|
|
|
2020-02-16 16:08:53 -05:00
|
|
|
def search_files_by_content(ref, query, options = {})
|
2019-02-27 16:37:33 -05:00
|
|
|
request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
|
2019-09-19 14:06:18 -04:00
|
|
|
response = GitalyClient.call(@storage, :repository_service, :search_files_by_content, request, timeout: GitalyClient.default_timeout)
|
2019-01-02 18:39:47 -05:00
|
|
|
|
2020-02-16 16:08:53 -05:00
|
|
|
search_results_from_response(response, options)
|
2018-05-04 09:53:01 -04:00
|
|
|
end
|
2019-05-01 00:45:19 -04:00
|
|
|
|
|
|
|
def disconnect_alternates
|
|
|
|
request = Gitaly::DisconnectGitAlternatesRequest.new(
|
|
|
|
repository: @gitaly_repo
|
|
|
|
)
|
|
|
|
|
2019-09-19 14:06:18 -04:00
|
|
|
GitalyClient.call(@storage, :object_pool_service, :disconnect_git_alternates, request, timeout: GitalyClient.long_timeout)
|
2019-05-01 00:45:19 -04:00
|
|
|
end
|
2019-10-02 11:06:12 -04:00
|
|
|
|
|
|
|
def rename(relative_path)
|
|
|
|
request = Gitaly::RenameRepositoryRequest.new(repository: @gitaly_repo, relative_path: relative_path)
|
|
|
|
|
|
|
|
GitalyClient.call(@storage, :repository_service, :rename_repository, request, timeout: GitalyClient.fast_timeout)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove
|
|
|
|
request = Gitaly::RemoveRepositoryRequest.new(repository: @gitaly_repo)
|
|
|
|
|
|
|
|
GitalyClient.call(@storage, :repository_service, :remove_repository, request, timeout: GitalyClient.long_timeout)
|
|
|
|
end
|
2018-06-07 09:10:35 -04:00
|
|
|
|
2020-03-12 20:09:34 -04:00
|
|
|
def replicate(source_repository)
|
|
|
|
request = Gitaly::ReplicateRepositoryRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
source: source_repository.gitaly_repository
|
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
:replicate_repository,
|
|
|
|
request,
|
|
|
|
remote_storage: source_repository.storage,
|
|
|
|
timeout: GitalyClient.long_timeout
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-06-07 09:10:35 -04:00
|
|
|
private
|
|
|
|
|
2020-02-16 16:08:53 -05:00
|
|
|
def search_results_from_response(gitaly_response, options = {})
|
|
|
|
limit = options[:limit]
|
|
|
|
|
2019-01-02 18:39:47 -05:00
|
|
|
matches = []
|
2020-02-16 16:08:53 -05:00
|
|
|
matches_count = 0
|
2019-01-02 18:39:47 -05:00
|
|
|
current_match = +""
|
|
|
|
|
|
|
|
gitaly_response.each do |message|
|
|
|
|
next if message.nil?
|
|
|
|
|
2020-02-16 16:08:53 -05:00
|
|
|
break if limit && matches_count >= limit
|
|
|
|
|
2019-02-27 16:37:33 -05:00
|
|
|
current_match << message.match_data
|
|
|
|
|
|
|
|
if message.end_of_match
|
|
|
|
matches << current_match
|
|
|
|
current_match = +""
|
2020-02-16 16:08:53 -05:00
|
|
|
matches_count += 1
|
2019-01-02 18:39:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
matches
|
|
|
|
end
|
|
|
|
|
2018-06-13 05:19:17 -04:00
|
|
|
def gitaly_fetch_stream_to_file(save_path, rpc_name, request_class, timeout)
|
|
|
|
request = request_class.new(repository: @gitaly_repo)
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
rpc_name,
|
|
|
|
request,
|
|
|
|
timeout: timeout
|
|
|
|
)
|
|
|
|
|
|
|
|
File.open(save_path, 'wb') do |f|
|
|
|
|
response.each do |message|
|
|
|
|
f.write(message.data)
|
|
|
|
end
|
|
|
|
end
|
2018-10-30 06:53:01 -04:00
|
|
|
# If the file is empty means that we received an empty stream, we delete the file
|
2018-06-13 05:19:17 -04:00
|
|
|
FileUtils.rm(save_path) if File.zero?(save_path)
|
|
|
|
end
|
|
|
|
|
2018-06-07 09:10:35 -04:00
|
|
|
def gitaly_repo_stream_request(file_path, rpc_name, request_class, timeout)
|
|
|
|
request = request_class.new(repository: @gitaly_repo)
|
|
|
|
enum = Enumerator.new do |y|
|
|
|
|
File.open(file_path, 'rb') do |f|
|
|
|
|
while data = f.read(MAX_MSG_SIZE)
|
|
|
|
request.data = data
|
|
|
|
|
|
|
|
y.yield request
|
|
|
|
request = request_class.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
GitalyClient.call(
|
|
|
|
@storage,
|
|
|
|
:repository_service,
|
|
|
|
rpc_name,
|
|
|
|
enum,
|
|
|
|
timeout: timeout
|
|
|
|
)
|
|
|
|
end
|
2018-07-04 08:42:24 -04:00
|
|
|
|
|
|
|
def build_set_config_entry(key, value)
|
|
|
|
entry = Gitaly::SetConfigRequest::Entry.new(key: key)
|
|
|
|
|
|
|
|
case value
|
|
|
|
when String
|
|
|
|
entry.value_str = value
|
|
|
|
when Integer
|
|
|
|
entry.value_int32 = value
|
|
|
|
when TrueClass, FalseClass
|
|
|
|
entry.value_bool = value
|
|
|
|
else
|
|
|
|
raise InvalidArgument, "invalid git config value: #{value.inspect}"
|
|
|
|
end
|
|
|
|
|
|
|
|
entry
|
|
|
|
end
|
2017-07-21 03:36:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|