]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: make QueryPattern consider current versions
authorJay Conrod <jayconrod@google.com>
Fri, 1 May 2020 19:30:58 +0000 (15:30 -0400)
committerJay Conrod <jayconrod@google.com>
Mon, 4 May 2020 16:50:30 +0000 (16:50 +0000)
QueryPattern will now look up the current version of a module (if any)
before invoking queryProxy. This changes the interpretation of some
patterns (like "upgrade") and avoids the need to download earlier
versions for earlier versions when the current version is
+incompatible.

Fixes #37574

Change-Id: I4089d6099236493df13a7f88a252b5e5e556d383
Reviewed-on: https://go-review.googlesource.com/c/go/+/231599
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modload/query.go
src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt [new file with mode: 0644]

index f8ea7e630924cdd93d0791dfaeeca9bf9458ad7a..5e9cfdcfe3dd2c20ebb556884d441bca7a60677f 100644 (file)
@@ -455,8 +455,9 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
 
        err := modfetch.TryProxies(func(proxy string) error {
                queryModule := func(path string) (r QueryResult, err error) {
+                       current := findCurrentVersion(path)
                        r.Mod.Path = path
-                       r.Rev, err = queryProxy(proxy, path, query, "", allowed)
+                       r.Rev, err = queryProxy(proxy, path, query, current, allowed)
                        if err != nil {
                                return r, err
                        }
@@ -508,6 +509,15 @@ func modulePrefixesExcludingTarget(path string) []string {
        return prefixes
 }
 
+func findCurrentVersion(path string) string {
+       for _, m := range buildList {
+               if m.Path == path {
+                       return m.Version
+               }
+       }
+       return ""
+}
+
 type prefixResult struct {
        QueryResult
        err error
diff --git a/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt b/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt
new file mode 100644 (file)
index 0000000..435578d
--- /dev/null
@@ -0,0 +1,8 @@
+Module example.com/incompatiblewithsub has an incompatible version
+and a package in a subdirectory.
+-- .info --
+{"Version":"v1.0.0"}
+-- .mod --
+module example.com/incompatiblewithsub
+-- sub/sub.go --
+package sub
diff --git a/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt b/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt
new file mode 100644 (file)
index 0000000..198ec17
--- /dev/null
@@ -0,0 +1,8 @@
+Module example.com/incompatiblewithsub has an incompatible version
+and a package in a subdirectory.
+-- .info --
+{"Version":"v2.0.0+incompatible"}
+-- .mod --
+module example.com/incompatiblewithsub
+-- sub/sub.go --
+package sub
diff --git a/src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt b/src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt
new file mode 100644 (file)
index 0000000..be3db42
--- /dev/null
@@ -0,0 +1,29 @@
+# Verifies golang.org/issue/37574.
+
+# If we are already using an +incompatible version, we shouldn't look up
+# a lower compatible version when upgrading.
+cp go.mod go.mod.orig
+go mod tidy
+cmp go.mod.orig go.mod
+grep '^example.com/incompatiblewithsub v2\.0\.0\+incompatible' go.sum
+! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
+
+go get -d example.com/incompatiblewithsub/sub
+cmp go.mod.orig go.mod
+! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
+
+# TODO(golang.org/issue/31580): the 'go get' command above should not change
+# go.sum. However, as part of the query above, we download example.com@v1.0.0,
+# an unrelated module, since it's a possible prefix. The sum for that module
+# should not be written to go.sum.
+
+-- go.mod --
+module m
+
+go 1.15
+
+require example.com/incompatiblewithsub v2.0.0+incompatible
+-- use.go --
+package use
+
+import _ "example.com/incompatiblewithsub/sub"