Skip to content

Commit bf2ff33

Browse files
committed
use max hash size constant for all SHA byte arrays
Expanding on the introduction of the maxHashSize constant in 528473b, we can use this in several other places as well for byte array initialization.
1 parent cb39e77 commit bf2ff33

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

pack/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
)
99

10-
const maxHashSize = sha256.Size
10+
const MaxHashSize = sha256.Size
1111

1212
// Index stores information about the location of objects in a corresponding
1313
// packfile.

pack/index_v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type V1 struct {
1313
// Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name
1414
// for the given entry at offset "at" in the v1 index file "idx".
1515
func (v *V1) Name(idx *Index, at int64) ([]byte, error) {
16-
var sha [maxHashSize]byte
16+
var sha [MaxHashSize]byte
1717

1818
hashlen := v.hash.Size()
1919

pack/index_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type V2 struct {
1313
// Name implements IndexVersion.Name by returning the 20 byte SHA-1 object name
1414
// for the given entry at offset "at" in the v2 index file "idx".
1515
func (v *V2) Name(idx *Index, at int64) ([]byte, error) {
16-
var sha [maxHashSize]byte
16+
var sha [MaxHashSize]byte
1717

1818
hashlen := v.hash.Size()
1919

pack/packfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (p *Packfile) findBase(typ PackedObjectType, offset, objOffset int64) (Chai
190190
// We assume that we have to read at least an object ID's worth (the
191191
// hash length in the case of a OBJ_REF_DELTA, or greater than the
192192
// length of the base offset encoded in an OBJ_OFS_DELTA).
193-
var sha [32]byte
193+
var sha [MaxHashSize]byte
194194
if _, err := p.r.ReadAt(sha[:hashlen], offset); err != nil {
195195
return nil, baseOffset, err
196196
}

tree.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strconv"
1111
"strings"
1212
"syscall"
13+
14+
"github.com/git-lfs/gitobj/v2/pack"
1315
)
1416

1517
// Tree encapsulates a Git tree object.
@@ -53,7 +55,7 @@ func (t *Tree) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err er
5355
n += len(fname)
5456
fname = strings.TrimSuffix(fname, "\x00")
5557

56-
var sha [32]byte
58+
var sha [pack.MaxHashSize]byte
5759
if _, err = io.ReadFull(buf, sha[:hashlen]); err != nil {
5860
return n, err
5961
}

0 commit comments

Comments
 (0)