From: Bryan C. Mills Date: Sat, 10 Apr 2021 02:51:07 +0000 (-0400) Subject: cmd/go/internal/modload: avoid loading the module graph to list only the name of... X-Git-Tag: go1.17beta1~327 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c05d50f8f3;p=gostls13.git cmd/go/internal/modload: avoid loading the module graph to list only the name of the main module For #36460 For #29666 Change-Id: I9e46f7054d52c053be80c483757cdd34b22822d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/309190 Trust: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Reviewed-by: Jay Conrod Reviewed-by: Michael Matloob --- diff --git a/src/cmd/go/internal/modload/list.go b/src/cmd/go/internal/modload/list.go index e33078b53c..66927a8288 100644 --- a/src/cmd/go/internal/modload/list.go +++ b/src/cmd/go/internal/modload/list.go @@ -78,6 +78,10 @@ func ListModules(ctx context.Context, args []string, mode ListMode) ([]*modinfo. } func listModules(ctx context.Context, rs *Requirements, args []string, mode ListMode) (_ *Requirements, mods []*modinfo.ModulePublic, mgErr error) { + if len(args) == 0 { + return rs, []*modinfo.ModulePublic{moduleInfo(ctx, rs, Target, mode)}, nil + } + var mg *ModuleGraph if go117LazyTODO { // Pull the args-loop below into another (new) loop. @@ -90,10 +94,6 @@ func listModules(ctx context.Context, rs *Requirements, args []string, mode List rs, mg, mgErr = expandGraph(ctx, rs) } - if len(args) == 0 { - return rs, []*modinfo.ModulePublic{moduleInfo(ctx, rs, Target, mode)}, mgErr - } - matchedModule := map[module.Version]bool{} for _, arg := range args { if strings.Contains(arg, `\`) { @@ -149,10 +149,6 @@ func listModules(ctx context.Context, rs *Requirements, args []string, mode List continue } - if go117LazyTODO { - ModRoot() // Unversioned paths require that we be inside a module. - } - // Module path or pattern. var match func(string) bool if arg == "all" { diff --git a/src/cmd/go/testdata/script/mod_load_badchain.txt b/src/cmd/go/testdata/script/mod_load_badchain.txt index 8cb7eec0aa..eb464ab0d3 100644 --- a/src/cmd/go/testdata/script/mod_load_badchain.txt +++ b/src/cmd/go/testdata/script/mod_load_badchain.txt @@ -22,7 +22,7 @@ cmp go.mod go.mod.orig # Update manually. Listing modules should produce an error. go mod edit -require=example.com/badchain/a@v1.1.0 -! go list -m +! go list -m all cmp stderr list-expected # Try listing a package that imports a package