123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package git
- import (
- "bytes"
- "strconv"
- "time"
- )
- type Signature struct {
- Email string
- Name string
- When time.Time
- }
- func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
- sig := new(Signature)
- emailStart := bytes.IndexByte(line, '<')
- sig.Name = string(line[:emailStart-1])
- emailEnd := bytes.IndexByte(line, '>')
- sig.Email = string(line[emailStart+1 : emailEnd])
-
- firstChar := line[emailEnd+2]
- if firstChar >= 48 && firstChar <= 57 {
- timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
- timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
- seconds, err := strconv.ParseInt(timestring, 10, 64)
- if err != nil {
- return nil, err
- }
- 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
- }
- }
- return sig, nil
- }
|