"strconv"
"strings"
"sync"
+ "sync/atomic"
"time"
"cmd/go/internal/base"
+ "cmd/go/internal/cfg"
"cmd/go/internal/lockedfile"
"cmd/go/internal/str"
"cmd/internal/par"
fetchOnce sync.Once
fetchErr error
+ fetched atomic.Bool
+
+ repoSumOnce sync.Once
+ repoSum string
}
func newVCSRepo(ctx context.Context, vcs, remote string, local bool) (Repo, error) {
return nil, err
}
_, err = Run(ctx, r.dir, cmd.init(r.remote))
+ if err == nil && cmd.postInit != nil {
+ err = cmd.postInit(ctx, r)
+ }
release()
if err != nil {
const vcsWorkDirType = "vcs1."
type vcsCmd struct {
- vcs string // vcs name "hg"
- init func(remote string) []string // cmd to init repo to track remote
- tags func(remote string) []string // cmd to list local tags
- tagRE *lazyregexp.Regexp // regexp to extract tag names from output of tags cmd
- branches func(remote string) []string // cmd to list local branches
- branchRE *lazyregexp.Regexp // regexp to extract branch names from output of tags cmd
- badLocalRevRE *lazyregexp.Regexp // regexp of names that must not be served out of local cache without doing fetch first
- statLocal func(rev, remote string) []string // cmd to stat local rev
- parseStat func(rev, out string) (*RevInfo, error) // cmd to parse output of statLocal
- fetch []string // cmd to fetch everything from remote
- latest string // name of latest commit on remote (tip, HEAD, etc)
- readFile func(rev, file, remote string) []string // cmd to read rev's file
- readZip func(rev, subdir, remote, target string) []string // cmd to read rev's subdir as zip file
- doReadZip func(ctx context.Context, dst io.Writer, workDir, rev, subdir, remote string) error // arbitrary function to read rev's subdir as zip file
+ vcs string // vcs name "hg"
+ init func(remote string) []string // cmd to init repo to track remote
+ postInit func(context.Context, *vcsRepo) error // func to init repo after .init runs
+ repoSum func(remote string) []string // cmd to calculate reposum of remote repo
+ lookupRef func(remote, ref string) []string // cmd to look up ref in remote repo
+ tags func(remote string) []string // cmd to list local tags
+ tagsNeedsFetch bool // run fetch before tags
+ tagRE *lazyregexp.Regexp // regexp to extract tag names from output of tags cmd
+ branches func(remote string) []string // cmd to list local branches
+ branchesNeedsFetch bool // run branches before tags
+ branchRE *lazyregexp.Regexp // regexp to extract branch names from output of tags cmd
+ badLocalRevRE *lazyregexp.Regexp // regexp of names that must not be served out of local cache without doing fetch first
+ statLocal func(rev, remote string) []string // cmd to stat local rev
+ parseStat func(rev, out string) (*RevInfo, error) // func to parse output of statLocal
+ fetch []string // cmd to fetch everything from remote
+ latest string // name of latest commit on remote (tip, HEAD, etc)
+ readFile func(rev, file, remote string) []string // cmd to read rev's file
+ readZip func(rev, subdir, remote, target string) []string // cmd to read rev's subdir as zip file
+
+ // arbitrary function to read rev's subdir as zip file
+ doReadZip func(ctx context.Context, dst io.Writer, workDir, rev, subdir, remote string) error
}
var re = lazyregexp.New
var vcsCmds = map[string]*vcsCmd{
"hg": {
vcs: "hg",
+ repoSum: func(remote string) []string {
+ return []string{
+ "hg",
+ "--config=extensions.goreposum=" + filepath.Join(cfg.GOROOT, "lib/hg/goreposum.py"),
+ "goreposum",
+ remote,
+ }
+ },
+ lookupRef: func(remote, ref string) []string {
+ return []string{
+ "hg",
+ "--config=extensions.goreposum=" + filepath.Join(cfg.GOROOT, "lib/hg/goreposum.py"),
+ "golookup",
+ remote,
+ ref,
+ }
+ },
init: func(remote string) []string {
- return []string{"hg", "clone", "-U", "--", remote, "."}
+ return []string{"hg", "init", "."}
},
+ postInit: hgAddRemote,
tags: func(remote string) []string {
return []string{"hg", "tags", "-q"}
},
- tagRE: re(`(?m)^[^\n]+$`),
+ tagsNeedsFetch: true,
+ tagRE: re(`(?m)^[^\n]+$`),
branches: func(remote string) []string {
return []string{"hg", "branches", "-c", "-q"}
},
- branchRE: re(`(?m)^[^\n]+$`),
- badLocalRevRE: re(`(?m)^(tip)$`),
+ branchesNeedsFetch: true,
+ branchRE: re(`(?m)^[^\n]+$`),
+ badLocalRevRE: re(`(?m)^(tip)$`),
statLocal: func(rev, remote string) []string {
return []string{"hg", "log", "-l1", "-r", rev, "--template", "{node} {date|hgdate} {tags}"}
},
}
func (r *vcsRepo) loadTags(ctx context.Context) {
+ if r.cmd.tagsNeedsFetch {
+ r.fetchOnce.Do(func() { r.fetch(ctx) })
+ }
+
out, err := Run(ctx, r.dir, r.cmd.tags(r.remote))
if err != nil {
return
return
}
+ if r.cmd.branchesNeedsFetch {
+ r.fetchOnce.Do(func() { r.fetch(ctx) })
+ }
+
out, err := Run(ctx, r.dir, r.cmd.branches(r.remote))
if err != nil {
return
}
}
+func (r *vcsRepo) loadRepoSum(ctx context.Context) {
+ if r.cmd.repoSum == nil {
+ return
+ }
+ where := r.remote
+ if r.fetched.Load() {
+ where = "." // use local repo
+ }
+ out, err := Run(ctx, r.dir, r.cmd.repoSum(where))
+ if err != nil {
+ return
+ }
+ r.repoSum = strings.TrimSpace(string(out))
+}
+
+func (r *vcsRepo) lookupRef(ctx context.Context, ref string) (string, error) {
+ if r.cmd.lookupRef == nil {
+ return "", fmt.Errorf("no lookupRef")
+ }
+ out, err := Run(ctx, r.dir, r.cmd.lookupRef(r.remote, ref))
+ if err != nil {
+ return "", err
+ }
+ return strings.TrimSpace(string(out)), nil
+}
+
+// repoSumOrigin returns an Origin containing a RepoSum.
+func (r *vcsRepo) repoSumOrigin(ctx context.Context) *Origin {
+ origin := &Origin{
+ VCS: r.cmd.vcs,
+ URL: r.remote,
+ RepoSum: r.repoSum,
+ }
+ r.repoSumOnce.Do(func() { r.loadRepoSum(ctx) })
+ origin.RepoSum = r.repoSum
+ return origin
+}
+
func (r *vcsRepo) CheckReuse(ctx context.Context, old *Origin, subdir string) error {
+ if old == nil {
+ return fmt.Errorf("missing origin")
+ }
+ if old.VCS != r.cmd.vcs || old.URL != r.remote {
+ return fmt.Errorf("origin moved from %v %q to %v %q", old.VCS, old.URL, r.cmd.vcs, r.remote)
+ }
+ if old.Subdir != subdir {
+ return fmt.Errorf("origin moved from %v %q %q to %v %q %q", old.VCS, old.URL, old.Subdir, r.cmd.vcs, r.remote, subdir)
+ }
+
+ if old.Ref == "" && old.RepoSum == "" && old.Hash != "" {
+ // Hash has to remain in repo.
+ hash, err := r.lookupRef(ctx, old.Hash)
+ if err == nil && hash == old.Hash {
+ return nil
+ }
+ if err != nil {
+ return fmt.Errorf("looking up hash: %v", err)
+ }
+ return fmt.Errorf("hash changed") // weird but maybe they made a tag
+ }
+
+ if old.Ref != "" && old.RepoSum == "" {
+ hash, err := r.lookupRef(ctx, old.Ref)
+ if err == nil && hash != "" && hash == old.Hash {
+ return nil
+ }
+ }
+
+ r.repoSumOnce.Do(func() { r.loadRepoSum(ctx) })
+ if r.repoSum != "" {
+ if old.RepoSum == "" {
+ return fmt.Errorf("non-specific origin")
+ }
+ if old.RepoSum != r.repoSum {
+ return fmt.Errorf("repo changed")
+ }
+ return nil
+ }
return fmt.Errorf("vcs %s: CheckReuse: %w", r.cmd.vcs, errors.ErrUnsupported)
}
r.tagsOnce.Do(func() { r.loadTags(ctx) })
tags := &Tags{
- // None of the other VCS provide a reasonable way to compute TagSum
- // without downloading the whole repo, so we only include VCS and URL
- // in the Origin.
- Origin: &Origin{
- VCS: r.cmd.vcs,
- URL: r.remote,
- },
- List: []Tag{},
+ Origin: r.repoSumOrigin(ctx),
+ List: []Tag{},
}
for tag := range r.tags {
if strings.HasPrefix(tag, prefix) {
}
info, err := r.statLocal(ctx, rev)
if err != nil {
- return nil, err
+ return info, err
}
if !revOK {
info.Version = info.Name
}
_, r.fetchErr = Run(ctx, r.dir, r.cmd.fetch)
release()
+ r.fetched.Store(true)
}
}
func (r *vcsRepo) statLocal(ctx context.Context, rev string) (*RevInfo, error) {
out, err := Run(ctx, r.dir, r.cmd.statLocal(rev, r.remote))
if err != nil {
- return nil, &UnknownRevisionError{Rev: rev}
+ info := &RevInfo{Origin: r.repoSumOrigin(ctx)}
+ return info, &UnknownRevisionError{Rev: rev}
}
info, err := r.cmd.parseStat(rev, string(out))
if err != nil {
}
info.Origin.VCS = r.cmd.vcs
info.Origin.URL = r.remote
+ info.Origin.Ref = rev
+ if strings.HasPrefix(info.Name, rev) && len(rev) >= 12 {
+ info.Origin.Ref = "" // duplicates Hash
+ }
return info, nil
}
return d.File.Close()
}
+func hgAddRemote(ctx context.Context, r *vcsRepo) error {
+ // Write .hg/hgrc with remote URL in it.
+ return os.WriteFile(filepath.Join(r.dir, ".hg/hgrc"), []byte(fmt.Sprintf("[paths]\ndefault = %s\n", r.remote)), 0666)
+}
+
func hgParseStat(rev, out string) (*RevInfo, error) {
f := strings.Fields(out)
if len(f) < 3 {
sort.Strings(tags)
info := &RevInfo{
- Origin: &Origin{
- Hash: hash,
- },
+ Origin: &Origin{Hash: hash},
Name: hash,
Short: ShortenSHA1(hash),
Time: time.Unix(t, 0).UTC(),
version = hash // extend to full hash
}
info := &RevInfo{
- Origin: &Origin{
- Hash: hash,
- },
+ Origin: &Origin{Hash: hash},
Name: hash,
Short: ShortenSHA1(hash),
Time: t,
-skip
-
[short] skip
-[!hg] skip
+[!exec:hg] skip
env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off
-# go mod download with the pseudo-version should invoke hg but not have a TagSum or Ref.
-go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922010558-fc3a09f3dc5c
+# go mod download with the pseudo-version should invoke hg but not have a TagSum or Ref or RepoSum.
+go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
stderr 'hg( .*)* pull'
cp stdout hellopseudo.json
-! stdout '"(Query|TagPrefix|TagSum|Ref)"'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+! stdout '"(Query|TagPrefix|TagSum|Ref|RepoSum)"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
! stdout '"RepoSum"'
go clean -modcache
go mod download -x -json vcs-test.golang.org/hg/hello.hg@latest
stderr 'hg( .*)* pull'
cp stdout hello.json
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
stdout '"Query": "latest"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"RepoSum"'
+! stdout '"TagSum"'
+stdout '"Ref": "tip"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
# pseudo-version again should not invoke hg pull (it has the version from the @latest query)
# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD,
# which is easy to do when reusing the cached version from the @latest query.
-go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922010558-fc3a09f3dc5c
+go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
! stderr 'hg( .*)* pull'
cp stdout hellopseudo2.json
cmpenv hellopseudo.json hellopseudo2.json
-# go mod download vcstest/hello@hash needs to check TagSum to find pseudoversion base.
-go mod download -x -json vcs-test.golang.org/hg/hello.hg@fc3a09f3dc5c
-! stderr 'hg( .*)* pull'
+# go mod download hg/hello@hash needs to check RepoSum to find pseudoversion base,
+# which does a refreshing hg pull.
+go mod download -x -json vcs-test.golang.org/hg/hello.hg@e483a7d9f8c9
+stderr 'hg( .*)* pull'
cp stdout hellohash.json
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
-stdout '"Query": "fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
+stdout '"Query": "e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"RepoSum"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
# go mod download vcstest/hello/v9 should fail, still print origin info
+# hg uses RepoSum instead of TagSum to describe failure condition.
! go mod download -x -json vcs-test.golang.org/hg/hello.hg/v9@latest
cp stdout hellov9.json
stdout '"Version": "latest"'
stdout '"Error":.*no matching versions'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout 'RepoSum'
+! stdout '"TagSum"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
-# go mod download vcstest/hello/sub/v9 should also fail, print origin info with TagPrefix
+# go mod download vcstest/hello/sub/v9 should also fail, print origin info
+# hg uses RepoSum instead of TagSum to describe failure condition.
! go mod download -x -json vcs-test.golang.org/hg/hello.hg/sub/v9@latest
cp stdout hellosubv9.json
stdout '"Version": "latest"'
stdout '"Error":.*no matching versions'
-stdout '"TagPrefix": "sub/"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout 'RepoSum'
+! stdout '"TagPrefix"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
# go mod download vcstest/hello@nonexist should fail, still print origin info
! go mod download -x -json vcs-test.golang.org/hg/hello.hg@nonexist
cp stdout hellononexist.json
stdout '"Version": "nonexist"'
stdout '"Error":.*unknown revision nonexist'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
# go mod download vcstest/hello@1234567890123456789012345678901234567890 should fail, still print origin info
cp stdout hellononhash.json
stdout '"Version": "1234567890123456789012345678901234567890"'
stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
# go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc should fail, still print origin info
cp stdout hellononpseudo.json
stdout '"Version": "v0.0.0-20220101120101-123456789abc"'
stdout '"Error":.*unknown revision 123456789abc'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
# go mod download vcstest/tagtests should invoke hg, print origin info
+# Need RepoSum to lock in tagged "latest".
go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@latest
stderr 'hg( .*)* pull'
cp stdout tagtests.json
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/tags/v0.2.2"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
-! stdout '"RepoSum"'
+! stdout '"TagSum"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
-# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum needed
+# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum or RepoSum needed.
go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
cp stdout tagtestsv022.json
stdout '"Version": "v0.2.2"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
! stdout '"TagSum"'
-stdout '"Ref": "refs/tags/v0.2.2"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
! stdout '"RepoSum"'
-
-# go mod download vcstest/tagtests@master needs a TagSum again
-go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@master
-cp stdout tagtestsmaster.json
-stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
-stdout '"Query": "master"'
+stdout '"Ref": "v0.2.2"'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
+
+# go mod download vcstest/tagtests@default needs a RepoSum again
+go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@default
+cp stdout tagtestsdefault.json
+stdout '"Version": "v0.0.0-20190509225625-8d0b18b816df"'
+stdout '"Query": "default"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/heads/master"'
-stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
-! stdout '"RepoSum"'
+! stdout '"TagSum"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
+stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"'
# go mod download vcstest/prefixtagtests should invoke hg, print origin info
go mod download -x -json vcs-test.golang.org/hg/prefixtagtests.hg/sub@latest
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/prefixtagtests"'
stdout '"Subdir": "sub"'
-stdout '"TagPrefix": "sub/"'
-stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="'
-stdout '"Ref": "refs/tags/sub/v0.0.10"'
-stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"'
-! stdout '"RepoSum"'
+stdout '"Ref": "sub/v0.0.10"'
+! stdout '"TagPrefix"'
+! stdout '"TagSum"'
+stdout '"RepoSum": "r1:YWOcei109p5Kohsr5xnSYlaQXmpT3iWZHZhRbfMoTkc="'
+stdout '"Hash": "1cc0dfcc254cb8901799e7f7ae182c04019b7a88"'
# go mod download of a bunch of these should fail (some are invalid) but write good JSON for later
-! go mod download -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@master
+! go mod download -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@default
cp stdout all.json
# clean the module cache, make sure that makes go mod download re-run hg pull, clean again
go mod download -reuse=hello.json -x -json vcs-test.golang.org/hg/hello.hg@latest
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Ref": "tip"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse go mod download vcstest/hello pseudoversion result
go clean -modcache
-go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922010558-fc3a09f3dc5c
+go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
! stdout '"(Query|TagPrefix|TagSum|Ref)"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
# reuse go mod download vcstest/hello@hash
go clean -modcache
-go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/hg/hello.hg@fc3a09f3dc5c
+go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/hg/hello.hg@e483a7d9f8c9
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
-stdout '"Query": "fc3a09f3dc5c"'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Query": "e483a7d9f8c9"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
! stdout '"(TagPrefix|Ref)"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse go mod download vcstest/hello/v9 error result
go clean -modcache
stdout '"Reuse": true'
stdout '"Error":.*no matching versions'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse go mod download vcstest/hello/sub/v9 error result
go clean -modcache
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
stdout '"Error":.*no matching versions'
-stdout '"TagPrefix": "sub/"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Ref": "HEAD"'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+! stdout '"TagPrefix"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Ref": "tip"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse go mod download vcstest/hello@nonexist
go clean -modcache
stdout '"Reuse": true'
stdout '"Version": "nonexist"'
stdout '"Error":.*unknown revision nonexist'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
! stdout '"(Dir|Info|GoMod|Zip)"'
stdout '"Reuse": true'
stdout '"Version": "1234567890123456789012345678901234567890"'
stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
! stdout '"(Dir|Info|GoMod|Zip)"'
stdout '"Reuse": true'
stdout '"Version": "v0.0.0-20220101120101-123456789abc"'
stdout '"Error":.*unknown revision 123456789abc'
-stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
! stdout '"(TagPrefix|TagSum|Ref|Hash)"'
! stdout '"(Dir|Info|GoMod|Zip)"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/tags/v0.2.2"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse go mod download vcstest/tagtests@v0.2.2 result
go clean -modcache
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
! stdout '"TagSum"'
-stdout '"Ref": "refs/tags/v0.2.2"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
+stdout '"Ref": "v0.2.2"'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
-# reuse go mod download vcstest/tagtests@master result
+# reuse go mod download vcstest/tagtests@default result
go clean -modcache
-go mod download -reuse=tagtestsmaster.json -x -json vcs-test.golang.org/hg/tagtests.hg@master
+go mod download -reuse=tagtestsdefault.json -x -json vcs-test.golang.org/hg/tagtests.hg@default
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
-stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
-stdout '"Query": "master"'
+ # NOTE: Strictly speaking this should be v0.2.3-... but we never
+ # implemented Mercurial support for finding ancestor tags to
+ # create pseudo-versions.
+stdout '"Version": "v0.0.0-20190509225625-8d0b18b816df"'
+stdout '"Query": "default"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/heads/master"'
-stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
+stdout '"Ref": "default"'
+stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
-# reuse go mod download vcstest/tagtests@master result again with all.json
+# reuse go mod download vcstest/tagtests@default result again with all.json
go clean -modcache
-go mod download -reuse=all.json -x -json vcs-test.golang.org/hg/tagtests.hg@master
+go mod download -reuse=all.json -x -json vcs-test.golang.org/hg/tagtests.hg@default
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
-stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
-stdout '"Query": "master"'
+stdout '"Version": "v0.0.0-20190509225625-8d0b18b816df"'
+stdout '"Query": "default"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/heads/master"'
-stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
-! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
+stdout '"Ref": "default"'
+stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"'
+! stdout '"(Dir|Info|GoMod|Zip)"'
# go mod download vcstest/prefixtagtests result with json
go clean -modcache
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/prefixtagtests"'
stdout '"Subdir": "sub"'
-stdout '"TagPrefix": "sub/"'
-stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="'
-stdout '"Ref": "refs/tags/sub/v0.0.10"'
-stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"'
+stdout '"RepoSum": "r1:YWOcei109p5Kohsr5xnSYlaQXmpT3iWZHZhRbfMoTkc="'
+stdout '"Ref": "sub/v0.0.10"'
+stdout '"Hash": "1cc0dfcc254cb8901799e7f7ae182c04019b7a88"'
! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse the bulk results with all.json
go clean -modcache
-! go mod download -reuse=all.json -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@master
+! go mod download -reuse=all.json -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@default
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
! stdout '"(Dir|Info|GoMod|Zip)"'
# reuse attempt with stale hash should reinvoke hg, not report reuse
go clean -modcache
cp tagtestsv022.json tagtestsv022badhash.json
-replace '57952' '56952XXX' tagtestsv022badhash.json
+replace '1e5315' '1e5315XXX' tagtestsv022badhash.json
go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
stderr 'hg( .*)* pull'
! stdout '"Reuse": true'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"(TagPrefix|TagSum|RepoSum)"'
-stdout '"Ref": "refs/tags/v0.2.2"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
+stdout '"Ref": "v0.2.2"'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
stdout '"Dir"'
stdout '"Info"'
stdout '"GoMod"'
# reuse with stale Dir
go clean -modcache
cp tagtestsv022.json tagtestsv022baddir.json
-replace '\t\t\"Ref\":' '\t\t\"Subdir\": \"subdir\",\n\t\t\"Ref\":' tagtestsv022baddir.json
+replace '\"VCS\":' '\"Subdir\":\"subdir\", \"VCS\":' tagtestsv022baddir.json
go mod download -reuse=tagtestsv022baddir.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2
! stdout '"Reuse": true'
stdout '"URL": ".*/hg/tagtests"'
! stdout '"RepoSum"'
-# reuse with stale TagSum
+# reuse with stale RepoSum
go clean -modcache
-cp tagtests.json tagtestsbadtagsum.json
-replace 'sMEOGo=' 'sMEoGo=XXX' tagtestsbadtagsum.json
-go mod download -reuse=tagtestsbadtagsum.json -x -json vcs-test.golang.org/hg/tagtests.hg@latest
+cp tagtests.json tagtestsbadreposum.json
+replace '8dnv90' '8dnv90XXX' tagtestsbadreposum.json
+go mod download -reuse=tagtestsbadreposum.json -x -json vcs-test.golang.org/hg/tagtests.hg@latest
! stdout '"Reuse": true'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-! stdout '"RepoSum"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
# go list on repo with no tags
go clean -modcache
stderr 'hg( .*)* pull'
cp stdout hellolist.json
! stdout '"Versions"'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
stdout '"Query": "latest"'
-! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"RepoSum"'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
# reuse go list on repo with no tags
go clean -modcache
! stderr 'hg( .*)* pull'
stdout '"Reuse": true'
! stdout '"Versions"'
-stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
+stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/hello"'
stdout '"Query": "latest"'
-! stdout '"TagPrefix"'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
-stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
-! stdout '"RepoSum"'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
+stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"'
# reuse with stale list
go clean -modcache
cp hellolist.json hellolistbad.json
-replace '47DEQ' 'ZZZ' hellolistbad.json
+replace 'blLvkhBri' 'ZZZ' hellolistbad.json
go clean -modcache
go list -x -reuse=hellolistbad.json -json -m -retracted -versions vcs-test.golang.org/hg/hello.hg@latest
stderr 'hg( .*)* pull'
! stdout '"Reuse": true'
-stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="'
+stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="'
# go list on repo with tags
go clean -modcache
stdout '"Version": "v0.2.2"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/tags/v0.2.2"'
+stdout '"Ref": "v0.2.2"'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
# reuse go list on repo with tags
go clean -modcache
stdout '"Version": "v0.2.2"'
stdout '"VCS": "hg"'
stdout '"URL": ".*/hg/tagtests"'
-stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
-stdout '"Ref": "refs/tags/v0.2.2"'
+stdout '"Ref": "v0.2.2"'
+stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'
# reuse with stale list
go clean -modcache
cp taglist.json taglistbad.json
-replace 'Dp7yRKDu' 'ZZZ' taglistbad.json
+replace '8dnv906' 'ZZZ' taglistbad.json
go list -reuse=taglistbad.json -x -json -m -retracted -versions vcs-test.golang.org/hg/tagtests.hg@latest
stderr 'hg( .*)* pull'
! stdout '"Reuse": true'
-stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="'
+stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="'