Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Add GPG payload to commit information if present #36

Merged
merged 2 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package git

import (
"bufio"
"bytes"
"container/list"
"fmt"
"net/http"
Expand All @@ -22,11 +23,30 @@ type Commit struct {
Author *Signature
Committer *Signature
CommitMessage string
Signature *CommitGPGSignature

parents []SHA1 // SHA1 strings
submoduleCache *ObjectCache
}

// CommitGPGSignature represents a git commit signature part.
type CommitGPGSignature struct {
Signature string
Payload string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sapk Easiest way would be to have a cache-layer for GPG-sigs somewhere, just not just where 🙂

}

// similar to https://github.com/git/git/blob/3bc53220cb2dcf709f7a027a3f526befd021d858/commit.c#L1128
func newGPGSignatureFromCommitline(data []byte, signatureStart int) (*CommitGPGSignature, error) {
sig := new(CommitGPGSignature)
signatureEnd := bytes.LastIndex(data, []byte("-----END PGP SIGNATURE-----"))
if signatureEnd == -1 {
return nil, fmt.Errorf("end of commit signature not found")
}
sig.Signature = strings.Replace(string(data[signatureStart:signatureEnd+27]), "\n ", "\n", -1)
sig.Payload = string(data[:signatureStart-8]) + string(data[signatureEnd+27:])
return sig, nil
}

// Message returns the commit message. Same as retrieving CommitMessage directly.
func (c *Commit) Message() string {
return c.CommitMessage
Expand Down
6 changes: 6 additions & 0 deletions repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ l:
return nil, err
}
commit.Committer = sig
case "gpgsig":
sig, err := newGPGSignatureFromCommitline(data, nextline+spacepos+1)
if err != nil {
return nil, err
}
commit.Signature = sig
}
nextline += eol + 1
case eol == 0:
Expand Down