aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/list.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-04-15 12:08:24 -0400
committerJay Conrod <jayconrod@google.com>2020-08-26 21:12:19 +0000
commitdb821b54d1a8dffa85a9a3cf599f83a19184f020 (patch)
tree96b289a0bf8c4bfe583a8ca155309748b517c021 /src/cmd/go/internal/modload/list.go
parentbf869c65d1a96da5db78a891430ea3acd7ddf1ab (diff)
downloadgo-db821b54d1a8dffa85a9a3cf599f83a19184f020.tar.gz
go-db821b54d1a8dffa85a9a3cf599f83a19184f020.zip
cmd/go/internal/modload: refactor version filtering for exclude
Query and other functions now accept an "allowed" function that returns an error (previously, the function returned a bool). If the error is equivalent to ErrDisallowed, it indicates the version is excluded (or, in a future CL, retracted). This provides predicates a chance to explain why a version is not allowed. When a query refers to a specific revision (by version, branch, tag, or commit name), most callers will not use the Allowed predicate. This allows commands like 'go list -m' and 'go mod download' to handle disallowed versions when explicitly requested. 'go get' will reject excluded versions though. When a query does not refer to a specific revision (for example, "latest"), disallowed versions will not be considered. When an "allowed" predicate returns an error not equivalent to ErrDisallowed, it may be ignored or returned, depending on the case. This never happens for excluded versions, but it may happen for retractions (in a future CL). This indicates a list of retractions could not be loaded. This frequently happens when offline, and it shouldn't cause a fatal or warning in most cases. For #24031 Change-Id: I4df6fb6bd60e3e0259e5b3b4bf71a307b4b32298 Reviewed-on: https://go-review.googlesource.com/c/go/+/228379 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/list.go')
-rw-r--r--src/cmd/go/internal/modload/list.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modload/list.go b/src/cmd/go/internal/modload/list.go
index 7bf4e86c8d..2f549540a6 100644
--- a/src/cmd/go/internal/modload/list.go
+++ b/src/cmd/go/internal/modload/list.go
@@ -34,7 +34,7 @@ func ListModules(ctx context.Context, args []string, listU, listVersions bool) [
addUpdate(ctx, m)
}
if listVersions {
- addVersions(m)
+ addVersions(ctx, m)
}
<-sem
}()
@@ -83,7 +83,12 @@ func listModules(ctx context.Context, args []string, listVersions bool) []*modin
}
}
- info, err := Query(ctx, path, vers, current, nil)
+ allowed := CheckAllowed
+ if IsRevisionQuery(vers) {
+ // Allow excluded versions if the user asked for a specific revision.
+ allowed = nil
+ }
+ info, err := Query(ctx, path, vers, current, allowed)
if err != nil {
mods = append(mods, &modinfo.ModulePublic{
Path: path,