]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: migrate to module.MatchPrefixPatterns
authorJay Conrod <jayconrod@google.com>
Thu, 25 Jun 2020 21:50:38 +0000 (17:50 -0400)
committerJay Conrod <jayconrod@google.com>
Fri, 14 Aug 2020 21:04:33 +0000 (21:04 +0000)
In CL 239797, str.GlobsMatchPath was copied to golang.org/x/mod/module
as MatchPrefixPatterns. This CL updates x/mod, switches calls to use
the new function, and deletes the old function.

For #38725

Change-Id: I7241032228b574aa539426a92d2f5aad9ee001e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/240061
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go.mod
src/cmd/go.sum
src/cmd/go/internal/modfetch/insecure.go
src/cmd/go/internal/modfetch/repo.go
src/cmd/go/internal/modfetch/sumdb.go
src/cmd/go/internal/str/path.go
src/cmd/vendor/golang.org/x/mod/module/module.go
src/cmd/vendor/modules.txt

index 6d57ceee791698826cc0dd243f90149ffbc0098a..21670b99965e2d14dcf6c20d6ec25d8b72056e63 100644 (file)
@@ -7,7 +7,7 @@ require (
        github.com/ianlancetaylor/demangle v0.0.0-20200414190113-039b1ae3a340 // indirect
        golang.org/x/arch v0.0.0-20200511175325-f7c78586839d
        golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
-       golang.org/x/mod v0.3.0
+       golang.org/x/mod v0.3.1-0.20200625141748-0b26df4a2231
        golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
        golang.org/x/tools v0.0.0-20200616133436-c1934b75d054
        golang.org/x/xerrors v0.0.0-20200806184451-1a77d5e9f316 // indirect
index 3fc693e3bfbd8dbc3f99018c7862bb6a32c51d00..1b5ef515c250849f1069f645cd3ed43ff26bc80f 100644 (file)
@@ -14,8 +14,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
-golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.3.1-0.20200625141748-0b26df4a2231 h1:R11LxkoUvECaAHdM5/ZOevSR7n+016EgTw8nbE1l+XM=
+golang.org/x/mod v0.3.1-0.20200625141748-0b26df4a2231/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
index 8420432d6cdf8db4c68aff4c07c4f545ccb555f1..b692669cbabae76b4b195af7f419523527856929 100644 (file)
@@ -7,10 +7,11 @@ package modfetch
 import (
        "cmd/go/internal/cfg"
        "cmd/go/internal/get"
-       "cmd/go/internal/str"
+
+       "golang.org/x/mod/module"
 )
 
 // allowInsecure reports whether we are allowed to fetch this path in an insecure manner.
 func allowInsecure(path string) bool {
-       return get.Insecure || str.GlobsMatchPath(cfg.GOINSECURE, path)
+       return get.Insecure || module.MatchPrefixPatterns(cfg.GOINSECURE, path)
 }
index f03bdd8d038a436f6eee89e9acfbaa5aa6a604f7..34f805d58ae384c0fb247b6f87f2262709e9dcce 100644 (file)
@@ -16,9 +16,9 @@ import (
        "cmd/go/internal/get"
        "cmd/go/internal/modfetch/codehost"
        "cmd/go/internal/par"
-       "cmd/go/internal/str"
        web "cmd/go/internal/web"
 
+       "golang.org/x/mod/module"
        "golang.org/x/mod/semver"
 )
 
@@ -217,7 +217,7 @@ func lookup(proxy, path string) (r Repo, err error) {
                return nil, errLookupDisabled
        }
 
-       if str.GlobsMatchPath(cfg.GONOPROXY, path) {
+       if module.MatchPrefixPatterns(cfg.GONOPROXY, path) {
                switch proxy {
                case "noproxy", "direct":
                        return lookupDirect(path)
index 7973f47426838381a3f94d03cde4e9ef05c17cd3..783c4a433b41c6b00faf7539e26d136f353827f6 100644 (file)
@@ -24,7 +24,6 @@ import (
        "cmd/go/internal/cfg"
        "cmd/go/internal/get"
        "cmd/go/internal/lockedfile"
-       "cmd/go/internal/str"
        "cmd/go/internal/web"
 
        "golang.org/x/mod/module"
@@ -34,7 +33,7 @@ import (
 
 // useSumDB reports whether to use the Go checksum database for the given module.
 func useSumDB(mod module.Version) bool {
-       return cfg.GOSUMDB != "off" && !get.Insecure && !str.GlobsMatchPath(cfg.GONOSUMDB, mod.Path)
+       return cfg.GOSUMDB != "off" && !get.Insecure && !module.MatchPrefixPatterns(cfg.GONOSUMDB, mod.Path)
 }
 
 // lookupSumDB returns the Go checksum database's go.sum lines for the given module,
index 95d91a3332e2986a178c43f540761d8025d35614..51ab2af82b58a6b42f5fc9eaa5e855d8de6fa5b4 100644 (file)
@@ -5,7 +5,6 @@
 package str
 
 import (
-       "path"
        "path/filepath"
        "strings"
 )
@@ -50,47 +49,3 @@ func HasFilePathPrefix(s, prefix string) bool {
                return s[len(prefix)] == filepath.Separator && s[:len(prefix)] == prefix
        }
 }
-
-// GlobsMatchPath reports whether any path prefix of target
-// matches one of the glob patterns (as defined by path.Match)
-// in the comma-separated globs list.
-// It ignores any empty or malformed patterns in the list.
-func GlobsMatchPath(globs, target string) bool {
-       for globs != "" {
-               // Extract next non-empty glob in comma-separated list.
-               var glob string
-               if i := strings.Index(globs, ","); i >= 0 {
-                       glob, globs = globs[:i], globs[i+1:]
-               } else {
-                       glob, globs = globs, ""
-               }
-               if glob == "" {
-                       continue
-               }
-
-               // A glob with N+1 path elements (N slashes) needs to be matched
-               // against the first N+1 path elements of target,
-               // which end just before the N+1'th slash.
-               n := strings.Count(glob, "/")
-               prefix := target
-               // Walk target, counting slashes, truncating at the N+1'th slash.
-               for i := 0; i < len(target); i++ {
-                       if target[i] == '/' {
-                               if n == 0 {
-                                       prefix = target[:i]
-                                       break
-                               }
-                               n--
-                       }
-               }
-               if n > 0 {
-                       // Not enough prefix elements.
-                       continue
-               }
-               matched, _ := path.Match(glob, prefix)
-               if matched {
-                       return true
-               }
-       }
-       return false
-}
index 6cd37280a85f5c29a0b36cab19bc2a864be3e686..3a8b080c7b2d79e3add359f33f0c9e62aac888cf 100644 (file)
@@ -97,6 +97,7 @@ package module
 
 import (
        "fmt"
+       "path"
        "sort"
        "strings"
        "unicode"
@@ -716,3 +717,49 @@ func unescapeString(escaped string) (string, bool) {
        }
        return string(buf), true
 }
+
+// MatchPrefixPatterns reports whether any path prefix of target matches one of
+// the glob patterns (as defined by path.Match) in the comma-separated globs
+// list. This implements the algorithm used when matching a module path to the
+// GOPRIVATE environment variable, as described by 'go help module-private'.
+//
+// It ignores any empty or malformed patterns in the list.
+func MatchPrefixPatterns(globs, target string) bool {
+       for globs != "" {
+               // Extract next non-empty glob in comma-separated list.
+               var glob string
+               if i := strings.Index(globs, ","); i >= 0 {
+                       glob, globs = globs[:i], globs[i+1:]
+               } else {
+                       glob, globs = globs, ""
+               }
+               if glob == "" {
+                       continue
+               }
+
+               // A glob with N+1 path elements (N slashes) needs to be matched
+               // against the first N+1 path elements of target,
+               // which end just before the N+1'th slash.
+               n := strings.Count(glob, "/")
+               prefix := target
+               // Walk target, counting slashes, truncating at the N+1'th slash.
+               for i := 0; i < len(target); i++ {
+                       if target[i] == '/' {
+                               if n == 0 {
+                                       prefix = target[:i]
+                                       break
+                               }
+                               n--
+                       }
+               }
+               if n > 0 {
+                       // Not enough prefix elements.
+                       continue
+               }
+               matched, _ := path.Match(glob, prefix)
+               if matched {
+                       return true
+               }
+       }
+       return false
+}
index 21fc78c2375d5865847e941c9bde2967cb79de08..7272f04ff3c830278bdf86352bd2f15134b17f2a 100644 (file)
@@ -29,7 +29,7 @@ golang.org/x/arch/x86/x86asm
 golang.org/x/crypto/ed25519
 golang.org/x/crypto/ed25519/internal/edwards25519
 golang.org/x/crypto/ssh/terminal
-# golang.org/x/mod v0.3.0
+# golang.org/x/mod v0.3.1-0.20200625141748-0b26df4a2231
 ## explicit
 golang.org/x/mod/internal/lazyregexp
 golang.org/x/mod/modfile