2017-09-10 17:25:29 +05:30
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class BlobService
|
2018-03-17 18:26:18 +05:30
|
|
|
include Gitlab::EncodingHelper
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def initialize(repository)
|
|
|
|
@gitaly_repo = repository.gitaly_repository
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_blob(oid:, limit:)
|
|
|
|
request = Gitaly::GetBlobRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
oid: oid,
|
|
|
|
limit: limit
|
|
|
|
)
|
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
data = ''
|
|
|
|
blob = nil
|
|
|
|
response.each do |msg|
|
|
|
|
if blob.nil?
|
|
|
|
blob = msg
|
|
|
|
end
|
|
|
|
|
|
|
|
data << msg.data
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return nil if blob.oid.blank?
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
Gitlab::Git::Blob.new(
|
|
|
|
id: blob.oid,
|
|
|
|
size: blob.size,
|
|
|
|
data: data,
|
|
|
|
binary: Gitlab::Git::Blob.binary?(data)
|
|
|
|
)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def batch_lfs_pointers(blob_ids)
|
|
|
|
return [] if blob_ids.empty?
|
|
|
|
|
|
|
|
request = Gitaly::GetLFSPointersRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
blob_ids: blob_ids
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_lfs_pointers, request)
|
|
|
|
|
|
|
|
response.flat_map do |message|
|
|
|
|
message.lfs_pointers.map do |lfs_pointer|
|
|
|
|
Gitlab::Git::Blob.new(
|
|
|
|
id: lfs_pointer.oid,
|
|
|
|
size: lfs_pointer.size,
|
|
|
|
data: lfs_pointer.data,
|
|
|
|
binary: Gitlab::Git::Blob.binary?(lfs_pointer.data)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_blobs(revision_paths, limit = -1)
|
|
|
|
return [] if revision_paths.empty?
|
|
|
|
|
|
|
|
revision_paths.map! do |rev, path|
|
|
|
|
Gitaly::GetBlobsRequest::RevisionPath.new(revision: rev, path: encode_binary(path))
|
|
|
|
end
|
|
|
|
|
|
|
|
request = Gitaly::GetBlobsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision_paths: revision_paths,
|
|
|
|
limit: limit
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@gitaly_repo.storage_name,
|
|
|
|
:blob_service,
|
|
|
|
:get_blobs,
|
|
|
|
request,
|
|
|
|
timeout: GitalyClient.default_timeout
|
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient::BlobsStitcher.new(response)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|