@@ -6,7 +6,6 @@ package git
66
77import (
88 "strings"
9- "time"
109
1110 "github.com/mcuadros/go-version"
1211)
@@ -95,84 +94,37 @@ func (repo *Repository) GetTag(name string) (*Tag, error) {
9594 return tag , nil
9695}
9796
98- // TagOption describes tag options
99- type TagOption struct {
100- }
101-
102- // parseTag parse the line
103- // 2016-10-14 20:54:25 +0200 (tag: translation/20161014.01) d3b76dcf2 Dirk Baeumer dirkb@microsoft.com Merge in translations
104- func parseTag (line string , opt TagOption ) (* Tag , error ) {
105- line = strings .TrimSpace (line )
106- if len (line ) < 40 {
107- return nil , nil
108- }
109-
110- var (
111- err error
112- tag Tag
113- sig Signature
114- )
115- sig .When , err = time .Parse ("2006-01-02 15:04:05 -0700" , line [0 :25 ])
116- if err != nil {
117- return nil , err
118- }
119-
120- left := strings .TrimSpace (line [25 :])
121- start := strings .Index (left , "tag: " )
122- if start < 0 {
123- return nil , nil
124- }
125- end := strings .LastIndexByte (left [start + 1 :], ')' )
126- if end < 0 {
127- return nil , nil
128- }
129- end = end + start + 1
130- part := strings .IndexByte (left [start + 5 :end ], ',' )
131- if part > 0 {
132- tag .Name = strings .TrimSpace (left [start + 5 : start + 5 + part ])
133- } else {
134- tag .Name = strings .TrimSpace (left [start + 5 : end ])
135- }
136- next := strings .IndexByte (left [end + 2 :], ' ' )
137- if next < 0 {
138- return nil , nil
139- }
140- tag .Object = MustIDFromString (strings .TrimSpace (left [end + 2 : end + 2 + next ]))
141- next = end + 2 + next
142-
143- emailStart := strings .IndexByte (left [next :], '<' )
144- sig .Name = strings .TrimSpace (left [next :][:emailStart - 1 ])
145- emailEnd := strings .IndexByte (left [next :], '>' )
146- sig .Email = strings .TrimSpace (left [next :][emailStart + 1 : emailEnd ])
147- tag .Tagger = & sig
148- tag .Message = strings .TrimSpace (left [next + emailEnd + 1 :])
149- return & tag , nil
150- }
151-
15297// GetTagInfos returns all tag infos of the repository.
153- func (repo * Repository ) GetTagInfos (opt TagOption ) ([]* Tag , error ) {
154- cmd := NewCommand ( "log" , "--tags" , "--simplify-by-decoration" , `--pretty=format:"%ci %d %H %cn<%ce> %s"` )
155- stdout , err := cmd .RunInDir (repo .Path )
98+ func (repo * Repository ) GetTagInfos () ([]* Tag , error ) {
99+ // TODO this a slow implementation, makes one git command per tag
100+ stdout , err := NewCommand ( "tag" ) .RunInDir (repo .Path )
156101 if err != nil {
157102 return nil , err
158103 }
159104
160- tagSlices := strings .Split (stdout , "\n " )
105+ tagNames := strings .Split (stdout , "\n " )
161106 var tags []* Tag
162- for _ , line := range tagSlices {
163- line := strings .Trim (line , `"` )
164- tag , err := parseTag (line , opt )
107+ for _ , tagName := range tagNames {
108+ tagName = strings .TrimSpace (tagName )
109+ if len (tagName ) == 0 {
110+ continue
111+ }
112+ commitID , err := NewCommand ("rev-parse" , tagName ).RunInDir (repo .Path )
165113 if err != nil {
166114 return nil , err
167115 }
168- if tag != nil {
169- tag . repo = repo
170- tags = append ( tags , tag )
116+ commit , err := repo . GetCommit ( commitID )
117+ if err != nil {
118+ return nil , err
171119 }
120+ tags = append (tags , & Tag {
121+ Name : tagName ,
122+ Message : commit .Message (),
123+ Object : commit .ID ,
124+ Tagger : commit .Author ,
125+ })
172126 }
173-
174127 sortTagsByTime (tags )
175-
176128 return tags , nil
177129}
178130
0 commit comments