diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-22 18:46:02 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2018-01-24 21:02:32 +0300 |
commit | 6a28967c1461a840926940beb075e4f9285c7e82 (patch) | |
tree | bc857c77ce914db1e6be131f7023e017249bff8a /lib/gitlab/gitaly_client/repository_service.rb | |
parent | a403011e4f7adae339a3a8584e22a75f4872c3c5 (diff) |
Migrate restoring repo from bundle to Gitaly
Closes gitaly#946
Diffstat (limited to 'lib/gitlab/gitaly_client/repository_service.rb')
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 654a3c314f1..b0dbaf11598 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -3,6 +3,8 @@ module Gitlab class RepositoryService include Gitlab::EncodingHelper + MAX_MSG_SIZE = 128.kilobytes.freeze + def initialize(repository) @repository = repository @gitaly_repo = repository.gitaly_repository @@ -178,6 +180,29 @@ module Gitlab end end end + + def create_from_bundle(bundle_path) + request = Gitaly::CreateRepositoryFromBundleRequest.new(repository: @gitaly_repo) + enum = Enumerator.new do |y| + 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, + enum, + timeout: GitalyClient.default_timeout + ) + end end end end |