From 4d716e4d4a25526ba963a7cfb2b5208eb52e71c0 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 24 Feb 2022 16:12:34 -0500 Subject: cmd/go/internal/modfetch: simplify handling of weird version tags This fixes an obscure bug in 'go list -versions' if the repo contains a tag with an explicit "+incompatible" suffix. However, I've never seen such a repo in the wild; mostly it's an attempt to wrap my brain around the code and simplify things a bit for the future. Updates #51324 Updates #51312 Change-Id: I1b078b5db36470cf61aaa85b5244c99b5ee2c842 Reviewed-on: https://go-review.googlesource.com/c/go/+/387917 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob --- src/cmd/go/internal/modfetch/codehost/codehost.go | 2 +- src/cmd/go/internal/modfetch/codehost/git.go | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/cmd/go/internal/modfetch/codehost') diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go index 31dc811752..e08a84b32c 100644 --- a/src/cmd/go/internal/modfetch/codehost/codehost.go +++ b/src/cmd/go/internal/modfetch/codehost/codehost.go @@ -65,7 +65,7 @@ type Repo interface { // RecentTag returns the most recent tag on rev or one of its predecessors // with the given prefix. allowed may be used to filter out unwanted versions. - RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) + RecentTag(rev, prefix string, allowed func(tag string) bool) (tag string, err error) // DescendsFrom reports whether rev or any of its ancestors has the given tag. // diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index 9c8fd42833..853d43bc5b 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -523,7 +523,7 @@ func (r *gitRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) { return out, nil } -func (r *gitRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) { +func (r *gitRepo) RecentTag(rev, prefix string, allowed func(tag string) bool) (tag string, err error) { info, err := r.Stat(rev) if err != nil { return "", err @@ -553,15 +553,11 @@ func (r *gitRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag if !strings.HasPrefix(line, prefix) { continue } - - semtag := line[len(prefix):] - // Consider only tags that are valid and complete (not just major.minor prefixes). - // 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) || !allowed(semtag) { + if !allowed(line) { continue } + + semtag := line[len(prefix):] if semver.Compare(semtag, highest) > 0 { highest = semtag } -- cgit v1.2.1