debian-mirror-gitlab/lib/gitlab/gitaly_client/blobs_stitcher.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
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-07-07 11:18:12 +05:30
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-06-08 01:23:25 +05:30
current_blob_data[:data_parts] = [msg.data]
2019-07-07 11:18:12 +05:30
else
2021-06-08 01:23:25 +05:30
current_blob_data[:data_parts] << msg.data
2018-03-17 18:26:18 +05:30
end
end
yield new_blob(current_blob_data) if current_blob_data
end
private
def new_blob(blob_data)
2021-06-08 01:23:25 +05:30
data = blob_data[:data_parts].join
2018-03-17 18:26:18 +05:30
Gitlab::Git::Blob.new(
id: blob_data[:oid],
2021-09-30 23:02:18 +05:30
mode: blob_data[:mode]&.to_s(8),
name: blob_data[:path] && File.basename(blob_data[:path]),
2018-03-17 18:26:18 +05:30
path: blob_data[:path],
size: blob_data[:size],
commit_id: blob_data[:revision],
2021-06-08 01:23:25 +05:30
data: data,
binary: Gitlab::Git::Blob.binary?(data, cache_key: blob_data[:oid])
2018-03-17 18:26:18 +05:30
)
end
end
end
end