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

Commit

Permalink
Fix signature without time parsing to fall back to unix 0 time (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored and lunny committed Oct 23, 2017
1 parent 576fbdd commit d47b98c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
sig.Email = string(line[emailStart+1 : emailEnd])

// Check date format.
firstChar := line[emailEnd+2]
if firstChar >= 48 && firstChar <= 57 {
timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
seconds, _ := strconv.ParseInt(timestring, 10, 64)
sig.When = time.Unix(seconds, 0)
} else {
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
if err != nil {
return nil, err
if len(line) > emailEnd+2 {
firstChar := line[emailEnd+2]
if firstChar >= 48 && firstChar <= 57 {
timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
seconds, _ := strconv.ParseInt(timestring, 10, 64)
sig.When = time.Unix(seconds, 0)
} else {
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
if err != nil {
return nil, err
}
}
} else {
// Fall back to unix 0 time
sig.When = time.Unix(0, 0)
}
return sig, nil
}

0 comments on commit d47b98c

Please sign in to comment.