@@ -6,6 +6,7 @@ package git
6
6
7
7
import (
8
8
"strings"
9
+ "time"
9
10
10
11
"github.com/mcuadros/go-version"
11
12
)
@@ -94,6 +95,87 @@ func (repo *Repository) GetTag(name string) (*Tag, error) {
94
95
return tag , nil
95
96
}
96
97
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 [email protected] 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 .IndexByte (left [start + 1 :], ')' )
126
+ if end < 0 {
127
+ return nil , nil
128
+ }
129
+ end = end + start + 1
130
+ part := strings .IndexByte (left [start + 6 :end ], ',' )
131
+ if part > 0 {
132
+ tag .Name = strings .TrimSpace (left [start + 6 : start + 6 + part ])
133
+ } else {
134
+ tag .Name = strings .TrimSpace (left [start + 6 : 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
+
152
+ // 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 )
156
+ if err != nil {
157
+ return nil , err
158
+ }
159
+
160
+ tagSlices := strings .Split (stdout , "\n " )
161
+ var tags []* Tag
162
+ for _ , line := range tagSlices {
163
+ line := strings .Trim (line , `"` )
164
+ tag , err := parseTag (line , opt )
165
+ if err != nil {
166
+ return nil , err
167
+ }
168
+ if tag != nil {
169
+ tag .repo = repo
170
+ tags = append (tags , tag )
171
+ }
172
+ }
173
+
174
+ sortTagsByTime (tags )
175
+
176
+ return tags , nil
177
+ }
178
+
97
179
// GetTags returns all tags of the repository.
98
180
func (repo * Repository ) GetTags () ([]string , error ) {
99
181
cmd := NewCommand ("tag" , "-l" )
0 commit comments