signature.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "bytes"
  7. "strconv"
  8. "time"
  9. )
  10. // Author and Committer information
  11. type Signature struct {
  12. Email string
  13. Name string
  14. When time.Time
  15. }
  16. // Helper to get a signature from the commit line, which looks like this:
  17. // author Patrick Gundlach <gundlach@speedata.de> 1378823654 +0200
  18. // but without the "author " at the beginning (this method should)
  19. // be used for author and committer.
  20. //
  21. // FIXME: include timezone!
  22. func newSignatureFromCommitline(line []byte) (*Signature, error) {
  23. sig := new(Signature)
  24. emailstart := bytes.IndexByte(line, '<')
  25. sig.Name = string(line[:emailstart-1])
  26. emailstop := bytes.IndexByte(line, '>')
  27. sig.Email = string(line[emailstart+1 : emailstop])
  28. timestop := bytes.IndexByte(line[emailstop+2:], ' ')
  29. timestring := string(line[emailstop+2 : emailstop+2+timestop])
  30. seconds, err := strconv.ParseInt(timestring, 10, 64)
  31. if err != nil {
  32. return nil, err
  33. }
  34. sig.When = time.Unix(seconds, 0)
  35. return sig, nil
  36. }