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,43 +335,18 @@ var goTag = regexp.MustCompile(
// 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 "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) {
const rPrefix = "release.r"
if strings.HasPrefix(goVersion, rPrefix) {
p := "go.r"
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
}
}
}
const wPrefix = "weekly."
if strings.HasPrefix(goVersion, wPrefix) {
p := "go.weekly."
v := goVersion[len(wPrefix):]
for _, t := range tags {
if !strings.HasPrefix(t, p) {
continue
}
if match < t && t[len(p):] <= v {
match = t
}
if t == "go1" {
return "go1"
}
}
return ""
/*
if goTag.MatchString(goVersion) {
v := goVersion
for _, t := range tags {
......@@ -385,6 +360,7 @@ func selectTag(goVersion string, tags []string) (match string) {
}
return match
*/
}
// cmpGoVersion returns -1, 0, +1 reporting whether
......
......@@ -50,6 +50,7 @@ var selectTagTests = []struct {
version string
selected string
}{
/*
{"release.r57", ""},
{"release.r58.2", "go.r58.1"},
{"release.r59", "go.r59"},
......@@ -85,6 +86,8 @@ var selectTagTests = []struct {
{"go200000000000", ""},
{"go2.", ""},
{"go2.0", ""},
*/
{"anything", "go1"},
}
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