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

Commit d47b98c

Browse files
lafrikslunny
authored andcommitted
Fix signature without time parsing to fall back to unix 0 time (#89)
1 parent 576fbdd commit d47b98c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

signature.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
3232
sig.Email = string(line[emailStart+1 : emailEnd])
3333

3434
// Check date format.
35-
firstChar := line[emailEnd+2]
36-
if firstChar >= 48 && firstChar <= 57 {
37-
timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
38-
timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
39-
seconds, _ := strconv.ParseInt(timestring, 10, 64)
40-
sig.When = time.Unix(seconds, 0)
41-
} else {
42-
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
43-
if err != nil {
44-
return nil, err
35+
if len(line) > emailEnd+2 {
36+
firstChar := line[emailEnd+2]
37+
if firstChar >= 48 && firstChar <= 57 {
38+
timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
39+
timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
40+
seconds, _ := strconv.ParseInt(timestring, 10, 64)
41+
sig.When = time.Unix(seconds, 0)
42+
} else {
43+
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
44+
if err != nil {
45+
return nil, err
46+
}
4547
}
48+
} else {
49+
// Fall back to unix 0 time
50+
sig.When = time.Unix(0, 0)
4651
}
4752
return sig, nil
4853
}

0 commit comments

Comments
 (0)