aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/query.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-10-02 16:25:17 -0400
committerBryan C. Mills <bcmills@google.com>2020-10-13 20:13:34 +0000
commitc9211577eb77df9c51f0565f1da7d20ff91d59df (patch)
tree8d2790ed1e421a3fd24ef16b1fba14b7569c73f5 /src/cmd/go/internal/modload/query.go
parent3a65abfbdac7ab29f693d69bd1eb12b2148a11ae (diff)
downloadgo-c9211577eb77df9c51f0565f1da7d20ff91d59df.tar.gz
go-c9211577eb77df9c51f0565f1da7d20ff91d59df.zip
cmd/go/internal/modfetch: remove error return from Lookup
We generally don't care about errors in resolving a repo if the result we're looking for is already in the module cache. Moreover, we can avoid some expense in initializing the repo if all of the methods we plan to call on it hit in the cache — especially when using GOPROXY=direct. This also incidentally fixes a possible (but rare) bug in Download: we had forgotten to reset the downloaded file in case the Zip method returned an error after writing a nonzero number of bytes. For #37438 Change-Id: Ib64f10f763f6d1936536b8e1f7d31ed1b463e955 Reviewed-on: https://go-review.googlesource.com/c/go/+/259158 Trust: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r--src/cmd/go/internal/modload/query.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index e75d901ec6..44076fb615 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -229,14 +229,15 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
// If the identifier is not a canonical semver tag — including if it's a
// semver tag with a +metadata suffix — then modfetch.Stat will populate
// info.Version with a suitable pseudo-version.
- info, err := modfetch.Stat(proxy, path, query)
+ repo := modfetch.Lookup(proxy, path)
+ info, err := repo.Stat(query)
if err != nil {
queryErr := err
// The full query doesn't correspond to a tag. If it is a semantic version
// with a +metadata suffix, see if there is a tag without that suffix:
// semantic versioning defines them to be equivalent.
if canonicalQuery != "" && query != canonicalQuery {
- info, err = modfetch.Stat(proxy, path, canonicalQuery)
+ info, err = repo.Stat(canonicalQuery)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return info, err
}
@@ -266,10 +267,7 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
}
// Load versions and execute query.
- repo, err := modfetch.Lookup(proxy, path)
- if err != nil {
- return nil, err
- }
+ repo := modfetch.Lookup(proxy, path)
versions, err := repo.Versions(prefix)
if err != nil {
return nil, err