aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-03-07 23:31:29 +0000
committerPaulo Gomes <pjbgf@linux.com>2023-03-08 00:14:59 +0000
commit9822ad8573e374421a79c096d8f1dfa91366fb02 (patch)
treee3adb42646511378112cb05461bb8154f010ddee /plumbing/format/packfile
parent99e2f85843878671b028d4d01bd4668676226dd1 (diff)
downloadgo-git-9822ad8573e374421a79c096d8f1dfa91366fb02.tar.gz
*: Support variable length plumbing.Hash
The variable length for plumbing.Hash is defined at build time, blocked by tag sha256. This approach was a trade-off between keeping backwards compatibility while making progress towards supporting SHA256 with a small amount of changes. Relates to the SHA256 implementation, defined in #706. Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r--plumbing/format/packfile/encoder.go3
-rw-r--r--plumbing/format/packfile/encoder_test.go9
-rw-r--r--plumbing/format/packfile/scanner_test.go3
3 files changed, 8 insertions, 7 deletions
diff --git a/plumbing/format/packfile/encoder.go b/plumbing/format/packfile/encoder.go
index a8a7e96..c9d19b3 100644
--- a/plumbing/format/packfile/encoder.go
+++ b/plumbing/format/packfile/encoder.go
@@ -2,7 +2,6 @@ package packfile
import (
"compress/zlib"
- "crypto"
"fmt"
"io"
@@ -29,7 +28,7 @@ type Encoder struct {
// OFSDeltaObject. To use Reference deltas, set useRefDeltas to true.
func NewEncoder(w io.Writer, s storer.EncodedObjectStorer, useRefDeltas bool) *Encoder {
h := plumbing.Hasher{
- Hash: hash.New(crypto.SHA1),
+ Hash: hash.New(hash.CryptoType),
}
mw := io.MultiWriter(w, h)
ow := newOffsetWriter(mw)
diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go
index c9d49c3..902d8cc 100644
--- a/plumbing/format/packfile/encoder_test.go
+++ b/plumbing/format/packfile/encoder_test.go
@@ -7,6 +7,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/idxfile"
+ "github.com/go-git/go-git/v5/plumbing/hash"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/go-git/go-billy/v5/memfs"
@@ -30,10 +31,10 @@ func (s *EncoderSuite) SetUpTest(c *C) {
}
func (s *EncoderSuite) TestCorrectPackHeader(c *C) {
- hash, err := s.enc.Encode([]plumbing.Hash{}, 10)
+ h, err := s.enc.Encode([]plumbing.Hash{}, 10)
c.Assert(err, IsNil)
- hb := [20]byte(hash)
+ hb := [hash.Size]byte(h)
// PACK + VERSION + OBJECTS + HASH
expectedResult := []byte{'P', 'A', 'C', 'K', 0, 0, 0, 2, 0, 0, 0, 0}
@@ -51,7 +52,7 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) {
_, err := s.store.SetEncodedObject(o)
c.Assert(err, IsNil)
- hash, err := s.enc.Encode([]plumbing.Hash{o.Hash()}, 10)
+ h, err := s.enc.Encode([]plumbing.Hash{o.Hash()}, 10)
c.Assert(err, IsNil)
// PACK + VERSION(2) + OBJECT NUMBER(1)
@@ -64,7 +65,7 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) {
[]byte{120, 156, 1, 0, 0, 255, 255, 0, 0, 0, 1}...)
// + HASH
- hb := [20]byte(hash)
+ hb := [hash.Size]byte(h)
expectedResult = append(expectedResult, hb[:]...)
result := s.buf.Bytes()
diff --git a/plumbing/format/packfile/scanner_test.go b/plumbing/format/packfile/scanner_test.go
index 892a27c..9dcc359 100644
--- a/plumbing/format/packfile/scanner_test.go
+++ b/plumbing/format/packfile/scanner_test.go
@@ -6,6 +6,7 @@ import (
fixtures "github.com/go-git/go-git-fixtures/v4"
"github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/plumbing/hash"
. "gopkg.in/check.v1"
)
@@ -71,7 +72,7 @@ func (s *ScannerSuite) testNextObjectHeader(c *C, tag string,
n, err := p.Checksum()
c.Assert(err, IsNil)
- c.Assert(n, HasLen, 20)
+ c.Assert(n, HasLen, hash.Size)
}
func (s *ScannerSuite) TestNextObjectHeaderWithOutReadObject(c *C) {