2017-07-07 10:45:52 -04:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
2017-07-18 03:59:36 -04:00
|
|
|
class BlobService
|
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
|
|
|
|
)
|
|
|
|
response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request)
|
|
|
|
|
|
|
|
blob = response.first
|
|
|
|
return unless blob.oid.present?
|
|
|
|
|
|
|
|
data = response.reduce(blob.data.dup) { |memo, msg| memo << msg.data.dup }
|
|
|
|
|
|
|
|
Gitlab::Git::Blob.new(
|
|
|
|
id: blob.oid,
|
|
|
|
size: blob.size,
|
|
|
|
data: data,
|
|
|
|
binary: Gitlab::Git::Blob.binary?(data)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|