diff options
author | Russ Cox <rsc@golang.org> | 2018-08-10 13:26:32 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2018-08-17 19:21:57 +0000 |
commit | d46587c4eaaf64a7e9cb0797fcfa238f5138b170 (patch) | |
tree | 44babdf5839a0f951a2909235b55251785933557 /src/cmd/go/internal/modcmd/why.go | |
parent | 08d10f9af1429d19633722e36f7bfeda6c000aa5 (diff) | |
download | go-d46587c4eaaf64a7e9cb0797fcfa238f5138b170.tar.gz go-d46587c4eaaf64a7e9cb0797fcfa238f5138b170.zip |
cmd/go: distinguish patterns from the results of matching them
To date the go command has always just treated the command line
package patterns as a []string, expanded by pattern matching into
another []string. As a result, the code is not always clear about
whether a particular []string contains patterns or results.
A few different important bugs are caused by not keeping
this distinction clear enough. This CL sets us up well for fixing those,
by introducing an explicit search.Match struct holding the
results of matching a single pattern.
The added clarity here also makes it clear how to avoid duplicate
warnings about unmatched packages.
Fixes #26925. (Test in followup CL.)
Change-Id: Ic2f0606f7ab8b3734a40e22d3cb1e6f58d031061
Reviewed-on: https://go-review.googlesource.com/129058
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/go/internal/modcmd/why.go')
-rw-r--r-- | src/cmd/go/internal/modcmd/why.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/cmd/go/internal/modcmd/why.go b/src/cmd/go/internal/modcmd/why.go index 6923685599..03e0a039bc 100644 --- a/src/cmd/go/internal/modcmd/why.go +++ b/src/cmd/go/internal/modcmd/why.go @@ -100,20 +100,22 @@ func runWhy(cmd *base.Command, args []string) { sep = "\n" } } else { - pkgs := modload.ImportPaths(args) // resolve to packages - loadALL() // rebuild graph, from main module (not from named packages) + matches := modload.ImportPaths(args) // resolve to packages + loadALL() // rebuild graph, from main module (not from named packages) sep := "" - for _, path := range pkgs { - why := modload.Why(path) - if why == "" { - vendoring := "" - if *whyVendor { - vendoring = " to vendor" + for _, m := range matches { + for _, path := range m.Pkgs { + why := modload.Why(path) + if why == "" { + vendoring := "" + if *whyVendor { + vendoring = " to vendor" + } + why = "(main module does not need" + vendoring + " package " + path + ")\n" } - why = "(main module does not need" + vendoring + " package " + path + ")\n" + fmt.Printf("%s# %s\n%s", sep, path, why) + sep = "\n" } - fmt.Printf("%s# %s\n%s", sep, path, why) - sep = "\n" } } } |