1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:16:17 -07:00

cmd/go: fix handling of gopkg.in/macaroon-bakery.v2-unstable

When we added v2.0.0+incompatible we generalized the API
enough to make it easy to also accepting these gopkg-specific
v2-unstable suffixes. Do that.

Fixes #23989.

Change-Id: Ieabed11a5250c2999d73450c10b20f4c645ad445
Reviewed-on: https://go-review.googlesource.com/128901
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Russ Cox 2018-08-09 17:03:05 -04:00
parent 9f5336d8d0
commit 479da24aac
6 changed files with 49 additions and 4 deletions

View File

@ -86,6 +86,13 @@ func (r *codeRepo) ModulePath() string {
}
func (r *codeRepo) Versions(prefix string) ([]string, error) {
// Special case: gopkg.in/macaroon-bakery.v2-unstable
// does not use the v2 tags (those are for macaroon-bakery.v2).
// It has no possible tags at all.
if strings.HasPrefix(r.modPath, "gopkg.in/") && strings.HasSuffix(r.modPath, "-unstable") {
return nil, nil
}
p := prefix
if r.codeDir != "" {
p = r.codeDir + "/" + p

View File

@ -49,6 +49,7 @@ func PseudoVersion(major, older string, t time.Time, rev string) string {
if major == "" {
major = "v0"
}
major = strings.TrimSuffix(major, "-unstable") // make gopkg.in/macaroon-bakery.v2-unstable use "v2"
segment := fmt.Sprintf("%s-%s", t.UTC().Format("20060102150405"), rev)
build := semver.Build(older)
older = semver.Canonical(older)

View File

@ -143,7 +143,7 @@ func CheckPath(path string) error {
}
}
if _, _, ok := SplitPathVersion(path); !ok {
return fmt.Errorf("malformed module path %q: invalid version %s", path, path[strings.LastIndex(path, "/")+1:])
return fmt.Errorf("malformed module path %q: invalid version", path)
}
return nil
}
@ -300,6 +300,9 @@ func splitGopkgIn(path string) (prefix, pathMajor string, ok bool) {
return path, "", false
}
i := len(path)
if strings.HasSuffix(path, "-unstable") {
i -= len("-unstable")
}
for i > 0 && ('0' <= path[i-1] && path[i-1] <= '9') {
i--
}
@ -317,6 +320,9 @@ func splitGopkgIn(path string) (prefix, pathMajor string, ok bool) {
// MatchPathMajor reports whether the semantic version v
// matches the path major version pathMajor.
func MatchPathMajor(v, pathMajor string) bool {
if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
}
if strings.HasPrefix(v, "v0.0.0-") && pathMajor == ".v1" {
// Allow old bug in pseudo-versions that generated v0.0.0- pseudoversion for gopkg .v1.
// For example, gopkg.in/yaml.v2@v2.2.1's go.mod requires gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405.

View File

@ -81,13 +81,13 @@ func readModList() {
encPath := strings.Replace(name[:i], "_", "/", -1)
path, err := module.DecodePath(encPath)
if err != nil {
fmt.Fprintf(os.Stderr, "go proxy_test: %v", err)
fmt.Fprintf(os.Stderr, "go proxy_test: %v\n", err)
continue
}
encVers := name[i+1:]
vers, err := module.DecodeVersion(encVers)
if err != nil {
fmt.Fprintf(os.Stderr, "go proxy_test: %v", err)
fmt.Fprintf(os.Stderr, "go proxy_test: %v\n", err)
continue
}
modList = append(modList, module.Version{Path: path, Version: vers})
@ -140,7 +140,7 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) {
encVers, ext := file[:i], file[i+1:]
vers, err := module.DecodeVersion(encVers)
if err != nil {
fmt.Fprintf(os.Stderr, "go proxy_test: %v", err)
fmt.Fprintf(os.Stderr, "go proxy_test: %v\n", err)
http.NotFound(w, r)
return
}

View File

@ -0,0 +1,9 @@
gopkg.in/dummy.v2-unstable v2.0.0
written by hand
-- .mod --
module gopkg.in/dummy.v2-unstable
-- .info --
{"Version":"v2.0.0"}
-- dummy.go --
package dummy

View File

@ -0,0 +1,22 @@
env GO111MODULE=on
cp go.mod.empty go.mod
go get -d gopkg.in/dummy.v2-unstable
cp x.go.txt x.go
cp go.mod.empty go.mod
go list
[!net] skip
env GOPROXY=
go get gopkg.in/macaroon-bakery.v2-unstable/bakery
go list -m all
stdout 'gopkg.in/macaroon-bakery.v2-unstable v2.0.0-[0-9]+-[0-9a-f]+$'
-- go.mod.empty --
module m
-- x.go.txt --
package x
import _ "gopkg.in/dummy.v2-unstable"