Skip to content

Commit ff2824d

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modcmd: eliminate a call to modload.LoadedModules
modload.LoadedModules reveals more information than necessary about whether modules have been loaded lazily. The 'vendor' subcommand doesn't actually need that much information: it has all of the information that it needs from prior calls to LoadPackages and ModFile. For #36460 Change-Id: If08733cca930b2b80616b037b63985ecfd6a320b Reviewed-on: https://go-review.googlesource.com/c/go/+/270979 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 0bb6115 commit ff2824d

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/cmd/go/internal/modcmd/vendor.go

+29-19
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
7373
modpkgs := make(map[module.Version][]string)
7474
for _, pkg := range pkgs {
7575
m := modload.PackageModule(pkg)
76-
if m == modload.Target {
76+
if m.Path == "" || m == modload.Target {
7777
continue
7878
}
7979
modpkgs[m] = append(modpkgs[m], pkg)
@@ -91,28 +91,38 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
9191
includeAllReplacements = true
9292
}
9393

94+
var vendorMods []module.Version
95+
for m := range isExplicit {
96+
vendorMods = append(vendorMods, m)
97+
}
98+
for m := range modpkgs {
99+
if !isExplicit[m] {
100+
vendorMods = append(vendorMods, m)
101+
}
102+
}
103+
module.Sort(vendorMods)
104+
94105
var buf bytes.Buffer
95-
for _, m := range modload.LoadedModules()[1:] {
96-
if pkgs := modpkgs[m]; len(pkgs) > 0 || isExplicit[m] {
97-
line := moduleLine(m, modload.Replacement(m))
98-
buf.WriteString(line)
106+
for _, m := range vendorMods {
107+
line := moduleLine(m, modload.Replacement(m))
108+
buf.WriteString(line)
109+
if cfg.BuildV {
110+
os.Stderr.WriteString(line)
111+
}
112+
if isExplicit[m] {
113+
buf.WriteString("## explicit\n")
99114
if cfg.BuildV {
100-
os.Stderr.WriteString(line)
101-
}
102-
if isExplicit[m] {
103-
buf.WriteString("## explicit\n")
104-
if cfg.BuildV {
105-
os.Stderr.WriteString("## explicit\n")
106-
}
115+
os.Stderr.WriteString("## explicit\n")
107116
}
108-
sort.Strings(pkgs)
109-
for _, pkg := range pkgs {
110-
fmt.Fprintf(&buf, "%s\n", pkg)
111-
if cfg.BuildV {
112-
fmt.Fprintf(os.Stderr, "%s\n", pkg)
113-
}
114-
vendorPkg(vdir, pkg)
117+
}
118+
pkgs := modpkgs[m]
119+
sort.Strings(pkgs)
120+
for _, pkg := range pkgs {
121+
fmt.Fprintf(&buf, "%s\n", pkg)
122+
if cfg.BuildV {
123+
fmt.Fprintf(os.Stderr, "%s\n", pkg)
115124
}
125+
vendorPkg(vdir, pkg)
116126
}
117127
}
118128

0 commit comments

Comments
 (0)