Commit 2bbac66c authored by Ahmad Hassan's avatar Ahmad Hassan

Refactor

parent 59a8c79f
...@@ -213,47 +213,20 @@ module Gitlab ...@@ -213,47 +213,20 @@ module Gitlab
end end
def create_from_bundle(bundle_path) def create_from_bundle(bundle_path)
request = Gitaly::CreateRepositoryFromBundleRequest.new(repository: @gitaly_repo) gitaly_repo_stream_request(
enum = Enumerator.new do |y| bundle_path,
File.open(bundle_path, 'rb') do |f|
while data = f.read(MAX_MSG_SIZE)
request.data = data
y.yield request
request = Gitaly::CreateRepositoryFromBundleRequest.new
end
end
end
GitalyClient.call(
@storage,
:repository_service,
:create_repository_from_bundle, :create_repository_from_bundle,
enum, Gitaly::CreateRepositoryFromBundleRequest,
timeout: GitalyClient.default_timeout GitalyClient.default_timeout
) )
end end
def restore_custom_hooks(custom_hooks_path) def restore_custom_hooks(custom_hooks_path)
request = Gitaly::RestoreCustomHooksRequest.new(repository: @gitaly_repo) gitaly_repo_stream_request(
enum = Enumerator.new do |y| custom_hooks_path,
File.open(custom_hooks_path, 'rb') do |f|
while data = f.read(MAX_MSG_SIZE)
request.data = data
y.yield request
request = Gitaly::RestoreCustomHooksRequest.new
end
end
end
GitalyClient.call(
@storage,
:repository_service,
:restore_custom_hooks, :restore_custom_hooks,
enum, Gitaly::RestoreCustomHooksRequest,
timeout: GitalyClient.default_timeout GitalyClient.default_timeout
) )
end end
...@@ -333,6 +306,30 @@ module Gitlab ...@@ -333,6 +306,30 @@ module Gitlab
request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query) request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches) GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches)
end end
private
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
end end
end end
end end
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