Skip to content

Commit fd506b6

Browse files
committed
Fix issues with walking commit graph across merges.
Signed-off-by: Filip Navara <[email protected]>
1 parent 3b451d5 commit fd506b6

File tree

2 files changed

+208
-134
lines changed

2 files changed

+208
-134
lines changed

modules/git/commit.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"net/http"
1515
"strconv"
1616
"strings"
17+
18+
"gopkg.in/src-d/go-git.v4/plumbing/object"
1719
)
1820

1921
// Commit represents a git commit.
@@ -52,6 +54,61 @@ func newGPGSignatureFromCommitline(data []byte, signatureStart int, tag bool) (*
5254
return sig, nil
5355
}
5456

57+
func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
58+
if c.PGPSignature == "" {
59+
return nil
60+
}
61+
62+
var w strings.Builder
63+
var err error
64+
65+
if _, err = fmt.Fprintf(&w, "tree %s\n", c.TreeHash.String()); err != nil {
66+
return nil
67+
}
68+
69+
for _, parent := range c.ParentHashes {
70+
if _, err = fmt.Fprintf(&w, "parent %s\n", parent.String()); err != nil {
71+
return nil
72+
}
73+
}
74+
75+
if _, err = fmt.Fprint(&w, "author "); err != nil {
76+
return nil
77+
}
78+
79+
if err = c.Author.Encode(&w); err != nil {
80+
return nil
81+
}
82+
83+
if _, err = fmt.Fprint(&w, "\ncommitter "); err != nil {
84+
return nil
85+
}
86+
87+
if err = c.Committer.Encode(&w); err != nil {
88+
return nil
89+
}
90+
91+
if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
92+
return nil
93+
}
94+
95+
return &CommitGPGSignature{
96+
Signature: c.PGPSignature,
97+
Payload: w.String(),
98+
}
99+
}
100+
101+
func convertCommit(c *object.Commit) *Commit {
102+
return &Commit{
103+
ID: c.Hash,
104+
CommitMessage: c.Message,
105+
Committer: &c.Committer,
106+
Author: &c.Author,
107+
Signature: convertPGPSignature(c),
108+
parents: c.ParentHashes,
109+
}
110+
}
111+
55112
// Message returns the commit message. Same as retrieving CommitMessage directly.
56113
func (c *Commit) Message() string {
57114
return c.CommitMessage

0 commit comments

Comments
 (0)