Skip to content

Commit 1dcbd8d

Browse files
author
Jay Conrod
committed
cmd/go/internal/modload: make QueryPattern consider current versions
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 <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent b3c0fe1 commit 1dcbd8d

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/cmd/go/internal/modload/query.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,9 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
455455

456456
err := modfetch.TryProxies(func(proxy string) error {
457457
queryModule := func(path string) (r QueryResult, err error) {
458+
current := findCurrentVersion(path)
458459
r.Mod.Path = path
459-
r.Rev, err = queryProxy(proxy, path, query, "", allowed)
460+
r.Rev, err = queryProxy(proxy, path, query, current, allowed)
460461
if err != nil {
461462
return r, err
462463
}
@@ -508,6 +509,15 @@ func modulePrefixesExcludingTarget(path string) []string {
508509
return prefixes
509510
}
510511

512+
func findCurrentVersion(path string) string {
513+
for _, m := range buildList {
514+
if m.Path == path {
515+
return m.Version
516+
}
517+
}
518+
return ""
519+
}
520+
511521
type prefixResult struct {
512522
QueryResult
513523
err error
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Module example.com/incompatiblewithsub has an incompatible version
2+
and a package in a subdirectory.
3+
-- .info --
4+
{"Version":"v1.0.0"}
5+
-- .mod --
6+
module example.com/incompatiblewithsub
7+
-- sub/sub.go --
8+
package sub
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Module example.com/incompatiblewithsub has an incompatible version
2+
and a package in a subdirectory.
3+
-- .info --
4+
{"Version":"v2.0.0+incompatible"}
5+
-- .mod --
6+
module example.com/incompatiblewithsub
7+
-- sub/sub.go --
8+
package sub
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Verifies golang.org/issue/37574.
2+
3+
# If we are already using an +incompatible version, we shouldn't look up
4+
# a lower compatible version when upgrading.
5+
cp go.mod go.mod.orig
6+
go mod tidy
7+
cmp go.mod.orig go.mod
8+
grep '^example.com/incompatiblewithsub v2\.0\.0\+incompatible' go.sum
9+
! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
10+
11+
go get -d example.com/incompatiblewithsub/sub
12+
cmp go.mod.orig go.mod
13+
! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
14+
15+
# TODO(golang.org/issue/31580): the 'go get' command above should not change
16+
# go.sum. However, as part of the query above, we download [email protected],
17+
# an unrelated module, since it's a possible prefix. The sum for that module
18+
# should not be written to go.sum.
19+
20+
-- go.mod --
21+
module m
22+
23+
go 1.15
24+
25+
require example.com/incompatiblewithsub v2.0.0+incompatible
26+
-- use.go --
27+
package use
28+
29+
import _ "example.com/incompatiblewithsub/sub"

0 commit comments

Comments
 (0)