OLD | NEW |
| 1 // Copyright 2011 The Go Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style |
| 3 // license that can be found in the LICENSE file. |
| 4 |
1 package main | 5 package main |
2 | 6 |
3 import ( | 7 import ( |
4 "fmt" | 8 "fmt" |
5 "os" | 9 "os" |
| 10 "regexp" |
6 "strconv" | 11 "strconv" |
7 "strings" | 12 "strings" |
8 ) | 13 ) |
9 | 14 |
10 type Commit struct { | 15 type Commit struct { |
11 num int // mercurial revision number | 16 num int // mercurial revision number |
12 node string // mercurial hash | 17 node string // mercurial hash |
13 parent string // hash of commit's parent | 18 parent string // hash of commit's parent |
14 user string // author's Name <email> | 19 user string // author's Name <email> |
15 date string // date of commit | 20 date string // date of commit |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 "--encoding", "utf-8", | 55 "--encoding", "utf-8", |
51 "--rev", rev, | 56 "--rev", rev, |
52 "--limit", "1", | 57 "--limit", "1", |
53 "--template", format, | 58 "--template", format, |
54 ) | 59 ) |
55 if err != nil { | 60 if err != nil { |
56 return | 61 return |
57 } | 62 } |
58 return strings.Split(s, ">", 5), nil | 63 return strings.Split(s, ">", 5), nil |
59 } | 64 } |
| 65 |
| 66 var revisionRe = regexp.MustCompile(`([0-9]+):[0-9a-f]+$`) |
| 67 |
| 68 // getTag fetches a Commit by finding the first hg tag that matches re. |
| 69 func getTag(re *regexp.Regexp) (c Commit, tag string, err os.Error) { |
| 70 o, _, err := runLog(nil, "", goroot, "hg", "tags") |
| 71 for _, l := range strings.Split(o, "\n", -1) { |
| 72 tag = re.FindString(l) |
| 73 if tag == "" { |
| 74 continue |
| 75 } |
| 76 s := revisionRe.FindStringSubmatch(l) |
| 77 if s == nil { |
| 78 err = os.NewError("couldn't find revision number") |
| 79 return |
| 80 } |
| 81 c, err = getCommit(s[1]) |
| 82 return |
| 83 } |
| 84 err = os.NewError("no matching tag found") |
| 85 return |
| 86 } |
OLD | NEW |