Commit 1994c891 authored by Patrick Steinhardt's avatar Patrick Steinhardt

repository: Allow listing blobs with paths

By default, the ListBlobs RPC will not return file paths of returned
blobs, but we need them when listing new blobs via ListBlobs such that
we can tell users exactly which file is too big in our push rules.

Expose a new `with_paths` parameter, which cause us to request blob
paths from Gitaly.
parent 9ad372d6
......@@ -374,13 +374,14 @@ module Gitlab
# 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)
def blobs(revisions, with_paths: false, 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)
gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT,
with_paths: with_paths, dynamic_timeout: dynamic_timeout)
end
end
......
......@@ -19,12 +19,13 @@ module Gitlab
consume_blob_response(response)
end
def list_blobs(revisions, limit: 0, bytes_limit: 0, dynamic_timeout: nil)
def list_blobs(revisions, limit: 0, bytes_limit: 0, with_paths: false, dynamic_timeout: nil)
request = Gitaly::ListBlobsRequest.new(
repository: @gitaly_repo,
revisions: Array.wrap(revisions),
limit: limit,
bytes_limit: bytes_limit
bytes_limit: bytes_limit,
with_paths: with_paths
)
timeout =
......
......@@ -92,13 +92,14 @@ RSpec.describe Gitlab::GitalyClient::BlobService do
describe '#list_blobs' do
let(:limit) { 0 }
let(:bytes_limit) { 0 }
let(:expected_params) { { revisions: revisions, limit: limit, bytes_limit: bytes_limit } }
let(:with_paths) { false }
let(:expected_params) { { revisions: revisions, limit: limit, bytes_limit: bytes_limit, with_paths: with_paths } }
before do
::Gitlab::GitalyClient.clear_stubs!
end
subject { client.list_blobs(revisions, limit: limit, bytes_limit: bytes_limit) }
subject { client.list_blobs(revisions, limit: limit, bytes_limit: bytes_limit, with_paths: with_paths) }
context 'with a single revision' do
let(:revisions) { ['master'] }
......@@ -147,6 +148,24 @@ RSpec.describe Gitlab::GitalyClient::BlobService do
end
end
context 'with paths' do
let(:revisions) { ['master'] }
let(:limit) { 10 }
let(:bytes_lmit) { 1024 }
let(:with_paths) { true }
it 'sends a list_blobs message' do
expect_next_instance_of(Gitaly::BlobService::Stub) do |service|
expect(service)
.to receive(:list_blobs)
.with(gitaly_request_with_params(expected_params), kind_of(Hash))
.and_return([])
end
subject
end
end
context 'with split contents' do
let(:revisions) { ['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