Skip to content

Commit cf3be9b

Browse files
author
Bryan C. Mills
committed
cmd/go: make commands other than 'tidy' prune go.mod less agressively
Updates #31870 Updates #33326 Fixes #34822 Change-Id: I1337f171133c20800eacc6b0955ede5a394ea7eb Reviewed-on: https://go-review.googlesource.com/c/go/+/204878 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 1bd974e commit cf3be9b

File tree

6 files changed

+439
-120
lines changed

6 files changed

+439
-120
lines changed

src/cmd/go/internal/modcmd/tidy.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
package modcmd
88

99
import (
10-
"fmt"
11-
"os"
12-
1310
"cmd/go/internal/base"
1411
"cmd/go/internal/cfg"
1512
"cmd/go/internal/modfetch"
@@ -45,28 +42,8 @@ func runTidy(cmd *base.Command, args []string) {
4542
base.Fatalf("go mod tidy: no arguments allowed")
4643
}
4744

48-
// LoadALL adds missing modules.
49-
// Remove unused modules.
50-
used := make(map[module.Version]bool)
51-
for _, pkg := range modload.LoadALL() {
52-
used[modload.PackageModule(pkg)] = true
53-
}
54-
used[modload.Target] = true // note: LoadALL initializes Target
55-
56-
inGoMod := make(map[string]bool)
57-
for _, r := range modload.ModFile().Require {
58-
inGoMod[r.Mod.Path] = true
59-
}
60-
61-
var keep []module.Version
62-
for _, m := range modload.BuildList() {
63-
if used[m] {
64-
keep = append(keep, m)
65-
} else if cfg.BuildV && inGoMod[m.Path] {
66-
fmt.Fprintf(os.Stderr, "unused %s\n", m.Path)
67-
}
68-
}
69-
modload.SetBuildList(keep)
45+
modload.LoadALL()
46+
modload.TidyBuildList()
7047
modTidyGoSum() // updates memory copy; WriteGoMod on next line flushes it out
7148
modload.WriteGoMod()
7249
}

0 commit comments

Comments
 (0)