Skip to content

Commit 52fdd62

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/mvs: in Req, omit versions implied by older-than-selected versions already in the graph
Fixes #31248 Change-Id: Ia54f2098c3b85549681198a487a31e8ce8fc59eb Reviewed-on: https://go-review.googlesource.com/c/go/+/186557 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent a005f99 commit 52fdd62

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

src/cmd/go/internal/mvs/mvs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ func Req(target module.Version, list []module.Version, base []string, reqs Reqs)
288288
}
289289

290290
// Walk modules in reverse post-order, only adding those not implied already.
291-
have := map[string]string{}
291+
have := map[module.Version]bool{}
292292
walk = func(m module.Version) error {
293-
if v, ok := have[m.Path]; ok && reqs.Max(m.Version, v) == v {
293+
if have[m] {
294294
return nil
295295
}
296-
have[m.Path] = m.Version
296+
have[m] = true
297297
for _, m1 := range reqCache[m] {
298298
walk(m1)
299299
}
@@ -321,7 +321,7 @@ func Req(target module.Version, list []module.Version, base []string, reqs Reqs)
321321
// Older version.
322322
continue
323323
}
324-
if have[m.Path] != m.Version {
324+
if !have[m] {
325325
min = append(min, m)
326326
walk(m)
327327
}

src/cmd/go/internal/mvs/mvs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ H1: G1
295295
req A: G1
296296
req A G: G1
297297
req A H: H1
298+
299+
name: req3
300+
M: A1 B1
301+
A1: X1
302+
B1: X2
303+
X1: I1
304+
X2:
305+
req M: A1 B1
298306
`
299307

300308
func Test(t *testing.T) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
env GO111MODULE=on
2+
3+
# golang.org/issue/31248: loading the build list must not add explicit entries
4+
# for indirect dependencies already implied by older-than-selected versions
5+
# already in the build list.
6+
7+
cp go.mod.orig go.mod
8+
go mod tidy
9+
cmp go.mod go.mod.orig
10+
11+
cp go.mod.orig go.mod
12+
go list -m all
13+
cmp go.mod go.mod.orig
14+
15+
-- go.mod.orig --
16+
module main
17+
18+
go 1.13
19+
20+
require a v0.0.0
21+
22+
replace (
23+
a v0.0.0 => ./a
24+
b v0.0.0 => ./b
25+
i v0.0.0 => ./i
26+
x v0.1.0 => ./x1
27+
x v0.2.0 => ./x2
28+
)
29+
-- main.go --
30+
package main
31+
32+
import _ "a"
33+
34+
func main() {}
35+
-- a/go.mod --
36+
module a
37+
go 1.13
38+
require (
39+
x v0.2.0
40+
b v0.0.0
41+
)
42+
-- a/a.go --
43+
package a
44+
-- b/go.mod --
45+
module b
46+
go 1.13
47+
require x v0.1.0
48+
-- x1/go.mod --
49+
module x
50+
go 1.13
51+
require (
52+
b v0.0.0
53+
i v0.0.0
54+
)
55+
-- x2/go.mod --
56+
module x
57+
go 1.13
58+
-- i/go.mod --
59+
module i
60+
go 1.13

0 commit comments

Comments
 (0)