@@ -109,6 +109,7 @@ func (d *Diff) finalize() error { return d.contentWriter.CloseForWriting() }
109
109
// Commit contains commit header info and diffs.
110
110
type Commit struct {
111
111
Hash string
112
+ SourceRef string
112
113
Author string
113
114
Committer string
114
115
Date time.Time
@@ -230,13 +231,16 @@ func (c *Parser) RepoPath(ctx context.Context, source string, head string, abbre
230
231
"--date=format:%a %b %d %H:%M:%S %Y %z" ,
231
232
"--pretty=fuller" , // https://git-scm.com/docs/git-log#_pretty_formats
232
233
"--notes" , // https://git-scm.com/docs/git-log#Documentation/git-log.txt---notesltrefgt
234
+ "--source" , // https://git-scm.com/docs/git-log#Documentation/git-log.txt---source
233
235
}
234
236
if abbreviatedLog {
237
+ // https://git-scm.com/docs/git-log#Documentation/git-log.txt---diff-filterACDMRTUXB82308203
235
238
args = append (args , "--diff-filter=AM" )
236
239
}
237
240
if head != "" {
238
241
args = append (args , head )
239
242
} else {
243
+ // https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
240
244
args = append (args , "--all" )
241
245
}
242
246
for _ , glob := range excludedGlobs {
@@ -323,10 +327,9 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan
323
327
outReader := bufio .NewReader (stdOut )
324
328
var (
325
329
currentCommit * Commit
326
-
327
- totalLogSize int
330
+ totalLogSize int
331
+ latestState = Initial
328
332
)
329
- var latestState = Initial
330
333
331
334
diff := func (c * Commit , opts ... diffOption ) * Diff {
332
335
opts = append (opts , withCustomContentWriter (bufferwriter .New ()))
@@ -386,10 +389,18 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan
386
389
// Create a new currentDiff and currentCommit
387
390
currentCommit = & Commit {Message : strings.Builder {}}
388
391
currentDiff = diff (currentCommit )
389
- // Check that the commit line contains a hash and set it.
390
- if len (line ) >= 47 {
391
- currentCommit .Hash = string (line [7 :47 ])
392
+
393
+ hash , ref := parseCommitLine (line )
394
+ if hash == nil || ref == nil {
395
+ ctx .Logger ().Error (
396
+ fmt .Errorf (`expected line to match 'commit <hash> <ref>', got "%s"` , line ),
397
+ "Failed to parse CommitLine" )
398
+ latestState = ParseFailure
399
+ continue
392
400
}
401
+
402
+ currentCommit .Hash = string (hash )
403
+ currentCommit .SourceRef = string (ref )
393
404
case isMergeLine (isStaged , latestState , line ):
394
405
latestState = MergeLine
395
406
case isAuthorLine (isStaged , latestState , line ):
@@ -605,6 +616,22 @@ func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool {
605
616
return false
606
617
}
607
618
619
+ func parseCommitLine (line []byte ) (hash []byte , ref []byte ) {
620
+ // Check that the commit line contains a 40-character hash and set it.
621
+ // `commit e5575cd6f2d21d3a1a604287c7bf4a7eab2266e0\n`
622
+ if len (line ) >= 47 {
623
+ hash = line [7 :47 ]
624
+ }
625
+
626
+ // Check if the commit line includes branch references.
627
+ // `commit 2dbbb28727c7c2954438666dafba57bb8c714d3b refs/heads/fix/github-enterprise-gist\n`
628
+ if len (line ) > 48 {
629
+ ref = line [48 : len (line )- 1 ]
630
+ }
631
+
632
+ return
633
+ }
634
+
608
635
// Author: Bill Rich <[email protected] >
609
636
func isAuthorLine (isStaged bool , latestState ParseState , line []byte ) bool {
610
637
if isStaged || ! (latestState == CommitLine || latestState == MergeLine ) {
0 commit comments