aboutsummaryrefslogtreecommitdiff
path: root/internal/stdlib/stdlib.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2022-01-12 11:02:09 -0500
committerJonathan Amsterdam <jba@google.com>2022-01-12 19:25:48 +0000
commit5e4fb81f1c5c43697f71e4e7850925f852441b1d (patch)
tree6d55df8d6689ff072270c81379292c92510433ef /internal/stdlib/stdlib.go
parent025beca8db02578a8fdbe10841376f52b4ee4c0c (diff)
downloadgo-x-pkgsite-5e4fb81f1c5c43697f71e4e7850925f852441b1d.tar.xz
internal/stdlib: get versions from local repo
When a local repo path has been specified, Versions will read refs from that repo instead of the remote. I checked with strace that visiting a stdlib package did not hit the network after this change. Fixes golang/go#50575 Change-Id: I3e61ab5a3f6e1be85c437412a0e4d4149b7f1f3c Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/378054 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/stdlib/stdlib.go')
-rw-r--r--internal/stdlib/stdlib.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
index 1f821799..926c7b32 100644
--- a/internal/stdlib/stdlib.go
+++ b/internal/stdlib/stdlib.go
@@ -324,6 +324,23 @@ func Versions() (_ []string, err error) {
var refNames []plumbing.ReferenceName
if UseTestData {
refNames = testRefs
+ } else if path := getGoRepoPath(); path != "" {
+ repo, err := git.PlainOpen(path)
+ if err != nil {
+ return nil, err
+ }
+ iter, err := repo.References()
+ if err != nil {
+ return nil, err
+ }
+ defer iter.Close()
+ err = iter.ForEach(func(r *plumbing.Reference) error {
+ refNames = append(refNames, r.Name())
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
} else {
refs, err := remoteRefs()
if err != nil {