]> Cypherpunks repositories - gostls13.git/commit
cmd/go: add support for git sha256 hashes
authorDavid Finkel <david.finkel@gmail.com>
Sat, 14 Dec 2024 01:36:30 +0000 (20:36 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 13 May 2025 17:14:36 +0000 (10:14 -0700)
commit76f63ee890170f4884f4d213e8150d39d6758ad3
tree0d31a02cea0e11d0ad51c66b9546e4ea704ff096
parent4aeb9ba0deac4eced472a8fc7869a14fb9340d04
cmd/go: add support for git sha256 hashes

Git's supported SHA 256 object hashes since 2.29[1] in 2021, and Gitlab
now has experimental support for sha256 repos.

Take rsc@'s suggestion of checking the of the length of the hashes from
git ls-remote to determine whether a git repo is using sha256 hashes and
decide whether to pass --object-format=sha256 to git init.

Unfortunately, just passing --object-format=sha256 wasn't quite enough,
though. We also need to decide whether the hash-length is 64 hex bytes
or 40 hex bytes when resolving refs to decide whether we've been passed
a full commit-hash. To that end, we use
git config extensions.objectformat to decide whether the (now guaranteed
local) repo is using sha256 hashes and hence 64-hex-byte strings.

[1]: lost experimental status in 2.42 from Aug 2023
(https://lore.kernel.org/git/xmqqr0nwp8mv.fsf@gitster.g/)

For: #68359
Change-Id: I47f480ab8334128c5d17570fe76722367d0d8ed8
Reviewed-on: https://go-review.googlesource.com/c/go/+/636475
Auto-Submit: Sam Thanawalla <samthanawalla@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: David Finkel <david.finkel@gmail.com>
src/cmd/go/internal/modfetch/codehost/git.go
src/cmd/go/internal/modfetch/codehost/git_test.go
src/cmd/go/testdata/script/mod_download_git_bareRepository_sha256.txt [new file with mode: 0644]
src/cmd/go/testdata/vcstest/git/gitrepo-sha256.txt [new file with mode: 0644]
src/cmd/go/testdata/vcstest/go/mod/gitrepo-sha256.txt [new file with mode: 0644]