Skip to content

Commit 3f842f2

Browse files
committed
verify-pack: Add support for sha256 packfiles
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 312096e commit 3f842f2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cmd/gogit/verify-pack.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ var (
2222
verifyPackVerbose bool
2323
verifyPackFixtureUrl bool
2424
verifyPackFixtureTag bool
25+
verifyPackSHA256 bool
2526
)
2627

2728
func init() {
2829
verifyPackCmd.Flags().BoolVarP(&verifyPackVerbose, "verbose", "v", false, "Show detailed object information")
2930
verifyPackCmd.Flags().BoolVarP(&verifyPackFixtureUrl, "fixture-url", "", false, "Use <file> as go-git-fixture url")
3031
verifyPackCmd.Flags().BoolVarP(&verifyPackFixtureTag, "fixture-tag", "", false, "Use <file> as go-git-fixture tag")
32+
verifyPackCmd.Flags().BoolVarP(&verifyPackSHA256, "sha256", "", false, "Treat the pack file as sha256")
3133
rootCmd.AddCommand(verifyPackCmd)
3234
}
3335

@@ -72,7 +74,12 @@ func verifyPack(path string, verbose bool) error {
7274
}
7375
}()
7476

75-
idx := idxfile.NewMemoryIndex(crypto.SHA1.Size())
77+
ch := crypto.SHA1
78+
if verifyPackSHA256 {
79+
ch = crypto.SHA256
80+
}
81+
82+
idx := idxfile.NewMemoryIndex(ch.Size())
7683

7784
dec := idxfile.NewDecoder(idxFile)
7885
if err := dec.Decode(idx); err != nil {
@@ -82,6 +89,7 @@ func verifyPack(path string, verbose bool) error {
8289
pf := packfile.NewPackfile(
8390
packFile,
8491
packfile.WithIdx(idx),
92+
packfile.WithObjectIDSize(ch.Size()),
8593
)
8694

8795
defer func() {
@@ -148,8 +156,8 @@ func verifyPack(path string, verbose bool) error {
148156
if err != nil {
149157
return fmt.Errorf("failed to stat pack file: %w", err)
150158
}
151-
// Pack file ends with a 20-byte SHA-1 checksum.
152-
objects[len(objects)-1].packedSize = stat.Size() - objects[len(objects)-1].offset - int64(crypto.SHA1.Size())
159+
// Pack file ends with a checksum (20-byte SHA-1 or 32-byte SHA-256).
160+
objects[len(objects)-1].packedSize = stat.Size() - objects[len(objects)-1].offset - int64(ch.Size())
153161
}
154162

155163
// Resolve actual types for all objects (after delta application).

0 commit comments

Comments
 (0)