Skip to content

Commit 1d85bce

Browse files
Bryan C. Millsprattmic
Bryan C. Mills
authored andcommitted
[release-branch.go1.19] cmd/go: omit checksums for go.mod files needed for go version lines more often in pre-1.21 modules
This updates the logic from CL 489075 to avoid trying to save extra sums if they aren't already expected to be present and cfg.BuildMod != "mod" (as in the case of "go list -m -u all" with a go.mod file that specifies go < 1.21). Fixes #60697. Updates #60667. Updates #56222. Change-Id: Ied6ed3e80a62f9cd9a328b43a415a42d14481056 Reviewed-on: https://go-review.googlesource.com/c/go/+/502017 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Bypass: Bryan Mills <[email protected]>
1 parent 3ba9c89 commit 1d85bce

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/cmd/go/internal/modload/init.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,17 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
15851585
// paths of loaded packages. We need to retain sums for all of these modules —
15861586
// not just the modules containing the actual packages — in order to rule out
15871587
// ambiguous import errors the next time we load the package.
1588-
if ld != nil {
1588+
keepModSumsForZipSums := true
1589+
if ld == nil {
1590+
if cfg.BuildMod != "mod" && semver.Compare("v"+MainModules.GoVersion(), tidyGoModSumVersionV) < 0 {
1591+
keepModSumsForZipSums = false
1592+
}
1593+
} else {
1594+
keepPkgGoModSums := true
1595+
if (ld.Tidy || cfg.BuildMod != "mod") && semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) < 0 {
1596+
keepPkgGoModSums = false
1597+
keepModSumsForZipSums = false
1598+
}
15891599
for _, pkg := range ld.pkgs {
15901600
// We check pkg.mod.Path here instead of pkg.inStd because the
15911601
// pseudo-package "C" is not in std, but not provided by any module (and
@@ -1599,7 +1609,7 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
15991609
// However, we didn't do so before Go 1.21, and the bug is relatively
16001610
// minor, so we maintain the previous (buggy) behavior in 'go mod tidy' to
16011611
// avoid introducing unnecessary churn.
1602-
if !ld.Tidy || semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) >= 0 {
1612+
if keepPkgGoModSums {
16031613
r := resolveReplacement(pkg.mod)
16041614
keep[modkey(r)] = true
16051615
}
@@ -1659,7 +1669,9 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
16591669
if which == addBuildListZipSums {
16601670
for _, m := range mg.BuildList() {
16611671
r := resolveReplacement(m)
1662-
keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
1672+
if keepModSumsForZipSums {
1673+
keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
1674+
}
16631675
keep[r] = true
16641676
}
16651677
}

src/cmd/go/testdata/script/mod_sum_issue56222.txt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ stdout 1.18
2222
go mod tidy -go=1.19
2323
go clean -modcache # Remove checksums from the module cache, so that only go.sum is used.
2424

25+
# Issue 60667: 'go list' without -mod=mod shouldn't report the checksums as
26+
# dirty either.
27+
go list -m -u all
28+
2529
env OLDSUMDB=$GOSUMDB
2630
env GOSUMDB=bad
2731
go mod tidy

0 commit comments

Comments
 (0)