diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-10-13 18:36:32 +0200 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-10-16 12:10:36 +0200 |
commit | 21d832ed591c74d7ceccfda437f8dea266dde443 (patch) | |
tree | 1274f67660eff7b0c8afca59e2213d0ca1fd13b8 | |
parent | 076231798dd9716479d8eef118678eeb7c2c7b11 (diff) | |
download | gitlab-ce-gitaly-659-get-blobs.tar.gz |
Gitlab::Git::Blob.batch_rawgitaly-659-get-blobs
-rw-r--r-- | GITALY_SERVER_VERSION | 2 | ||||
-rw-r--r-- | lib/gitlab/git/blob.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/blob_service.rb | 31 |
3 files changed, 44 insertions, 1 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 421ab545d9a..cb4164fa7af 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.47.0 +=632-blob-service-get-blobs-by-shas diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index a4336facee5..6168a8c1cde 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -44,6 +44,18 @@ module Gitlab end end + def batch_raw(repository, blob_oids, blob_size_limit: nil) + Gitlab::GitalyClient.migrate(:blob_batch_raw) do |is_enabled| + if is_enabled + Gitlab::GitalyClient::BlobService.new(repository).get_blobs(oids: blob_oids, limit: blob_size_limit) + else + blob_oids.map do |oid| + raw_by_rugged(repository, oid) + end + end + end + end + # Returns an array of Blob instances, specified in blob_references as # [[commit_sha, path], [commit_sha, path], ...]. If blob_size_limit < 0 then the # full blob contents are returned. If blob_size_limit >= 0 then each blob will diff --git a/lib/gitlab/gitaly_client/blob_service.rb b/lib/gitlab/gitaly_client/blob_service.rb index a250eb75bd4..8ebddf247d5 100644 --- a/lib/gitlab/gitaly_client/blob_service.rb +++ b/lib/gitlab/gitaly_client/blob_service.rb @@ -32,6 +32,37 @@ module Gitlab binary: Gitlab::Git::Blob.binary?(data) ) end + + def get_blobs(oids:, limit: ) + request = Gitaly::GetBlobsRequest.new( + repository: @gitaly_repo, + oids: Gitlab::GitalyClient.encode_repeated(oids), + limit: limit + ) + response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blobs, request) + + blobs = [] + blob = nil + response.each do |msg| + if msg.oid.empty? + blob.data << msg.data + else + unless blob.nil? + blobs << blob + end + blob = msg + end + end + + blobs.map do |blob| + Gitlab::Git::Blob.new( + id: blob.oid, + size: blob.size, + data: blob.data, + binary: Gitlab::Git::Blob.binary?(data) + ) + end + end end end end |