Skip to content

Commit

Permalink
cmd/go/internal/modload: avoid loading the module graph to list only …
Browse files Browse the repository at this point in the history
…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 <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>
  • Loading branch information
Bryan C. Mills committed Apr 30, 2021
1 parent ee4f965 commit c05d50f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/cmd/go/internal/modload/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, `\`) {
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/testdata/script/mod_load_badchain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c05d50f

Please sign in to comment.