diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-11 20:35:06 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-11 20:35:06 +0200 |
commit | 58fe211f1b0e4863b425542d2fad15803276fd66 (patch) | |
tree | c200b6317b7b1c77c312faa411ab39e6e4468967 /formats/packfile/decoder_test.go | |
parent | 6f1d1e00a7c615209cf6b25e314d033bda3b5d09 (diff) | |
download | go-git-58fe211f1b0e4863b425542d2fad15803276fd66.tar.gz |
format: packfile fix ReadObjectAt without decode
Diffstat (limited to 'formats/packfile/decoder_test.go')
-rw-r--r-- | formats/packfile/decoder_test.go | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/formats/packfile/decoder_test.go b/formats/packfile/decoder_test.go index 7baab44..d85f3bf 100644 --- a/formats/packfile/decoder_test.go +++ b/formats/packfile/decoder_test.go @@ -1,10 +1,12 @@ package packfile import ( + "io" "testing" "gopkg.in/src-d/go-git.v4/core" "gopkg.in/src-d/go-git.v4/fixtures" + "gopkg.in/src-d/go-git.v4/formats/idxfile" "gopkg.in/src-d/go-git.v4/storage/memory" . "gopkg.in/check.v1" @@ -68,7 +70,7 @@ func (s *ReaderSuite) TestDecode(c *C) { }) } func (s *ReaderSuite) TestDecodeCRCs(c *C) { - f := fixtures.Basic().ByTag("ofs-delta") + f := fixtures.Basic().ByTag("ofs-delta").One() scanner := NewScanner(f.Packfile()) storage := memory.NewStorage() @@ -86,18 +88,24 @@ func (s *ReaderSuite) TestDecodeCRCs(c *C) { } func (s *ReaderSuite) TestReadObjectAt(c *C) { - f := fixtures.Basic().One() + fixtures.Basic().Test(c, func(f *fixtures.Fixture) { + scanner := NewScanner(f.Packfile()) + storage := memory.NewStorage() - scanner := NewScanner(f.Packfile()) - storage := memory.NewStorage() + d := NewDecoder(scanner, storage.ObjectStorage()) - d := NewDecoder(scanner, storage.ObjectStorage()) + // when the packfile is ref-delta based, the offsets are required + if f.Is("ref-delta") { + offsets := getOffsetsFromIdx(f.Idx()) + d.SetOffsets(offsets) + } - // the objects at reference 186, is a delta, so should be recall, without - // being read before. - obj, err := d.ReadObjectAt(186) - c.Assert(err, IsNil) - c.Assert(obj.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + // the objects at reference 186, is a delta, so should be recall, + // without being read before. + obj, err := d.ReadObjectAt(186) + c.Assert(err, IsNil) + c.Assert(obj.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + }) } func AssertObjects(c *C, s *memory.Storage, expects []string) { @@ -110,3 +118,18 @@ func AssertObjects(c *C, s *memory.Storage, expects []string) { c.Assert(obt.Hash().String(), Equals, exp) } } + +func getOffsetsFromIdx(r io.Reader) map[core.Hash]int64 { + idx := &idxfile.Idxfile{} + err := idxfile.NewDecoder(r).Decode(idx) + if err != nil { + panic(err) + } + + offsets := make(map[core.Hash]int64) + for _, e := range idx.Entries { + offsets[e.Hash] = int64(e.Offset) + } + + return offsets +} |