diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-18 17:12:41 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-18 17:12:41 +0300 |
commit | d7c7061a9c5f464fa10b450594ff7aeec7aebce6 (patch) | |
tree | 781c383ef2d783b0061ae324524077cc3cf0014f /lib | |
parent | 430b3f0e9ad0e219cffd162374e60739fb3280e2 (diff) | |
parent | 4d87f3bb37ae9db979d42c930603ce233f0565e6 (diff) |
Merge branch 'gitaly-commit-signature' into 'master'
Retrieve commit signatures with Gitaly
Closes gitaly#923
See merge request gitlab-org/gitlab-ce!16467
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/commit.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/commit_service.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/gpg/commit.rb | 8 |
3 files changed, 37 insertions, 6 deletions
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 46e0c0e82a2..768617e2cae 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -239,6 +239,24 @@ module Gitlab end end end + + def extract_signature(repository, commit_id) + repository.gitaly_migrate(:extract_commit_signature) do |is_enabled| + if is_enabled + repository.gitaly_commit_client.extract_signature(commit_id) + else + rugged_extract_signature(repository, commit_id) + end + end + end + + def rugged_extract_signature(repository, commit_id) + begin + Rugged::Commit.extract_signature(repository.rugged, commit_id) + rescue Rugged::OdbError + nil + end + end end def initialize(repository, raw_commit, head = nil) diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index 71b212023d6..2231371cfa7 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -282,6 +282,23 @@ module Gitlab end end + def extract_signature(commit_id) + request = Gitaly::ExtractCommitSignatureRequest.new(repository: @gitaly_repo, commit_id: commit_id) + response = GitalyClient.call(@repository.storage, :commit_service, :extract_commit_signature, request) + + signature = ''.b + signed_text = ''.b + + response.each do |message| + signature << message.signature + signed_text << message.signed_text + end + + return if signature.blank? && signed_text.blank? + + [signature, signed_text] + end + private def call_commit_diff(request_params, options = {}) diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 0f4ba6f83fc..672b5579dfd 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -4,12 +4,8 @@ module Gitlab def initialize(commit) @commit = commit - @signature_text, @signed_text = - begin - Rugged::Commit.extract_signature(@commit.project.repository.rugged, @commit.sha) - rescue Rugged::OdbError - nil - end + repo = commit.project.repository.raw_repository + @signature_text, @signed_text = Gitlab::Git::Commit.extract_signature(repo, commit.sha) end def has_signature? |