Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Meier <r.meier@siemens.com>2019-12-02 22:28:40 +0300
committerJohn Cai <jcai@gitlab.com>2019-12-02 22:28:40 +0300
commitb3dbb922d2827d067d8e7c0f4e4e3cbf4f4d0a90 (patch)
tree2a1b632a6ab31d3487625bec804069369fbfaac7 /internal/git
parent712a6072e8b95f989f54ecfb37cd721f96711d12 (diff)
feat: add signature type to GitCommit
Diffstat (limited to 'internal/git')
-rw-r--r--internal/git/log/commit.go15
-rw-r--r--internal/git/log/tag.go8
2 files changed, 23 insertions, 0 deletions
diff --git a/internal/git/log/commit.go b/internal/git/log/commit.go
index 3fd7a4cfd..421bfd59c 100644
--- a/internal/git/log/commit.go
+++ b/internal/git/log/commit.go
@@ -117,6 +117,8 @@ func buildCommit(header, body []byte, info *catfile.ObjectInfo) (*gitalypb.GitCo
commit.Author = parseCommitAuthor(headerSplit[1])
case "committer":
commit.Committer = parseCommitAuthor(headerSplit[1])
+ case "gpgsig":
+ commit.SignatureType = detectSignatureType(headerSplit[1])
}
}
if err := scanner.Err(); err != nil {
@@ -168,3 +170,16 @@ func parseCommitAuthor(line string) *gitalypb.CommitAuthor {
func subjectFromBody(body []byte) []byte {
return bytes.TrimRight(bytes.SplitN(body, []byte("\n"), 2)[0], "\r\n")
}
+
+func detectSignatureType(line string) gitalypb.SignatureType {
+ switch strings.TrimSuffix(line, "\n") {
+ case "-----BEGIN SIGNED MESSAGE-----":
+ return gitalypb.SignatureType_X509
+ case "-----BEGIN PGP MESSAGE-----":
+ return gitalypb.SignatureType_PGP
+ case "-----BEGIN PGP SIGNATURE-----":
+ return gitalypb.SignatureType_PGP
+ default:
+ return gitalypb.SignatureType_NONE
+ }
+}
diff --git a/internal/git/log/tag.go b/internal/git/log/tag.go
index 9750aca57..6e78cb0db 100644
--- a/internal/git/log/tag.go
+++ b/internal/git/log/tag.go
@@ -119,6 +119,14 @@ func buildAnnotatedTag(b *catfile.Batch, tagID, name string, header *tagHeader,
}
}
+ // tags contain the signature block in the message:
+ // https://github.com/git/git/blob/master/Documentation/technical/signature-format.txt#L12
+ index := bytes.Index([]byte(tag.Message), []byte("-----BEGIN"))
+ if index > 0 {
+ signature := string(tag.Message[index : bytes.Index(tag.Message[index:], []byte("\n"))+index])
+ tag.SignatureType = detectSignatureType(signature)
+ }
+
tag.Tagger = parseCommitAuthor(header.tagger)
return tag, nil