1package git23import (4 "bytes"5 "strconv"6 "time"7)89// Signature represents a author or committer.10type Signature struct {11 // The name of the person.12 Name string13 // The email address.14 Email string15 // The time of the signature.16 When time.Time17}1819// parseSignature parses signature information from the (uncompressed) commit20// line, which looks like the following but without the "author " at the21// beginning:22//23// author Patrick Gundlach <gundlach@speedata.de> 1378823654 +020024// author Patrick Gundlach <gundlach@speedata.de> Thu Apr 07 22:13:13 2005 +020025//26// This method should only be used for parsing author and committer.27func parseSignature(line []byte) (*Signature, error) {28 emailStart := bytes.IndexByte(line, '<')29 emailEnd := bytes.IndexByte(line, '>')30 sig := &Signature{31 Name: string(line[:emailStart-1]),32 Email: string(line[emailStart+1 : emailEnd]),33 }3435 // Check the date format36 firstChar := line[emailEnd+2]37 if firstChar >= 48 && firstChar <= 57 { // ASCII code for 0-938 timestop := bytes.IndexByte(line[emailEnd+2:], ' ')39 timestamp := line[emailEnd+2 : emailEnd+2+timestop]40 seconds, err := strconv.ParseInt(string(timestamp), 10, 64)41 if err != nil {42 return nil, err43 }44 sig.When = time.Unix(seconds, 0)45 return sig, nil46 }4748 var err error49 sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))50 if err != nil {51 return nil, err52 }53 return sig, nil54}