]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch/codehost: replace a dubious call to semver.Max
authorBryan C. Mills <bcmills@google.com>
Fri, 20 Dec 2019 04:17:55 +0000 (23:17 -0500)
committerBryan C. Mills <bcmills@google.com>
Fri, 20 Dec 2019 15:34:39 +0000 (15:34 +0000)
The documentation for RecentTag indicates that it returns an actual
tag, not a canonicalized prefix+version blob equivalent to a tag,
so the canonicalization due to semver.Max seems like a bug here.

Fortunately, RecentTag is not currently ever actually used as a tag,
so the removal of metadata does not result in a user-facing bug.
Nonetheless, it may be a subtle source of confusion for maintainers
in the future.

Updates #32700

Change-Id: I525423c1c0c7ec7c36c09e53b180034474f74e5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/212202
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modfetch/codehost/git.go
src/cmd/go/internal/modload/query_test.go

index e329cbc58e7d1ecdf9f52547d2dec19264e1ecd2..f08df512f02539bcadfce7b112c99bfef33e6f9f 100644 (file)
@@ -682,8 +682,11 @@ func (r *gitRepo) RecentTag(rev, prefix, major string) (tag string, err error) {
 
                        semtag := line[len(prefix):]
                        // Consider only tags that are valid and complete (not just major.minor prefixes).
-                       if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) {
-                               highest = semver.Max(highest, semtag)
+                       // NOTE: Do not replace the call to semver.Compare with semver.Max.
+                       // We want to return the actual tag, not a canonicalized version of it,
+                       // and semver.Max currently canonicalizes (see golang.org/issue/32700).
+                       if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) && semver.Compare(semtag, highest) > 0 {
+                               highest = semtag
                        }
                }
 
index 9c91c05e5f821442950b8f24473b42c78e246643..bad34f088d500ae0309d2a87a30fd6f033c26d37 100644 (file)
@@ -64,7 +64,7 @@ var queryTests = []struct {
                git add go.mod
                git commit -m v1 go.mod
                git tag start
-               for i in v0.0.0-pre1 v0.0.0 v0.0.1 v0.0.2 v0.0.3 v0.1.0 v0.1.1 v0.1.2 v0.3.0 v1.0.0 v1.1.0 v1.9.0 v1.9.9 v1.9.10-pre1 v1.9.10-pre2+metadata; do
+               for i in v0.0.0-pre1 v0.0.0 v0.0.1 v0.0.2 v0.0.3 v0.1.0 v0.1.1 v0.1.2 v0.3.0 v1.0.0 v1.1.0 v1.9.0 v1.9.9 v1.9.10-pre1 v1.9.10-pre2+metadata unversioned; do
                        echo before $i >status
                        git add status
                        git commit -m "before $i" status
@@ -107,6 +107,7 @@ var queryTests = []struct {
        {path: queryRepo, query: "v0.2", err: `no matching versions for query "v0.2"`},
        {path: queryRepo, query: "v0.0", vers: "v0.0.3"},
        {path: queryRepo, query: "v1.9.10-pre2+metadata", vers: "v1.9.10-pre2.0.20190513201126-42abcb6df8ee"},
+       {path: queryRepo, query: "ed5ffdaa", vers: "v1.9.10-pre2.0.20191220134614-ed5ffdaa1f5e"},
 
        // golang.org/issue/29262: The major version for for a module without a suffix
        // should be based on the most recent tag (v1 as appropriate, not v0