aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/commitgraph/encoder.go
diff options
context:
space:
mode:
authorAndrew Thornton <art27@cantab.net>2023-09-30 09:09:10 +0100
committerAndrew Thornton <art27@cantab.net>2023-09-30 10:35:18 +0100
commit9c9c8c331b6bdb8fd5710c433e0dfd42f756d119 (patch)
tree0cd246aaa5dddb93c8cc8462956aecb14b6a1fd6 /plumbing/format/commitgraph/encoder.go
parent3e9173c2bd35ac1d85fb9070755d2dd0363d22b9 (diff)
downloadgo-git-9c9c8c331b6bdb8fd5710c433e0dfd42f756d119.tar.gz
plumbing: commitgraph, allow SHA256 commit-graphs
Since the build-tag sha256 was introduced the commit graph code should be switched to use hash.Size and only use a graph if it has the correct hash version for the version of go-git that is built. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'plumbing/format/commitgraph/encoder.go')
-rw-r--r--plumbing/format/commitgraph/encoder.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/plumbing/format/commitgraph/encoder.go b/plumbing/format/commitgraph/encoder.go
index f61025b..674f52e 100644
--- a/plumbing/format/commitgraph/encoder.go
+++ b/plumbing/format/commitgraph/encoder.go
@@ -1,6 +1,7 @@
package commitgraph
import (
+ "crypto"
"io"
"github.com/go-git/go-git/v5/plumbing"
@@ -30,7 +31,7 @@ func (e *Encoder) Encode(idx Index) error {
hashToIndex, fanout, extraEdgesCount := e.prepare(idx, hashes)
chunkSignatures := [][]byte{oidFanoutSignature, oidLookupSignature, commitDataSignature}
- chunkSizes := []uint64{4 * 256, uint64(len(hashes)) * hash.Size, uint64(len(hashes)) * 36}
+ chunkSizes := []uint64{4 * 256, uint64(len(hashes)) * hash.Size, uint64(len(hashes)) * (hash.Size + commitDataSize)}
if extraEdgesCount > 0 {
chunkSignatures = append(chunkSignatures, extraEdgeListSignature)
chunkSizes = append(chunkSizes, uint64(extraEdgesCount)*4)
@@ -88,7 +89,11 @@ func (e *Encoder) prepare(idx Index, hashes []plumbing.Hash) (hashToIndex map[pl
func (e *Encoder) encodeFileHeader(chunkCount int) (err error) {
if _, err = e.Write(commitFileSignature); err == nil {
- _, err = e.Write([]byte{1, 1, byte(chunkCount), 0})
+ version := byte(1)
+ if hash.CryptoType == crypto.SHA256 {
+ version = byte(2)
+ }
+ _, err = e.Write([]byte{1, version, byte(chunkCount), 0})
}
return
}