]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: avoid loading the module graph to list only the name of...
authorBryan C. Mills <bcmills@google.com>
Sat, 10 Apr 2021 02:51:07 +0000 (22:51 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 30 Apr 2021 18:06:26 +0000 (18:06 +0000)
For #36460
For #29666

Change-Id: I9e46f7054d52c053be80c483757cdd34b22822d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/309190
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>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modload/list.go
src/cmd/go/testdata/script/mod_load_badchain.txt

index e33078b53c2a82c871e41c43b92b4021d32bde80..66927a82886aa4dc2f4433f979540fc3ab2a1919 100644 (file)
@@ -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" {
index 8cb7eec0aa4a2c9ac1ee51e762df929605afd13a..eb464ab0d3b84ea1faec6d201ccf10eb7e476389 100644 (file)
@@ -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