tag.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. )
  8. // Tag represents a Git tag.
  9. type Tag struct {
  10. Name string
  11. Id sha1
  12. repo *Repository
  13. Object sha1 // The id of this commit object
  14. Type string
  15. Tagger *Signature
  16. TagMessage string
  17. }
  18. func (tag *Tag) Commit() (*Commit, error) {
  19. return tag.repo.getCommit(tag.Object)
  20. }
  21. // Parse commit information from the (uncompressed) raw
  22. // data from the commit object.
  23. // \n\n separate headers from message
  24. func parseTagData(data []byte) (*Tag, error) {
  25. tag := new(Tag)
  26. // we now have the contents of the commit object. Let's investigate...
  27. nextline := 0
  28. l:
  29. for {
  30. eol := bytes.IndexByte(data[nextline:], '\n')
  31. switch {
  32. case eol > 0:
  33. line := data[nextline : nextline+eol]
  34. spacepos := bytes.IndexByte(line, ' ')
  35. reftype := line[:spacepos]
  36. switch string(reftype) {
  37. case "object":
  38. id, err := NewIdFromString(string(line[spacepos+1:]))
  39. if err != nil {
  40. return nil, err
  41. }
  42. tag.Object = id
  43. case "type":
  44. // A commit can have one or more parents
  45. tag.Type = string(line[spacepos+1:])
  46. case "tagger":
  47. sig, err := newSignatureFromCommitline(line[spacepos+1:])
  48. if err != nil {
  49. return nil, err
  50. }
  51. tag.Tagger = sig
  52. }
  53. nextline += eol + 1
  54. case eol == 0:
  55. tag.TagMessage = string(data[nextline+1:])
  56. break l
  57. default:
  58. break l
  59. }
  60. }
  61. return tag, nil
  62. }