2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-01 14:56:41 -05:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class BlobsStitcher
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
def initialize(rpc_response)
|
|
|
|
@rpc_response = rpc_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
current_blob_data = nil
|
|
|
|
|
|
|
|
@rpc_response.each do |msg|
|
2019-03-13 09:42:43 -04:00
|
|
|
if msg.oid.blank? && msg.data.blank?
|
|
|
|
next
|
|
|
|
elsif msg.oid.present?
|
|
|
|
yield new_blob(current_blob_data) if current_blob_data
|
|
|
|
|
|
|
|
current_blob_data = msg.to_h.slice(:oid, :path, :size, :revision, :mode)
|
2021-04-28 17:10:01 -04:00
|
|
|
current_blob_data[:data_parts] = [msg.data]
|
2019-03-13 09:42:43 -04:00
|
|
|
else
|
2021-04-28 17:10:01 -04:00
|
|
|
current_blob_data[:data_parts] << msg.data
|
2018-02-01 14:56:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
yield new_blob(current_blob_data) if current_blob_data
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def new_blob(blob_data)
|
2021-04-28 17:10:01 -04:00
|
|
|
data = blob_data[:data_parts].join
|
|
|
|
|
2018-02-01 14:56:41 -05:00
|
|
|
Gitlab::Git::Blob.new(
|
|
|
|
id: blob_data[:oid],
|
2021-06-24 11:07:28 -04:00
|
|
|
mode: blob_data[:mode]&.to_s(8),
|
|
|
|
name: blob_data[:path] && File.basename(blob_data[:path]),
|
2018-02-01 14:56:41 -05:00
|
|
|
path: blob_data[:path],
|
|
|
|
size: blob_data[:size],
|
|
|
|
commit_id: blob_data[:revision],
|
2021-04-28 17:10:01 -04:00
|
|
|
data: data,
|
2021-05-06 08:10:38 -04:00
|
|
|
binary: Gitlab::Git::Blob.binary?(data, cache_key: blob_data[:oid])
|
2018-02-01 14:56:41 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|