]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: accept @hash/branch in mod download
authormarwan-at-work <marwan.sameer@gmail.com>
Fri, 16 Nov 2018 02:04:44 +0000 (02:04 +0000)
committerBryan C. Mills <bcmills@google.com>
Fri, 16 Nov 2018 19:46:17 +0000 (19:46 +0000)
Go get in mod-enabled packages lets you do go get "pkg@<hash>" or "pkg@<branch>".
Go internally will switch the hash or branch into a pseudo version.
Go mod download should do the same. The bug lay in the fact that the disk cache
was not being written when Go converted the hash/branch into a pseudo version.

Fixes #27947

Change-Id: I94c29a5c95f69ab18a9cd7a2ecade128047c5e36
GitHub-Last-Rev: 668634b3e70206c6eadabae5969fca1b03093b0d
GitHub-Pull-Request: golang/go#28042
Reviewed-on: https://go-review.googlesource.com/c/140257
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modfetch/cache.go
src/cmd/go/testdata/script/mod_download_hash.txt [new file with mode: 0644]

index 1f9cc96c3ec80858ff299b959e9b715438333596..171718d20b0689152ea887da33477342aa2c4387 100644 (file)
@@ -129,16 +129,18 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
                }
                info, err = r.r.Stat(rev)
                if err == nil {
-                       if err := writeDiskStat(file, info); err != nil {
-                               fmt.Fprintf(os.Stderr, "go: writing stat cache: %v\n", err)
-                       }
                        // If we resolved, say, 1234abcde to v0.0.0-20180604122334-1234abcdef78,
                        // then save the information under the proper version, for future use.
                        if info.Version != rev {
+                               file, _ = CachePath(module.Version{Path: r.path, Version: info.Version}, "info")
                                r.cache.Do("stat:"+info.Version, func() interface{} {
                                        return cachedInfo{info, err}
                                })
                        }
+
+                       if err := writeDiskStat(file, info); err != nil {
+                               fmt.Fprintf(os.Stderr, "go: writing stat cache: %v\n", err)
+                       }
                }
                return cachedInfo{info, err}
        }).(cachedInfo)
diff --git a/src/cmd/go/testdata/script/mod_download_hash.txt b/src/cmd/go/testdata/script/mod_download_hash.txt
new file mode 100644 (file)
index 0000000..1662043
--- /dev/null
@@ -0,0 +1,23 @@
+env GO111MODULE=on
+
+# Testing mod download with non semantic versions; turn off proxy.
+[!net] skip
+[!exec:git] skip
+env GOPROXY=
+
+go mod download rsc.io/quote@a91498bed0a73d4bb9c1fb2597925f7883bc40a7
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180709162918-a91498bed0a7.info
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180709162918-a91498bed0a7.mod
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180709162918-a91498bed0a7.zip
+
+go mod download rsc.io/quote@master
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180710144737-5d9f230bcfba.info
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180710144737-5d9f230bcfba.mod
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v0.0.0-20180710144737-5d9f230bcfba.zip
+
+
+-- go.mod --
+module m
+
+-- m.go --
+package m
\ No newline at end of file