Skip to content

Commit 8b3acef

Browse files
Bryan C. Millsprattmic
Bryan C. Mills
authored andcommitted
[release-branch.go1.20] 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 #60698. Updates #60667. Updates #56222. Change-Id: Ied6ed3e80a62f9cd9a328b43a415a42d14481056 Reviewed-on: https://go-review.googlesource.com/c/go/+/502016 Reviewed-by: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent 1008486 commit 8b3acef

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
@@ -1597,7 +1597,17 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
15971597
// paths of loaded packages. We need to retain sums for all of these modules —
15981598
// not just the modules containing the actual packages — in order to rule out
15991599
// ambiguous import errors the next time we load the package.
1600-
if ld != nil {
1600+
keepModSumsForZipSums := true
1601+
if ld == nil {
1602+
if cfg.BuildMod != "mod" && semver.Compare("v"+MainModules.GoVersion(), tidyGoModSumVersionV) < 0 {
1603+
keepModSumsForZipSums = false
1604+
}
1605+
} else {
1606+
keepPkgGoModSums := true
1607+
if (ld.Tidy || cfg.BuildMod != "mod") && semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) < 0 {
1608+
keepPkgGoModSums = false
1609+
keepModSumsForZipSums = false
1610+
}
16011611
for _, pkg := range ld.pkgs {
16021612
// We check pkg.mod.Path here instead of pkg.inStd because the
16031613
// pseudo-package "C" is not in std, but not provided by any module (and
@@ -1611,7 +1621,7 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
16111621
// However, we didn't do so before Go 1.21, and the bug is relatively
16121622
// minor, so we maintain the previous (buggy) behavior in 'go mod tidy' to
16131623
// avoid introducing unnecessary churn.
1614-
if !ld.Tidy || semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) >= 0 {
1624+
if keepPkgGoModSums {
16151625
r := resolveReplacement(pkg.mod)
16161626
keep[modkey(r)] = true
16171627
}
@@ -1671,7 +1681,9 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
16711681
if which == addBuildListZipSums {
16721682
for _, m := range mg.BuildList() {
16731683
r := resolveReplacement(m)
1674-
keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
1684+
if keepModSumsForZipSums {
1685+
keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
1686+
}
16751687
keep[r] = true
16761688
}
16771689
}

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

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

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

0 commit comments

Comments
 (0)