BigW Consortium Gitlab

Commit 8c77ae2d by Robert Speicher

Merge branch 'gitaly-764-commit-filter-shas-with-signature' into 'master'

Migrate Gitlab::Git::Commit.shas_with_signature Closes gitaly#764 See merge request gitlab-org/gitlab-ce!15621
parents 93032262 49dd62ad
...@@ -213,11 +213,17 @@ module Gitlab ...@@ -213,11 +213,17 @@ module Gitlab
end end
def shas_with_signatures(repository, shas) def shas_with_signatures(repository, shas)
shas.select do |sha| GitalyClient.migrate(:filter_shas_with_signatures) do |is_enabled|
begin if is_enabled
Rugged::Commit.extract_signature(repository.rugged, sha) Gitlab::GitalyClient::CommitService.new(repository).filter_shas_with_signatures(shas)
rescue Rugged::OdbError else
false shas.select do |sha|
begin
Rugged::Commit.extract_signature(repository.rugged, sha)
rescue Rugged::OdbError
false
end
end
end end
end end
end end
......
...@@ -250,6 +250,26 @@ module Gitlab ...@@ -250,6 +250,26 @@ module Gitlab
consume_commits_response(response) consume_commits_response(response)
end end
def filter_shas_with_signatures(shas)
request = Gitaly::FilterShasWithSignaturesRequest.new(repository: @gitaly_repo)
enum = Enumerator.new do |y|
shas.each_slice(20) do |revs|
request.shas = GitalyClient.encode_repeated(revs)
y.yield request
request = Gitaly::FilterShasWithSignaturesRequest.new
end
end
response = GitalyClient.call(@repository.storage, :commit_service, :filter_shas_with_signatures, enum)
response.flat_map do |msg|
msg.shas.map { |sha| EncodingHelper.encode!(sha) }
end
end
private private
def call_commit_diff(request_params, options = {}) def call_commit_diff(request_params, options = {})
......
...@@ -278,6 +278,35 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -278,6 +278,35 @@ describe Gitlab::Git::Commit, seed_helper: true do
it { is_expected.not_to include(SeedRepo::FirstCommit::ID) } it { is_expected.not_to include(SeedRepo::FirstCommit::ID) }
end end
shared_examples '.shas_with_signatures' do
let(:signed_shas) { %w[5937ac0a7beb003549fc5fd26fc247adbce4a52e 570e7b2abdd848b95f2f578043fc23bd6f6fd24d] }
let(:unsigned_shas) { %w[19e2e9b4ef76b422ce1154af39a91323ccc57434 c642fe9b8b9f28f9225d7ea953fe14e74748d53b] }
let(:first_signed_shas) { %w[5937ac0a7beb003549fc5fd26fc247adbce4a52e c642fe9b8b9f28f9225d7ea953fe14e74748d53b] }
it 'has 2 signed shas' do
ret = described_class.shas_with_signatures(repository, signed_shas)
expect(ret).to eq(signed_shas)
end
it 'has 0 signed shas' do
ret = described_class.shas_with_signatures(repository, unsigned_shas)
expect(ret).to eq([])
end
it 'has 1 signed sha' do
ret = described_class.shas_with_signatures(repository, first_signed_shas)
expect(ret).to contain_exactly(first_signed_shas.first)
end
end
describe '.shas_with_signatures with gitaly on' do
it_should_behave_like '.shas_with_signatures'
end
describe '.shas_with_signatures with gitaly disabled', :disable_gitaly do
it_should_behave_like '.shas_with_signatures'
end
describe '.find_all' do describe '.find_all' do
shared_examples 'finding all commits' do shared_examples 'finding all commits' do
it 'should return a return a collection of commits' do it 'should return a return a collection of commits' do
......
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