1
0
mirror of https://github.com/golang/go synced 2024-11-22 14:15:05 -07:00

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 <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2020-11-17 22:13:35 -05:00
parent 0bb6115dd6
commit ff2824d4b3

View File

@ -73,7 +73,7 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
modpkgs := make(map[module.Version][]string)
for _, pkg := range pkgs {
m := modload.PackageModule(pkg)
if m == modload.Target {
if m.Path == "" || m == modload.Target {
continue
}
modpkgs[m] = append(modpkgs[m], pkg)
@ -91,28 +91,38 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
includeAllReplacements = true
}
var vendorMods []module.Version
for m := range isExplicit {
vendorMods = append(vendorMods, m)
}
for m := range modpkgs {
if !isExplicit[m] {
vendorMods = append(vendorMods, m)
}
}
module.Sort(vendorMods)
var buf bytes.Buffer
for _, m := range modload.LoadedModules()[1:] {
if pkgs := modpkgs[m]; len(pkgs) > 0 || isExplicit[m] {
line := moduleLine(m, modload.Replacement(m))
buf.WriteString(line)
for _, m := range vendorMods {
line := moduleLine(m, modload.Replacement(m))
buf.WriteString(line)
if cfg.BuildV {
os.Stderr.WriteString(line)
}
if isExplicit[m] {
buf.WriteString("## explicit\n")
if cfg.BuildV {
os.Stderr.WriteString(line)
os.Stderr.WriteString("## explicit\n")
}
if isExplicit[m] {
buf.WriteString("## explicit\n")
if cfg.BuildV {
os.Stderr.WriteString("## explicit\n")
}
}
sort.Strings(pkgs)
for _, pkg := range pkgs {
fmt.Fprintf(&buf, "%s\n", pkg)
if cfg.BuildV {
fmt.Fprintf(os.Stderr, "%s\n", pkg)
}
vendorPkg(vdir, pkg)
}
pkgs := modpkgs[m]
sort.Strings(pkgs)
for _, pkg := range pkgs {
fmt.Fprintf(&buf, "%s\n", pkg)
if cfg.BuildV {
fmt.Fprintf(os.Stderr, "%s\n", pkg)
}
vendorPkg(vdir, pkg)
}
}