2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-07 10:45:52 -04:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
2017-07-18 03:59:36 -04:00
|
|
|
class BlobService
|
2018-02-01 14:56:41 -05:00
|
|
|
include Gitlab::EncodingHelper
|
|
|
|
|
2017-07-07 10:45:52 -04:00
|
|
|
def initialize(repository)
|
|
|
|
@gitaly_repo = repository.gitaly_repository
|
|
|
|
end
|
2017-07-18 03:59:36 -04:00
|
|
|
|
2017-07-07 10:45:52 -04:00
|
|
|
def get_blob(oid:, limit:)
|
|
|
|
request = Gitaly::GetBlobRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
oid: oid,
|
|
|
|
limit: limit
|
|
|
|
)
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request, timeout: GitalyClient.fast_timeout)
|
2017-07-07 10:45:52 -04:00
|
|
|
|
2018-11-09 13:39:43 -05:00
|
|
|
data = []
|
2017-08-16 08:29:27 -04:00
|
|
|
blob = nil
|
|
|
|
response.each do |msg|
|
|
|
|
if blob.nil?
|
|
|
|
blob = msg
|
|
|
|
end
|
2017-07-07 10:45:52 -04:00
|
|
|
|
2017-08-16 08:29:27 -04:00
|
|
|
data << msg.data
|
|
|
|
end
|
|
|
|
|
2019-02-08 07:19:53 -05:00
|
|
|
return if blob.oid.blank?
|
2017-07-07 10:45:52 -04:00
|
|
|
|
2018-11-09 13:39:43 -05:00
|
|
|
data = data.join
|
|
|
|
|
2017-07-07 10:45:52 -04:00
|
|
|
Gitlab::Git::Blob.new(
|
|
|
|
id: blob.oid,
|
|
|
|
size: blob.size,
|
|
|
|
data: data,
|
|
|
|
binary: Gitlab::Git::Blob.binary?(data)
|
|
|
|
)
|
|
|
|
end
|
2018-01-17 08:21:46 -05:00
|
|
|
|
|
|
|
def batch_lfs_pointers(blob_ids)
|
2018-01-25 04:46:15 -05:00
|
|
|
return [] if blob_ids.empty?
|
|
|
|
|
2018-01-17 08:21:46 -05:00
|
|
|
request = Gitaly::GetLFSPointersRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
blob_ids: blob_ids
|
|
|
|
)
|
|
|
|
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_lfs_pointers, request, timeout: GitalyClient.medium_timeout)
|
2018-01-17 08:21:46 -05:00
|
|
|
|
2018-02-06 17:49:33 -05:00
|
|
|
map_lfs_pointers(response)
|
2018-01-17 08:21:46 -05:00
|
|
|
end
|
2018-02-01 14:56:41 -05:00
|
|
|
|
|
|
|
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,
|
2018-07-05 12:05:24 -04:00
|
|
|
timeout: GitalyClient.fast_timeout
|
2018-02-01 14:56:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
GitalyClient::BlobsStitcher.new(response)
|
|
|
|
end
|
2018-02-06 17:49:33 -05:00
|
|
|
|
2018-10-22 10:49:20 -04:00
|
|
|
def get_new_lfs_pointers(revision, limit, not_in, dynamic_timeout = nil)
|
2018-02-06 17:49:33 -05:00
|
|
|
request = Gitaly::GetNewLFSPointersRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision: encode_binary(revision),
|
|
|
|
limit: limit || 0
|
|
|
|
)
|
|
|
|
|
|
|
|
if not_in.nil? || not_in == :all
|
|
|
|
request.not_in_all = true
|
|
|
|
else
|
|
|
|
request.not_in_refs += not_in
|
|
|
|
end
|
|
|
|
|
2018-10-22 10:49:20 -04:00
|
|
|
timeout =
|
|
|
|
if dynamic_timeout
|
|
|
|
[dynamic_timeout, GitalyClient.medium_timeout].min
|
|
|
|
else
|
|
|
|
GitalyClient.medium_timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
response = GitalyClient.call(
|
|
|
|
@gitaly_repo.storage_name,
|
|
|
|
:blob_service,
|
|
|
|
:get_new_lfs_pointers,
|
|
|
|
request,
|
|
|
|
timeout: timeout
|
|
|
|
)
|
2018-02-06 17:49:33 -05:00
|
|
|
|
|
|
|
map_lfs_pointers(response)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_all_lfs_pointers(revision)
|
|
|
|
request = Gitaly::GetNewLFSPointersRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision: encode_binary(revision)
|
|
|
|
)
|
|
|
|
|
2018-07-05 12:05:24 -04:00
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_all_lfs_pointers, request, timeout: GitalyClient.medium_timeout)
|
2018-02-06 17:49:33 -05:00
|
|
|
|
|
|
|
map_lfs_pointers(response)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def map_lfs_pointers(response)
|
|
|
|
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
|
2017-07-07 10:45:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|