Commit ab35492c authored by Patrick Steinhardt's avatar Patrick Steinhardt

repository: Add new `#blobs` function to enumerate blobs

Now that the `BlobService` has support for enumerating blobs via a the
new Gitaly RPC `#list_blobs`, implement support for reading blobs via
`Repository#blobs`.
parent 121bc0af
......@@ -370,6 +370,20 @@ module Gitlab
end
end
# List blobs reachable via a set of revisions. Supports the
# pseudo-revisions `--not` and `--all`. Uses the minimum of
# GitalyClient.medium_timeout and dynamic timeout if the dynamic
# timeout is set, otherwise it'll always use the medium timeout.
def blobs(revisions, dynamic_timeout: nil)
revisions = revisions.reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA }
return [] if revisions.blank?
wrapped_gitaly_errors do
gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT, dynamic_timeout: dynamic_timeout)
end
end
def count_commits(options)
options = process_count_commits_options(options.dup)
......
......@@ -869,6 +869,71 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
describe '#blobs' do
let_it_be(:commit_oid) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' }
shared_examples 'a blob enumeration' do
it 'enumerates blobs' do
blobs = repository.blobs(revisions).to_a
expect(blobs.size).to eq(expected_blobs)
blobs.each do |blob|
expect(blob.data).to be_empty
expect(blob.id.size).to be(40)
end
end
end
context 'single revision' do
let(:revisions) { [commit_oid] }
let(:expected_blobs) { 53 }
it_behaves_like 'a blob enumeration'
end
context 'multiple revisions' do
let(:revisions) { ["^#{commit_oid}~", commit_oid] }
let(:expected_blobs) { 1 }
it_behaves_like 'a blob enumeration'
end
context 'pseudo revisions' do
let(:revisions) { ['master', '--not', '--all'] }
let(:expected_blobs) { 0 }
it_behaves_like 'a blob enumeration'
end
context 'blank revisions' do
let(:revisions) { [::Gitlab::Git::BLANK_SHA] }
let(:expected_blobs) { 0 }
before do
expect_any_instance_of(Gitlab::GitalyClient::BlobService)
.not_to receive(:list_blobs)
end
it_behaves_like 'a blob enumeration'
end
context 'partially blank revisions' do
let(:revisions) { [::Gitlab::Git::BLANK_SHA, commit_oid] }
let(:expected_blobs) { 53 }
before do
expect_next_instance_of(Gitlab::GitalyClient::BlobService) do |service|
expect(service)
.to receive(:list_blobs)
.with([commit_oid], kind_of(Hash))
.and_call_original
end
end
it_behaves_like 'a blob enumeration'
end
end
describe '#count_commits_between' do
subject { repository.count_commits_between('feature', 'master') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment