summaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modfetch/codehost
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-02-24 16:12:34 -0500
committerGopher Robot <gobot@golang.org>2022-05-10 18:25:37 +0000
commit4d716e4d4a25526ba963a7cfb2b5208eb52e71c0 (patch)
tree4ff4e591ffbeb0eb51904550bcfdfc397ec14887 /src/cmd/go/internal/modfetch/codehost
parent17dc7b487f2406261d638350e4652fc5df224cc2 (diff)
downloadgo-git-4d716e4d4a25526ba963a7cfb2b5208eb52e71c0.tar.gz
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 <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modfetch/codehost')
-rw-r--r--src/cmd/go/internal/modfetch/codehost/codehost.go2
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git.go12
2 files changed, 5 insertions, 9 deletions
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
}