summaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modfetch/codehost/codehost.go
Commit message (Collapse)AuthorAgeFilesLines
* cmd/go/internal/modfetch/codehost: explicitly specify GIT_DIREmily Shaffer2023-05-081-0/+2
| | | | | | | | | | | | | | | | | | | | | When Git has safe.bareRepository=explicit set, operations on bare Git repositories will fail unless --git-dir or GIT_DIR is set. The rest of the time, specifying the gitdir makes repository discovery at the beginning of a Git command ever-so-slightly faster. So, there is no downside to ensuring that users with this stricter security config set can still use 'go mod' commands easily. See https://lore.kernel.org/git/pull.1261.v8.git.git.1657834081.gitgitgadget@gmail.com/ for a more detailed description of security concerns around embedded bare repositories without an explicitly specified GIT_DIR. Change-Id: I01c1d97a79fdab12c2b5532caf84eb7760f96b18 Reviewed-on: https://go-review.googlesource.com/c/go/+/489915 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
* cmd/go/internal/modfetch: use errors.ErrUnsupportedTobias Klauser2023-03-141-13/+0
| | | | | | | | | | | | | | | | CL 473935 added errors.ErrUnsupported, let's use it. Updates #41198 Change-Id: If6534d19cb31ca979ff00d529bd6bdfc964a616d Reviewed-on: https://go-review.googlesource.com/c/go/+/476135 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Bryan Mills <bcmills@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
* cmd/go/internal/modfetch: distinguish "unsupported" errors from RecentTagBryan C. Mills2022-08-291-0/+13
| | | | | | | | | | | | | | | | | CL 426079 started checking errors from RecentTag. Unfortunately, we forgot to run "-longtest" SlowBots, and it turns out to have broken non-short tests for non-git VCS implementations, because those don't implement the RecentTag method. Updates #53935. Change-Id: I5935f2f4b3f684515e99e8bf70a840154c36249f Reviewed-on: https://go-review.googlesource.com/c/go/+/426495 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: avoid overwriting cached Origin metadataBryan C. Mills2022-08-241-1/+3
| | | | | | | | | | | Fixes #54631. Change-Id: I17d2fa282642aeb1ae2a6e29a0756b8960bea34b Reviewed-on: https://go-review.googlesource.com/c/go/+/425255 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
* cmd/go/internal/modfetch/codehost: add missing newline in '# lock' log messageBryan C. Mills2022-07-121-1/+1
| | | | | | | | | Change-Id: Ib92e983b6cdeed2b275a028c85b2bba583def059 Reviewed-on: https://go-review.googlesource.com/c/go/+/403850 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
* cmd/go: make module@nonexistentversion failures reusableRuss Cox2022-07-051-1/+8
| | | | | | | | | | | | | | | | | | | CL 411398 added the -reuse flag for reusing cached JSON output when the remote Git repository has not changed. One case that was not yet cached is a lookup of a nonexistent version. This CL adds caching of failed lookups of nonexistent versions, by saving a checksum of all the heads and tags refs on the remote server (we never consider other kinds of refs). If none of those have changed, then we don't need to download the full server. Fixes #53644. Change-Id: I428bbc8ec8475bd7d03788934d643e1e2be3add0 Reviewed-on: https://go-review.googlesource.com/c/go/+/415678 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: add -reuse flag to make proxy invocations more efficientRuss Cox2022-07-051-10/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The go list -m and go mod download commands now have a -reuse flag, which is passed the name of a file containing the JSON output from a previous run of the same command. (It is up to the caller to ensure that flags such as -versions or -retracted, which affect the output, are consistent between the old and new run.) The new run uses the old JSON to evaluate whether the answer is unchanged since the old run. If so, it reuses that information, avoiding a costly 'git fetch', and sets a new Reuse: true field in its own JSON output. This dance with saving the JSON output and passing it back to -reuse is not necessary on most systems, because the go command caches version control checkouts in the module cache. That cache means that a new 'git fetch' would only download the commits that are new since the previous one (often none at all). The dance becomes important only on systems that do not preserve the module cache, for example by running 'go clean -modcache' aggressively or by running in some environment that starts with an empty file system. For #53644. Change-Id: I447960abf8055f83cc6dbc699a9fde9931130004 Reviewed-on: https://go-review.googlesource.com/c/go/+/411398 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: record origin metadata during module downloadRuss Cox2022-07-051-2/+88
| | | | | | | | | | | | | | | | | | | | | | | | This change adds an "Origin" JSON key to the output of go list -json -m and go mod download -json. The associated value is a JSON object with metadata about the source control system. For Git, that metadata is sufficient to evaluate whether the remote server has changed in any interesting way that might invalidate the cached data. In most cases, it will not have, and a fetch could then avoid downloading a full repo from the server. This origin metadata is also now recorded in the .info file for a given module@version, for informational and debugging purposes. This change only adds the metadata. It does not use it to optimize away unnecessary git fetch operations. (That's the next change.) For #53644. Change-Id: I4a1712a2386d1d8ab4e02ffdf0f72ba75d556115 Reviewed-on: https://go-review.googlesource.com/c/go/+/411397 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go/internal/modfetch: simplify handling of weird version tagsBryan C. Mills2022-05-101-1/+1
| | | | | | | | | | | | | | | | | This fixes an obscure bug in 'go list -versions' if the repo contains a tag with an explicit "+incompatible" suffix. However, I've never seen such a repo in the wild; mostly it's an attempt to wrap my brain around the code and simplify things a bit for the future. Updates #51324 Updates #51312 Change-Id: I1b078b5db36470cf61aaa85b5244c99b5ee2c842 Reviewed-on: https://go-review.googlesource.com/c/go/+/387917 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
* all: use os/exec instead of internal/execabsRuss Cox2022-05-021-1/+1
| | | | | | | | | | | | | | | | | | | | | We added internal/execabs back in January 2021 in order to fix a security problem caused by os/exec's handling of the current directory. Now that os/exec has that code, internal/execabs is superfluous and can be deleted. This commit rewrites all the imports back to os/exec and deletes internal/execabs. For #43724. Change-Id: Ib9736baf978be2afd42a1225e2ab3fd5d33d19df Reviewed-on: https://go-review.googlesource.com/c/go/+/381375 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
* cmd/go/internal/modfetch: remove unused FileRev structBaokun Lee2022-03-271-7/+0
| | | | | | | | | | | | | In CL 367756 we remove ReadFileRevs function, We simplified the implementation of the interface Repo. and the type FileRev is no longer used. Change-Id: Iec9e2f0d6bb227f4d0d0f565e897137dcf392a3a Reviewed-on: https://go-review.googlesource.com/c/go/+/373375 Trust: Lee Baokun <bk@golangcn.org> Run-TryBot: Lee Baokun <bk@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* all: gofmt -w -r 'interface{} -> any' srcRuss Cox2021-12-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go/internal/modfetch: remove legacy codeBaokun Lee2021-12-011-15/+0
| | | | | | | | | | | ReadFileRevs function is no longer used. Change-Id: Ibac6319dca4cf8010195e7c2fb502655494fb728 Reviewed-on: https://go-review.googlesource.com/c/go/+/367756 Run-TryBot: Baokun Lee <bk@golangcn.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Baokun Lee <bk@golangcn.org>
* cmd: move internal/str back to cmd/goRuss Cox2021-10-271-1/+1
| | | | | | | | | | | | | | | | | | | cmd/go is not subject to all the same restrictions as most of cmd. In particular it need not be buildable with the bootstrap toolchain. So it is better to keep as little code shared between cmd/go and cmd/compile, cmd/link, cmd/cgo as possible. cmd/internal/str started as cmd/go/internal/str but was moved to cmd/internal in order to make use of the quoted string code. Move that code to cmd/internal/quoted and then move the rest of cmd/internal/str back to cmd/go/internal/str. Change-Id: I3a98f754d545cc3af7e9a32c2b77a5a035ea7b9a Reviewed-on: https://go-review.googlesource.com/c/go/+/355010 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* cmd/internal/str: move package from cmd/go/internal/strJay Conrod2021-08-131-1/+1
| | | | | | | | | | | | | | This will let cmd/cgo and cmd/link use this package for argument parsing. For golang/go#41400 Change-Id: I12ee21151bf3f00f3e8d427faaaab2453c823117 Reviewed-on: https://go-review.googlesource.com/c/go/+/334730 Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/341934 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* all: introduce and use internal/execabsRoland Shoemaker2021-01-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Introduces a wrapper around os/exec, internal/execabs, for use in all commands. This wrapper prevents exec.LookPath and exec.Command from running executables in the current directory. All imports of os/exec in non-test files in cmd/ are replaced with imports of internal/execabs. This issue was reported by RyotaK. Fixes CVE-2021-3115 Fixes #43783 Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/955304 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/284783 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
* all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox2020-12-091-3/+2
| | | | | | | | | | | | | | | | | | | | | | As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* cmd/go: stop tests from using network during -shortRuss Cox2020-12-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turned out that "go get" was using the network to look up https://github.com?go-get=1 while resolving github.com/google/go-cmp, and that is not the fastest page to load. Stop that lookup by adjusting the path prefixes in the vcs table. It also turned out that "go get" was using the network to look up https://rsc.io?go-get=1 while resolving https://rsc.io/nonexist.svn. That's a bit more defensible maybe, since rsc.io is not a known VCS host. But for tests we really want to avoid the network entirely, so this CL adds a special case in repoRootFromVCSPaths that returns a hard error for plain "rsc.io" instead of doing the web fetch. To keep us honest in the future, I added two automatically-set env variables TESTGONETWORK=panic and TESTGOVCS=panic. These cause the go command to panic rather than make a network request or invoke a VCS command. go test -short cmd/go now passes with these checks. This reduced the time spent in go test -short cmd/go on my Google workstation from 154s to 30s. (Yay network firewalls.) Change-Id: I49207fca7f901fa011765fb984dc9cec8b691f11 Reviewed-on: https://go-review.googlesource.com/c/go/+/274441 Trust: Russ Cox <rsc@golang.org> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* all: update references to symbols moved from os to io/fsRuss Cox2020-10-201-4/+5
| | | | | | | | | | | | | | | | | | The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* cmd/go: ignore retracted versions when converting revisions to versionsJay Conrod2020-10-091-3/+2
| | | | | | | | | | | | | | | | | | | | | When a module author retracts a version, the go command should act as if it doesn't exist unless it's specifically requested. When converting a revision to a version, we should ignore tags for retracted versions. For example, if the tag v1.0.0 is retracted, and branch B points to the same revision, we should convert B to a pseudo-version, not v1.0.0. Similarly, if B points to a commit after v1.0.0, we should not use v1.0.0 as the base; we can use an earlier non-retracted tag or no base. Fixes #41700 Change-Id: Ia596b05b0780e5acfe6616a04e94d24bd342fbae Reviewed-on: https://go-review.googlesource.com/c/go/+/261079 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com>
* cmd/go: allow configuring module cache directory with GOMODCACHEMichael Matloob2020-04-081-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds a GOMODCACHE environment variable that's used by cmd/go to determine the location of the module cache. The default value of GOMODCACHE will be GOPATH[0]/pkg/mod, the default location of the module cache before this change. Replace the cmd/go/internal/modfetch.PkgMod variable which previously held the location of the module cache with the new cmd/go/internal/cfg.GOMODCACHE variable, for consistency with many of the other environment variables that affect the behavior of cmd/go. (Most of the changes in this CL are due to moving/renaming the variable.) The value of cfg.GOMODCACHE is now set using a variable initializer. It was previously set in cmd/go/internal/modload.Init. The location of GOPATH/pkg/sumdb is unchanged by this CL. While it was previously determined using the value of PkgMod, it now is determined independently dirctly from the value of GOPATH[0]. Fixes #34527 Change-Id: Id4d31d217b3507d6057c8ef7c52af1a0606603e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/219538 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
* cmd/go/internal/modfetch/codehost: remove invariantly-empty return value ↵Bryan C. Mills2019-10-241-4/+3
| | | | | | | | | | | | | | | from Repo.ReadZip Previously, codehost.Repo.ReadZip returned an 'actualSubdir' value that was the empty string in all current implementations. Updates #26092 Change-Id: I6708dd0f13ba88bcf1a1fb405e9d818fd6f9197e Reviewed-on: https://go-review.googlesource.com/c/go/+/203277 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* cmd/go/internal/modfetch: return structured errors from proxy operationsBryan C. Mills2019-06-251-1/+13
| | | | | | | | | | | | | | | | | CL 181881 added structured error types for direct fetches. Use those same structured errors to format proxy errors consistently. Also ensure that an empty @v/list is treated as equivalent to the module not existing at all. Updates #27173 Updates #32715 Change-Id: I203fd8259bc4f28b3389745f1a1fde936b0fa24d Reviewed-on: https://go-review.googlesource.com/c/go/+/183619 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* cmd/go: validate pseudo-versions against module paths and revision metadataBryan C. Mills2019-06-211-8/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, most operations involving pseudo-versions allowed any arbitrary combination of version string and date, and would resolve to the underlying revision (typically a Git commit hash) as long as that revision existed. There are a number of problems with that approach: • The pseudo-version participates in minimal version selection. If its version prefix is inaccurate, the pseudo-version may appear to have higher precedence that the releases that follow it, effectively “pinning” the module to that commit. For release tags, module authors are the ones who make the decision about release tagging; they should also have control over the pseudo-version precedence within their module. • The commit date within the pseudo-version provides a total order among pseudo-versions. If it is not accurate, the pseudo-version will sort into the wrong place relative to other commits with the same version prefix. To address those problems, this change restricts the pseudo-versions that the 'go' command accepts, rendering some previously accepted-but-not-canonical versions invalid. A pseudo-version is now valid only if all of: 1. The tag from which the pseudo-version derives points to the named revision or one of its ancestors as reported by the underlying VCS tool, or the pseudo-version is not derived from any tag (that is, has a "vX.0.0-" prefix before the date string and uses the lowest major version appropriate to the module path). 2. The date string within the pseudo-version matches the UTC timestamp of the revision as reported by the underlying VCS tool. 3. The short name of the revision within the pseudo-version (such as a Git hash prefix) is the same as the short name reported by the underlying cmd/go/internal/modfetch/codehost.Repo. Specifically, if the short name is a SHA-1 prefix, it must use the same number of hex digits (12) as codehost.ShortenSHA1. 4. The pseudo-version includes a '+incompatible' suffix only if it is needed for the corresponding major version, and only if the underlying module does not have a go.mod file. We believe that all releases of the 'go' tool have generated pseudo-versions that meet these constraints. However, a few pseudo-versions edited by hand or generated by third-party tools do not. If we discover invalid-but-benign pseudo-versions in widely-used existing dependencies, we may choose to add a whitelist for those specific path/version combinations. ― To work around invalid dependencies in leaf modules, users may add a 'replace' directive from the invalid version to its valid equivalent. Note that the go command's go.mod parser automatically resolves commit hashes found in 'replace' directives to the appropriate pseudo-versions, so in most cases one can write something like: replace github.com/docker/docker v1.14.0-0.20190319215453-e7b5f7dbe98c => github.com/docker/docker e7b5f7dbe98c and then run any 'go' command (such as 'go list' or 'go mod tidy') to resolve it to an appropriate pseudo-version. Note that the invalid version will still be used in minimal version selection, so this use of 'replace' directives is an incomplete workaround. ― One of the common use cases for higher-than-tagged pseudo-versions is for projects that do parallel development on release branches. For example, if a project cuts a 'v1.2' release branch at v1.2.0, they may want future commits on the main branch to show up as pre-releases for v1.3.0 rather than for v1.2.1 — especially if v1.2.1 is already tagged on the release branch. (On the other hand, a backport of a patch to the v1.2 branch should not show up as a pre-release for v1.3.0.) To address this use-case, module authors can make use of our existing support for pseudo-versions derived from pre-release tags: if the author adds an explicit pre-release tag (such as 'v1.3.0-devel') to the first commit after the branch, then the pseudo-versions for that commit and its descendents will be derived from that tag and will sort appropriately in version selection. ― Updates #27171 Fixes #29262 Fixes #27173 Fixes #32662 Fixes #32695 Change-Id: I0d50a538b6fdb0d3080aca9c9c3df1040da1b329 Reviewed-on: https://go-review.googlesource.com/c/go/+/181881 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
* cmd/go: link to the FAQ for errors that indicate private VCS repos.Julie Qiu2018-12-121-3/+7
| | | | | | | | | | | Updates #25982 Change-Id: I5a284e3844e944f9bfae31fa65b242060d4139c7 Reviewed-on: https://go-review.googlesource.com/c/150777 Run-TryBot: Julie Qiu <julie@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* cmd/go/internal/modfetch/codehost: add lockfiles for reposBryan C. Mills2018-11-291-9/+29
| | | | | | | | | | | | | | | | | | | The lockfile guards calls that may change the repo's filesystem contents. We don't know how robust VCS implementations are to running simultaneous commands, and this way we don't need to care: only one 'go' command at a time will modify any given repository. If we can guarantee that particular VCS implementations are robust enough across all of the VCS tool versions we support, we may be able to remove some of this locking to improve parallelism. Updates #26794 Change-Id: I578524974f5015629239cef43d3793aee2b9075c Reviewed-on: https://go-review.googlesource.com/c/146381 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
* all: use strings.ReplaceAll and bytes.ReplaceAll where applicableBrad Fitzpatrick2018-09-261-1/+1
| | | | | | | | | | | | | I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* cmd/go/internal/modfetch/codehost: quote arguments to commands printed from -xBryan C. Mills2018-07-311-3/+27
| | | | | | | | | | | | Some of the arguments — particularly format strings passed to git commands — may contain spaces, and it's useful to be able to paste commands from 'go get -x foo' directly into a shell to reproduce their output. Change-Id: I4f0c0b4e05db8b5232458e9a271f2ccbb665e85a Reviewed-on: https://go-review.googlesource.com/126955 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/go/internal/modfetch: move to new pseudo-version designRuss Cox2018-07-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original pseudo-version design used versions of the form v0.0.0-yyyymmddhhmmss-abcdef123456 These were intentionally chosen to be valid semantic versions that sort below any explicitly-chosen semantic version (even v0.0.0), so that they could be used before anything was tagged but after that would essentially only be useful in replace statements (because the max operation during MVS would always prefer a tagged version). Then we changed the go command to accept hashes on the command line, so that you can say go get github.com/my/proj@abcdef and it will download and use v0.0.0-yyyymmddhhmmss-abcdef123456. If you were using v1.10.1 before and this commit is just little bit newer than that commit, calling it v0.0.0-xxx is confusing but also harmful: the go command sees the change from v1.10.1 to the v0.0.0 pseudoversion as a downgrade, and it downgrades other modules in the build. In particular if some other module has a requirement of github.com/my/proj v1.9.0 (or later), the pseudo-version appears to be before that, so go get would downgrade that module too. It might even remove it entirely, if every available version needs a post-v0.0.0 version of my/proj. This CL introduces new pseudo-version forms that can be used to slot in after the most recent explicit tag before the commit. If the most recent tagged commit before abcdef is v1.10.1, then now we will use v1.10.2-0.yyyymmddhhmmss-abcdef123456 This has the right properties for downgrades and the like, since it is after v1.10.1 but before almost any possible successor, such as v1.10.2, v1.10.2-1, or v1.10.2-pre. This CL also uses those pseudo-version forms as appropriate when mapping a hash to a pseudo-version. This fixes the downgrade problem. Overall, this CL reflects our growing recognition of pseudo-versions as being like "untagged prereleases". Issue #26150 was about documenting best practices for how to work around this kind of accidental downgrade problem with additional steps. Now there are no additional steps: the problem is avoided by default. Fixes #26150. Change-Id: I402feeccb93e8e937bafcaa26402d88572e9b14c Reviewed-on: https://go-review.googlesource.com/124515 Reviewed-by: Bryan C. Mills <bcmills@google.com>
* cmd/go/internal/module: add new +incompatible version build annotationRuss Cox2018-07-191-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Repos written before the introduction of semantic import versioning introduced tags like v2.0.0, v3.0.0, and so on, expecting that (1) the import path would remain unchanged, and perhaps also (2) there would be at most one copy of the package in a build. We've always accommodated these by mapping them into the v0/v1 version range, so that if you ran go get k8s.io/client-go@v8.0.0 it would not complain about v8.x.x being a non-v1 version and instead would map that version to a pseudo-version in go.mod: require k8s.io/client-go v0.0.0-20180628043050-7d04d0e2a0a1 The pseudo-version fails to capture two important facts: first, that this really is the v8.0.0 tag, and second, that it should be preferred over any earlier v1 tags. A related problem is that running "go get k8s.io/client-go" with no version will choose the latest v1 tag (v1.5.1), which is obsolete. This CL introduces a new version suffix +incompatible that indicates that the tag should be considered an (incompatible) extension of the v1 version sequence instead of part of its own major version with its own versioned module path. The requirement above can now be written: require k8s.io/client-go v8.0.0+incompatible (The +metadata suffix is a standard part of semantic versioning, and that suffix is ignored when comparing two versions for precedence or equality. As part of canonicalizing versions recorded in go.mod, the go command has always stripped all such suffixes. It still strips nearly all: only +incompatible is preserved now.) In addition to recognizing the +incompatible, the code that maps a commit hash to a version will use that form when appropriate, so that go get k8s.io/client-go@7d04d0 will choose k8s.io/client-go@v8.0.0+incompatible. Also, the code that computes the list of available versions from a given source code repository also maps old tags to +incompatible versions, for any tagged commit in which a go.mod file does not exist. Therefore go list -m -versions k8s.io/client-go@latest will show k8s.io/client-go v1.4.0 v1.5.0 v1.5.1 v2.0.0-alpha.0+incompatible ... v8.0.0+incompatible and similarly go get k8s.io/client-go will now choose v8.0.0+incompatible as the meaning of "latest tagged version". The extraction of +incompatible versions from source code repos depends on a codehost.Repo method ReadFileRevs, to do a bulk read of multiple revisions of a file. That method is only implemented for git in this CL. Future CLs will need to add support for that method to the other repository implementations. Documentation for this change is in CL 124515. Fixes #26238. Change-Id: I5bb1d7a46b5fffde34a3c0e6f8d19d9608188cea Reviewed-on: https://go-review.googlesource.com/124384 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/go: merge module support from x/vgo repoRuss Cox2018-07-121-13/+32
| | | | | | | | | | | | | This CL corresponds to CL 123361, the final manual CL in that repo, making this the final manual sync. All future commits will happen in this repo (the main Go repo), and we'll update x/vgo automatically with a fixed patch+script. Change-Id: I572243309c1809727604fd704705a23c30e85d1a Reviewed-on: https://go-review.googlesource.com/123576 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* cmd/go: add dark copy of golang.org/x/vgoRuss Cox2018-06-151-0/+187
This CL corresponds to golang.org/cl/118096 (7fbc8df48a7) in the vgo repo. It copies the bulk of the code from vgo back into the main repo, but completely disabled - vgo.Init is a no-op and vgo.Enabled returns false unconditionally. The point of this CL is to make the two trees easier to diff and to make future syncs smaller. Change-Id: Ic34fd5ddd8272a70c5a3b3437b5169e967d0ed03 Reviewed-on: https://go-review.googlesource.com/118095 Reviewed-by: Bryan C. Mills <bcmills@google.com>