Commit d09943ae authored by Russ Cox's avatar Russ Cox

cmd/go: new tag selection logic

The new logic is "use go1 if it's there, otherwise no tag."
Nothing needs to say "I require go1.0.1", and I want to
preserve some flexibility in defining what tags mean.

Right now (before go1.0.1) there is only one possible tag,
"go1", and I'd like to keep it that way.

R=golang-dev, bradfitz, r, adg
CC=golang-dev
https://golang.org/cl/6112060
parent e5f2662c
...@@ -335,56 +335,32 @@ var goTag = regexp.MustCompile( ...@@ -335,56 +335,32 @@ var goTag = regexp.MustCompile(
// Version "goX" (or "goX.Y" or "goX.Y.Z") matches tags of the same form. // Version "goX" (or "goX.Y" or "goX.Y.Z") matches tags of the same form.
// Version "release.rN" matches tags of the form "go.rN" (N being a floating-point number). // Version "release.rN" matches tags of the form "go.rN" (N being a floating-point number).
// Version "weekly.YYYY-MM-DD" matches tags like "go.weekly.YYYY-MM-DD". // Version "weekly.YYYY-MM-DD" matches tags like "go.weekly.YYYY-MM-DD".
//
// NOTE(rsc): Eventually we will need to decide on some logic here.
// For now, there is only "go1". This matches the docs in go help get.
func selectTag(goVersion string, tags []string) (match string) { func selectTag(goVersion string, tags []string) (match string) {
const rPrefix = "release.r" for _, t := range tags {
if strings.HasPrefix(goVersion, rPrefix) { if t == "go1" {
p := "go.r" return "go1"
v, err := strconv.ParseFloat(goVersion[len(rPrefix):], 64)
if err != nil {
return ""
}
var matchf float64
for _, t := range tags {
if !strings.HasPrefix(t, p) {
continue
}
tf, err := strconv.ParseFloat(t[len(p):], 64)
if err != nil {
continue
}
if matchf < tf && tf <= v {
match, matchf = t, tf
}
} }
} }
return ""
const wPrefix = "weekly."
if strings.HasPrefix(goVersion, wPrefix) { /*
p := "go.weekly." if goTag.MatchString(goVersion) {
v := goVersion[len(wPrefix):] v := goVersion
for _, t := range tags { for _, t := range tags {
if !strings.HasPrefix(t, p) { if !goTag.MatchString(t) {
continue continue
} }
if match < t && t[len(p):] <= v { if cmpGoVersion(match, t) < 0 && cmpGoVersion(t, v) <= 0 {
match = t match = t
} }
}
}
if goTag.MatchString(goVersion) {
v := goVersion
for _, t := range tags {
if !goTag.MatchString(t) {
continue
}
if cmpGoVersion(match, t) < 0 && cmpGoVersion(t, v) <= 0 {
match = t
} }
} }
}
return match return match
*/
} }
// cmpGoVersion returns -1, 0, +1 reporting whether // cmpGoVersion returns -1, 0, +1 reporting whether
......
...@@ -50,41 +50,44 @@ var selectTagTests = []struct { ...@@ -50,41 +50,44 @@ var selectTagTests = []struct {
version string version string
selected string selected string
}{ }{
{"release.r57", ""}, /*
{"release.r58.2", "go.r58.1"}, {"release.r57", ""},
{"release.r59", "go.r59"}, {"release.r58.2", "go.r58.1"},
{"release.r59.1", "go.r59.1"}, {"release.r59", "go.r59"},
{"release.r60", "go.r59.1"}, {"release.r59.1", "go.r59.1"},
{"release.r60.1", "go.r59.1"}, {"release.r60", "go.r59.1"},
{"release.r61", "go.r61"}, {"release.r60.1", "go.r59.1"},
{"release.r66", "go.r61.1"}, {"release.r61", "go.r61"},
{"weekly.2010-01-01", ""}, {"release.r66", "go.r61.1"},
{"weekly.2010-01-02", "go.weekly.2010-01-02"}, {"weekly.2010-01-01", ""},
{"weekly.2010-01-02.1", "go.weekly.2010-01-02"}, {"weekly.2010-01-02", "go.weekly.2010-01-02"},
{"weekly.2010-01-03", "go.weekly.2010-01-02"}, {"weekly.2010-01-02.1", "go.weekly.2010-01-02"},
{"weekly.2011-10-12", "go.weekly.2011-10-12"}, {"weekly.2010-01-03", "go.weekly.2010-01-02"},
{"weekly.2011-10-12.1", "go.weekly.2011-10-12.1"}, {"weekly.2011-10-12", "go.weekly.2011-10-12"},
{"weekly.2011-10-13", "go.weekly.2011-10-12.1"}, {"weekly.2011-10-12.1", "go.weekly.2011-10-12.1"},
{"weekly.2011-10-14", "go.weekly.2011-10-14"}, {"weekly.2011-10-13", "go.weekly.2011-10-12.1"},
{"weekly.2011-10-14.1", "go.weekly.2011-10-14"}, {"weekly.2011-10-14", "go.weekly.2011-10-14"},
{"weekly.2011-11-01", "go.weekly.2011-11-01"}, {"weekly.2011-10-14.1", "go.weekly.2011-10-14"},
{"weekly.2014-01-01", "go.weekly.2011-11-01"}, {"weekly.2011-11-01", "go.weekly.2011-11-01"},
{"weekly.3000-01-01", "go.weekly.2011-11-01"}, {"weekly.2014-01-01", "go.weekly.2011-11-01"},
{"go1", "go1"}, {"weekly.3000-01-01", "go.weekly.2011-11-01"},
{"go1.1", "go1.0.1"}, {"go1", "go1"},
{"go1.998", "go1.9.2"}, {"go1.1", "go1.0.1"},
{"go1.1000", "go1.999"}, {"go1.998", "go1.9.2"},
{"go6", "go5"}, {"go1.1000", "go1.999"},
{"go6", "go5"},
// faulty versions: // faulty versions:
{"release.f00", ""}, {"release.f00", ""},
{"weekly.1999-01-01", ""}, {"weekly.1999-01-01", ""},
{"junk", ""}, {"junk", ""},
{"", ""}, {"", ""},
{"go2x", ""}, {"go2x", ""},
{"go200000000000", ""}, {"go200000000000", ""},
{"go2.", ""}, {"go2.", ""},
{"go2.0", ""}, {"go2.0", ""},
*/
{"anything", "go1"},
} }
func TestSelectTag(t *testing.T) { func TestSelectTag(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment