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 ...@@ -374,13 +374,14 @@ module Gitlab
# pseudo-revisions `--not` and `--all`. Uses the minimum of # pseudo-revisions `--not` and `--all`. Uses the minimum of
# GitalyClient.medium_timeout and dynamic timeout if the dynamic # GitalyClient.medium_timeout and dynamic timeout if the dynamic
# timeout is set, otherwise it'll always use the medium timeout. # 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 } revisions = revisions.reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA }
return [] if revisions.blank? return [] if revisions.blank?
wrapped_gitaly_errors do 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
end end
......
...@@ -19,12 +19,13 @@ module Gitlab ...@@ -19,12 +19,13 @@ module Gitlab
consume_blob_response(response) consume_blob_response(response)
end 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( request = Gitaly::ListBlobsRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
revisions: Array.wrap(revisions), revisions: Array.wrap(revisions),
limit: limit, limit: limit,
bytes_limit: bytes_limit bytes_limit: bytes_limit,
with_paths: with_paths
) )
timeout = timeout =
......
...@@ -92,13 +92,14 @@ RSpec.describe Gitlab::GitalyClient::BlobService do ...@@ -92,13 +92,14 @@ RSpec.describe Gitlab::GitalyClient::BlobService do
describe '#list_blobs' do describe '#list_blobs' do
let(:limit) { 0 } let(:limit) { 0 }
let(:bytes_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 before do
::Gitlab::GitalyClient.clear_stubs! ::Gitlab::GitalyClient.clear_stubs!
end 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 context 'with a single revision' do
let(:revisions) { ['master'] } let(:revisions) { ['master'] }
...@@ -147,6 +148,24 @@ RSpec.describe Gitlab::GitalyClient::BlobService do ...@@ -147,6 +148,24 @@ RSpec.describe Gitlab::GitalyClient::BlobService do
end end
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 context 'with split contents' do
let(:revisions) { ['master'] } 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