aboutsummaryrefslogtreecommitdiffstats
path: root/formats/packfile/parser_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'formats/packfile/parser_test.go')
-rw-r--r--formats/packfile/parser_test.go553
1 files changed, 102 insertions, 451 deletions
diff --git a/formats/packfile/parser_test.go b/formats/packfile/parser_test.go
index 0c07daa..d746b98 100644
--- a/formats/packfile/parser_test.go
+++ b/formats/packfile/parser_test.go
@@ -2,502 +2,153 @@ package packfile
import (
"bytes"
- "encoding/base64"
- "io/ioutil"
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-git.v4/core"
+ "gopkg.in/src-d/go-git.v4/fixtures"
)
type ScannerSuite struct{}
var _ = Suite(&ScannerSuite{})
+func (s *ScannerSuite) SetUpSuite(c *C) {
+ fixtures.RootFolder = "../../fixtures"
+}
+
func (s *ScannerSuite) TestHeader(c *C) {
- data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects)
+ r := fixtures.Basic().One().Packfile()
+ p := NewScanner(r)
- p := NewScanner(bytes.NewReader(data))
version, objects, err := p.Header()
c.Assert(err, IsNil)
c.Assert(version, Equals, VersionSupported)
- c.Assert(objects, Equals, uint32(11))
+ c.Assert(objects, Equals, uint32(31))
}
-func (s *ScannerSuite) TestNextObjectHeader(c *C) {
- data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects)
+func (s *ScannerSuite) TestNextObjectHeaderREFDelta(c *C) {
+ s.testNextObjectHeader(c, "ref-delta", expectedHeadersREF)
+}
- r := bytes.NewReader(data)
+func (s *ScannerSuite) TestNextObjectHeaderOFSDelta(c *C) {
+ s.testNextObjectHeader(c, "ofs-delta", expectedHeadersOFS)
+}
+
+func (s *ScannerSuite) testNextObjectHeader(c *C, tag string, expected []ObjectHeader) {
+ r := fixtures.Basic().ByTag(tag).Packfile()
p := NewScanner(r)
+
_, objects, err := p.Header()
c.Assert(err, IsNil)
for i := 0; i < int(objects); i++ {
h, err := p.NextObjectHeader()
c.Assert(err, IsNil)
- c.Assert(*h, DeepEquals, expectedHeaders[i])
+ c.Assert(*h, DeepEquals, expected[i])
buf := bytes.NewBuffer(nil)
- n, err := p.NextObject(buf)
+ n, _, err := p.NextObject(buf)
c.Assert(err, IsNil)
c.Assert(n, Equals, h.Length)
}
- n, err := ioutil.ReadAll(r)
+ n, err := p.Checksum()
c.Assert(err, IsNil)
c.Assert(n, HasLen, 20)
}
func (s *ScannerSuite) TestNextObjectHeaderWithOutReadObject(c *C) {
- data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects)
-
- r := bytes.NewReader(data)
+ f := fixtures.Basic().ByTag("ref-delta")
+ r := f.Packfile()
p := NewScanner(r)
+
_, objects, err := p.Header()
c.Assert(err, IsNil)
for i := 0; i < int(objects); i++ {
- h, err := p.NextObjectHeader()
+ h, _ := p.NextObjectHeader()
c.Assert(err, IsNil)
- c.Assert(*h, DeepEquals, expectedHeaders[i])
+ c.Assert(*h, DeepEquals, expectedHeadersREF[i])
}
err = p.discardObjectIfNeeded()
c.Assert(err, IsNil)
- n, err := ioutil.ReadAll(r)
- c.Assert(err, IsNil)
- c.Assert(n, HasLen, 20)
-}
-
-var expectedHeaders = []ObjectHeader{
- {Type: core.CommitObject, Offset: 12, Length: 239},
- {Type: core.CommitObject, Offset: 177, Length: 244},
- {Type: core.CommitObject, Offset: 345, Length: 239},
- {Type: core.CommitObject, Offset: 507, Length: 191},
- {Type: core.TreeObject, Offset: 639, Length: 91},
- {Type: core.BlobObject, Offset: 714, Length: 0},
- {Type: core.BlobObject, Offset: 723, Length: 14},
- {Type: core.OFSDeltaObject, Offset: 740, Length: 4, OffsetReference: 639},
- {Type: core.TreeObject, Offset: 754, Length: 58},
- {Type: core.BlobObject, Offset: 820, Length: 7},
- {Type: core.TreeObject, Offset: 833, Length: 29},
-}
-
-/*
-const (
- sigOffset = 0
- verOffset = 4
- countOffset = 8
-)
-
-type ParserSuite struct {
- fixtures map[string]*fix
-}
-
-type fix struct {
- path string
- parser *Parser
- seekable io.Seeker
-}
-
-func newFix(path string) (*fix, error) {
- fix := new(fix)
- fix.path = path
-
- f, err := os.Open(path)
- if err != nil {
- return nil, err
- }
-
- data, err := ioutil.ReadAll(f)
- if err != nil {
- return nil, err
- }
-
- if err = f.Close(); err != nil {
- return nil, err
- }
-
- seekable := NewSeekable(bytes.NewReader(data))
- fix.seekable = seekable
- fix.parser = NewParser(seekable)
-
- return fix, nil
-}
-
-func (f *fix) seek(o int64) error {
- _, err := f.seekable.Seek(o, os.SEEK_SET)
- return err
-}
-
-var _ = Suite(&ParserSuite{})
-
-func (s *ParserSuite) SetUpSuite(c *C) {
- s.fixtures = make(map[string]*fix)
- for _, fixData := range []struct {
- id string
- path string
- }{
- {"ofs-deltas", "fixtures/alcortesm-binary-relations.pack"},
- {"ref-deltas", "fixtures/git-fixture.ref-delta"},
- } {
- fix, err := newFix(fixData.path)
- c.Assert(err, IsNil,
- Commentf("setting up fixture id %s: %s", fixData.id, err))
-
- _, ok := s.fixtures[fixData.id]
- c.Assert(ok, Equals, false,
- Commentf("duplicated fixture id: %s", fixData.id))
-
- s.fixtures[fixData.id] = fix
- }
-}
-
-func (s *ParserSuite) TestSignature(c *C) {
- for id, fix := range s.fixtures {
- com := Commentf("fixture id = %s", id)
- err := fix.seek(sigOffset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- sig, err := p.ReadSignature()
- c.Assert(err, IsNil, com)
- c.Assert(p.IsValidSignature(sig), Equals, true, com)
- }
-}
-
-func (s *ParserSuite) TestVersion(c *C) {
- for i, test := range [...]struct {
- fixID string
- expected uint32
- }{
- {
- fixID: "ofs-deltas",
- expected: uint32(2),
- }, {
- fixID: "ref-deltas",
- expected: uint32(2),
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(verOffset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- v, err := p.ReadVersion()
- c.Assert(err, IsNil, com)
- c.Assert(v, Equals, test.expected, com)
- c.Assert(p.IsSupportedVersion(v), Equals, true, com)
- }
-}
-
-func (s *ParserSuite) TestCount(c *C) {
- for i, test := range [...]struct {
- fixID string
- expected uint32
- }{
- {
- fixID: "ofs-deltas",
- expected: uint32(0x50),
- }, {
- fixID: "ref-deltas",
- expected: uint32(0x1c),
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(countOffset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- count, err := p.ReadCount()
- c.Assert(err, IsNil, com)
- c.Assert(count, Equals, test.expected, com)
- }
-}
-
-func (s *ParserSuite) TestReadObjectTypeAndLength(c *C) {
- for i, test := range [...]struct {
- fixID string
- offset int64
- expType core.ObjectType
- expLength int64
- }{
- {
- fixID: "ofs-deltas",
- offset: 12,
- expType: core.CommitObject,
- expLength: 342,
- }, {
- fixID: "ofs-deltas",
- offset: 1212,
- expType: core.OFSDeltaObject,
- expLength: 104,
- }, {
- fixID: "ofs-deltas",
- offset: 3193,
- expType: core.TreeObject,
- expLength: 226,
- }, {
- fixID: "ofs-deltas",
- offset: 3639,
- expType: core.BlobObject,
- expLength: 90,
- }, {
- fixID: "ofs-deltas",
- offset: 4504,
- expType: core.BlobObject,
- expLength: 7107,
- }, {
- fixID: "ref-deltas",
- offset: 84849,
- expType: core.REFDeltaObject,
- expLength: 6,
- }, {
- fixID: "ref-deltas",
- offset: 85070,
- expType: core.REFDeltaObject,
- expLength: 8,
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(test.offset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- typ, length, err := p.ReadObjectTypeAndLength()
- c.Assert(err, IsNil, com)
- c.Assert(typ, Equals, test.expType, com)
- c.Assert(length, Equals, test.expLength, com)
- }
-}
-
-func (s *ParserSuite) TestReadNonDeltaObjectContent(c *C) {
- for i, test := range [...]struct {
- fixID string
- offset int64
- expected []byte
- }{
- {
- fixID: "ofs-deltas",
- offset: 12,
- expected: []byte("tree 87c87d16e815a43e4e574dd8edd72c5450ac3a8e\nparent a87d72684d1cf68099ce6e9f68689e25e645a14c\nauthor Gorka Guardiola <Gorka Guardiola Múzquiz> 1450265632 +0100\ncommitter Gorka Guardiola <Gorka Guardiola Múzquiz> 1450265632 +0100\n\nChanged example to use dot.\nI did not remove the original files outside of the\ntex, I leave that to alcortes.\n"),
- }, {
- fixID: "ofs-deltas",
- offset: 1610,
- expected: []byte("tree 4b4f0d9a07109ef0b8a3051138cc20cdb47fa513\nparent b373f85fa2594d7dcd9989f4a5858a81647fb8ea\nauthor Alberto Cortés <alberto@sourced.tech> 1448017995 +0100\ncommitter Alberto Cortés <alberto@sourced.tech> 1448018112 +0100\n\nMove generated images to it own dir (img/)\n\nFixes #1.\n"),
- }, {
- fixID: "ofs-deltas",
- offset: 10566,
- expected: []byte("40000 map-slice\x00\x00\xce\xfb\x8ew\xf7\xa8\xc6\x1b\x99\xdd$\x91\xffH\xa3\xb0\xb1fy40000 simple-arrays\x00\x9a7\x81\xb7\xfd\x9d(Q\xe2\xa4H\x8c\x03^٬\x90Z\xecy"),
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(test.offset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- _, _, err = p.ReadObjectTypeAndLength()
- c.Assert(err, IsNil, com)
-
- obj := &core.MemoryObject{}
- err = p.FillFromNonDeltaContent(obj)
- c.Assert(err, IsNil, com)
-
- r, _ := obj.Reader()
- bytes, _ := ioutil.ReadAll(r)
- c.Assert(bytes, DeepEquals, test.expected, com)
- }
-}
-
-func (s *ParserSuite) TestFillOFSDeltaObjectContent(c *C) {
- for i, test := range [...]struct {
- fixID string
- offset int64
- expOffset int64
- expType core.ObjectType
- expContent []byte
- }{
- {
- fixID: "ofs-deltas",
- offset: 1212,
- expOffset: -212,
- expType: core.CommitObject,
- expContent: []byte("tree c4573589ce78ac63769c20742b9a970f6e274a38\nparent 4571a24948494ebe1cb3dc18ca5a9286e79705ae\nauthor Alberto Cortés <alberto@sourced.tech> 1448139640 +0100\ncommitter Alberto Cortés <alberto@sourced.tech> 1448139640 +0100\n\nUpdate reference to binrels module\n"),
- }, {
- fixID: "ofs-deltas",
- offset: 3514,
- expOffset: -102,
- expType: core.TreeObject,
- expContent: []byte("100644 .gitignore\x00\u007fA\x90[Mw\xabJ\x9a-3O\xcd\x0f\xb5\xdbn\x8e!\x83100644 .gitmodules\x00\xd4`\xa8>\x15\xcfd\x05\x81B7_\xc4\v\x04\xa7\xa9A\x85\n100644 Makefile\x00-ҭ\x8c\x14\xdef\x12\xed\x15\x816y\xa6UK\xad\x993\v100644 binary-relations.tex\x00\x802\x05@\x11'^ \xf5<\xf7\xfd\x81%3\xd1o\xa9_$40000 graphs\x00\xdehu\x16\xc6\x0e\\H\x8e\xe9\xa1JIXE\xbaڽg\xc540000 imgs-gen\x00\xeb\"\xddhzg\xa3\x1f\xc8j\xc5\xfc豢\xe9\x96\xce\xce^40000 src\x00\x895\x11t\xff\x86\xa7\xea\xa6\xc0v%\x11E\x10f,ݒ\x1a"),
- }, {
- fixID: "ofs-deltas",
- offset: 9806,
- expOffset: -6613,
- expType: core.TreeObject,
- expContent: []byte("100644 .gitignore\x00\u007fA\x90[Mw\xabJ\x9a-3O\xcd\x0f\xb5\xdbn\x8e!\x83100644 .gitmodules\x00\xd4`\xa8>\x15\xcfd\x05\x81B7_\xc4\v\x04\xa7\xa9A\x85\n100644 Makefile\x00-ҭ\x8c\x14\xdef\x12\xed\x15\x816y\xa6UK\xad\x993\v100644 binary-relations.tex\x00I\x13~\xb8کEU\x9f\x99#\xc4E.\x9d>\uef1e\xad40000 graphs\x00\xb9\x00\xf34\xde\xff\xce@+\xbd\xf8 9\xb8=\xc1\xb9\x00\x84]40000 imgs-gen\x00\xeb\"\xddhzg\xa3\x1f\xc8j\xc5\xfc豢\xe9\x96\xce\xce^40000 src\x00\x895\x11t\xff\x86\xa7\xea\xa6\xc0v%\x11E\x10f,ݒ\x1a"),
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(test.offset)
- c.Assert(err, IsNil, com)
- p := fix.parser
-
- _, _, err = p.ReadObjectTypeAndLength()
- c.Assert(err, IsNil, com)
-
- beforeJumpSize, err := p.Offset()
- c.Assert(err, IsNil, com)
-
- jump, err := p.ReadNegativeOffset()
- c.Assert(err, IsNil, com)
- c.Assert(jump, Equals, test.expOffset, com)
-
- err = fix.seek(beforeJumpSize)
- c.Assert(err, IsNil, com)
-
- obj := &core.MemoryObject{}
- err = p.FillOFSDeltaObjectContent(obj, test.offset)
- c.Assert(err, IsNil, com)
- c.Assert(obj.Type(), Equals, test.expType, com)
-
- r, _ := obj.Reader()
- bytes, _ := ioutil.ReadAll(r)
- c.Assert(bytes, DeepEquals, test.expContent, com)
- }
-}
-
-func (s *ParserSuite) TestFillREFDeltaObjectContent(c *C) {
- for i, test := range [...]struct {
- fixID string
- offset int64
- deps map[int64]core.Object
- expHash core.Hash
- expType core.ObjectType
- expContent []byte
- }{
- {
- fixID: "ref-deltas",
- offset: 84849,
- deps: map[int64]core.Object{
- 83607: newObject(core.TreeObject, []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 CHANGELOG\x00\xd3\xffS\xe0VJ\x9f\x87\xd8\xe8Kn(\xe5\x06\x0eQp\b\xaa100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r40000 go\x00\xa3\x97q\xa7e\x1f\x97\xfa\xf5\xc7.\b\"M\x85\u007f\xc3Q3\xdb40000 json\x00Z\x87~j\x90j'C\xadnEٜ\x17\x93d*\xaf\x8e\xda40000 php\x00Xj\xf5gл^w\x1eI\xbd\xd9CO^\x0f\xb7m%\xfa40000 vendor\x00\xcfJ\xa3\xb3\x89t\xfb}\x81\xf3g\xc0\x83\x0f}x\xd6Z\xb8k")),
- },
- expHash: core.NewHash("a8d315b2b1c615d43042c3a62402b8a54288cf5c"),
- expType: core.TreeObject,
- expContent: []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 CHANGELOG\x00\xd3\xffS\xe0VJ\x9f\x87\xd8\xe8Kn(\xe5\x06\x0eQp\b\xaa100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r40000 go\x00\xa3\x97q\xa7e\x1f\x97\xfa\xf5\xc7.\b\"M\x85\u007f\xc3Q3\xdb40000 json\x00Z\x87~j\x90j'C\xadnEٜ\x17\x93d*\xaf\x8e\xda40000 php\x00Xj\xf5gл^w\x1eI\xbd\xd9CO^\x0f\xb7m%\xfa"),
- }, {
- fixID: "ref-deltas",
- offset: 85070,
- deps: map[int64]core.Object{
- 84922: newObject(core.TreeObject, []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 CHANGELOG\x00\xd3\xffS\xe0VJ\x9f\x87\xd8\xe8Kn(\xe5\x06\x0eQp\b\xaa100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r")),
- 84849: newObject(core.TreeObject, []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 CHANGELOG\x00\xd3\xffS\xe0VJ\x9f\x87\xd8\xe8Kn(\xe5\x06\x0eQp\b\xaa100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r40000 go\x00\xa3\x97q\xa7e\x1f\x97\xfa\xf5\xc7.\b\"M\x85\u007f\xc3Q3\xdb40000 json\x00Z\x87~j\x90j'C\xadnEٜ\x17\x93d*\xaf\x8e\xda40000 php\x00Xj\xf5gл^w\x1eI\xbd\xd9CO^\x0f\xb7m%\xfa")),
- 83607: newObject(core.TreeObject, []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 CHANGELOG\x00\xd3\xffS\xe0VJ\x9f\x87\xd8\xe8Kn(\xe5\x06\x0eQp\b\xaa100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r40000 go\x00\xa3\x97q\xa7e\x1f\x97\xfa\xf5\xc7.\b\"M\x85\u007f\xc3Q3\xdb40000 json\x00Z\x87~j\x90j'C\xadnEٜ\x17\x93d*\xaf\x8e\xda40000 php\x00Xj\xf5gл^w\x1eI\xbd\xd9CO^\x0f\xb7m%\xfa40000 vendor\x00\xcfJ\xa3\xb3\x89t\xfb}\x81\xf3g\xc0\x83\x0f}x\xd6Z\xb8k")),
- },
- expHash: core.NewHash("eba74343e2f15d62adedfd8c883ee0262b5c8021"),
- expType: core.TreeObject,
- expContent: []byte("100644 .gitignore\x002\x85\x8a\xad<8>\xd1\xff\n\x0f\x9b\xdf#\x1dT\xa0\f\x9e\x88100644 LICENSE\x00\xc1\x92\xbdj$\xea\x1a\xb0\x1dxhnA|\x8b\xdc|=\x19\u007f100644 binary.jpg\x00\xd5\xc0\xf4\xab\x81\x18\x97\xca\xdf\x03\xae\xc3X\xae`\xd2\x1f\x91\xc5\r"),
- },
- } {
- com := Commentf("test %d) fixture id = %s", i, test.fixID)
- fix, ok := s.fixtures[test.fixID]
- c.Assert(ok, Equals, true, com)
-
- err := fix.seek(test.offset)
- c.Assert(err, IsNil, com)
- p := fix.parser
- for k, v := range test.deps {
- err = p.Remember(k, v)
- c.Assert(err, IsNil, com)
- }
-
- _, _, err = p.ReadObjectTypeAndLength()
- c.Assert(err, IsNil, com)
-
- beforeHash, err := p.Offset()
- c.Assert(err, IsNil, com)
-
- hash, err := p.ReadHash()
- c.Assert(err, IsNil, com)
- c.Assert(hash, Equals, test.expHash, com)
-
- err = fix.seek(beforeHash)
- c.Assert(err, IsNil, com)
-
- obj := &core.MemoryObject{}
- err = p.FillREFDeltaObjectContent(obj)
- c.Assert(err, IsNil, com)
- c.Assert(obj.Type(), Equals, test.expType, com)
-
- r, _ := obj.Reader()
- bytes, _ := ioutil.ReadAll(r)
- c.Assert(bytes, DeepEquals, test.expContent, com)
-
- p.ForgetAll()
- }
-}
-
-func newObject(t core.ObjectType, c []byte) core.Object {
- o := &core.MemoryObject{}
- o.SetType(t)
- o.SetSize(int64(len(c)))
- o.Write(c)
-
- return o
-}
-
-func (s *ParserSuite) TestReadHeaderBadSignatureError(c *C) {
- data := []byte{
- 0x50, 0x42, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x50,
- }
- p := NewParser(NewSeekable(bytes.NewReader(data)))
-
- _, err := p.ReadHeader()
- c.Assert(err, ErrorMatches, ErrBadSignature.Error())
-}
-
-func (s *ParserSuite) TestReadHeaderEmptyPackfileError(c *C) {
- data := []byte{}
- p := NewParser(NewSeekable(bytes.NewReader(data)))
-
- _, err := p.ReadHeader()
- c.Assert(err, ErrorMatches, ErrEmptyPackfile.Error())
-}
-
-func (s *ParserSuite) TestReadHeaderUnsupportedVersionError(c *C) {
- data := []byte{
- 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x50,
- }
- p := NewParser(NewSeekable(bytes.NewReader(data)))
-
- _, err := p.ReadHeader()
- c.Assert(err, ErrorMatches, ErrUnsupportedVersion.Error()+".*")
-}
-
-func (s *ParserSuite) TestReadHeader(c *C) {
- data := []byte{
- 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x50,
- }
- p := NewParser(NewSeekable(bytes.NewReader(data)))
-
- count, err := p.ReadHeader()
+ n, err := p.Checksum()
c.Assert(err, IsNil)
- c.Assert(count, Equals, uint32(0x50))
+ c.Assert(n, Equals, f.PackfileHash)
+}
+
+var expectedHeadersOFS = []ObjectHeader{
+ {Type: core.CommitObject, Offset: 12, Length: 254},
+ {Type: core.OFSDeltaObject, Offset: 186, Length: 93, OffsetReference: 12},
+ {Type: core.CommitObject, Offset: 286, Length: 242},
+ {Type: core.CommitObject, Offset: 449, Length: 242},
+ {Type: core.CommitObject, Offset: 615, Length: 333},
+ {Type: core.CommitObject, Offset: 838, Length: 332},
+ {Type: core.CommitObject, Offset: 1063, Length: 244},
+ {Type: core.CommitObject, Offset: 1230, Length: 243},
+ {Type: core.CommitObject, Offset: 1392, Length: 187},
+ {Type: core.BlobObject, Offset: 1524, Length: 189},
+ {Type: core.BlobObject, Offset: 1685, Length: 18},
+ {Type: core.BlobObject, Offset: 1713, Length: 1072},
+ {Type: core.BlobObject, Offset: 2351, Length: 76110},
+ {Type: core.BlobObject, Offset: 78050, Length: 2780},
+ {Type: core.BlobObject, Offset: 78882, Length: 217848},
+ {Type: core.BlobObject, Offset: 80725, Length: 706},
+ {Type: core.BlobObject, Offset: 80998, Length: 11488},
+ {Type: core.BlobObject, Offset: 84032, Length: 78},
+ {Type: core.TreeObject, Offset: 84115, Length: 272},
+ {Type: core.OFSDeltaObject, Offset: 84375, Length: 43, OffsetReference: 84115},
+ {Type: core.TreeObject, Offset: 84430, Length: 38},
+ {Type: core.TreeObject, Offset: 84479, Length: 75},
+ {Type: core.TreeObject, Offset: 84559, Length: 38},
+ {Type: core.TreeObject, Offset: 84608, Length: 34},
+ {Type: core.BlobObject, Offset: 84653, Length: 9},
+ {Type: core.OFSDeltaObject, Offset: 84671, Length: 6, OffsetReference: 84375},
+ {Type: core.OFSDeltaObject, Offset: 84688, Length: 9, OffsetReference: 84375},
+ {Type: core.OFSDeltaObject, Offset: 84708, Length: 6, OffsetReference: 84375},
+ {Type: core.OFSDeltaObject, Offset: 84725, Length: 5, OffsetReference: 84115},
+ {Type: core.OFSDeltaObject, Offset: 84741, Length: 8, OffsetReference: 84375},
+ {Type: core.OFSDeltaObject, Offset: 84760, Length: 4, OffsetReference: 84741},
+}
+
+var expectedHeadersREF = []ObjectHeader{
+ {Type: core.CommitObject, Offset: 12, Length: 254},
+ {Type: core.REFDeltaObject, Offset: 186, Length: 93,
+ Reference: core.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")},
+ {Type: core.CommitObject, Offset: 304, Length: 242},
+ {Type: core.CommitObject, Offset: 467, Length: 242},
+ {Type: core.CommitObject, Offset: 633, Length: 333},
+ {Type: core.CommitObject, Offset: 856, Length: 332},
+ {Type: core.CommitObject, Offset: 1081, Length: 243},
+ {Type: core.CommitObject, Offset: 1243, Length: 244},
+ {Type: core.CommitObject, Offset: 1410, Length: 187},
+ {Type: core.BlobObject, Offset: 1542, Length: 189},
+ {Type: core.BlobObject, Offset: 1703, Length: 18},
+ {Type: core.BlobObject, Offset: 1731, Length: 1072},
+ {Type: core.BlobObject, Offset: 2369, Length: 76110},
+ {Type: core.TreeObject, Offset: 78068, Length: 38},
+ {Type: core.BlobObject, Offset: 78117, Length: 2780},
+ {Type: core.TreeObject, Offset: 79049, Length: 75},
+ {Type: core.BlobObject, Offset: 79129, Length: 217848},
+ {Type: core.BlobObject, Offset: 80972, Length: 706},
+ {Type: core.TreeObject, Offset: 81265, Length: 38},
+ {Type: core.BlobObject, Offset: 81314, Length: 11488},
+ {Type: core.TreeObject, Offset: 84752, Length: 34},
+ {Type: core.BlobObject, Offset: 84797, Length: 78},
+ {Type: core.TreeObject, Offset: 84880, Length: 271},
+ {Type: core.REFDeltaObject, Offset: 85141, Length: 6,
+ Reference: core.NewHash("a8d315b2b1c615d43042c3a62402b8a54288cf5c")},
+ {Type: core.REFDeltaObject, Offset: 85176, Length: 37,
+ Reference: core.NewHash("fb72698cab7617ac416264415f13224dfd7a165e")},
+ {Type: core.BlobObject, Offset: 85244, Length: 9},
+ {Type: core.REFDeltaObject, Offset: 85262, Length: 9,
+ Reference: core.NewHash("fb72698cab7617ac416264415f13224dfd7a165e")},
+ {Type: core.REFDeltaObject, Offset: 85300, Length: 6,
+ Reference: core.NewHash("fb72698cab7617ac416264415f13224dfd7a165e")},
+ {Type: core.TreeObject, Offset: 85335, Length: 110},
+ {Type: core.REFDeltaObject, Offset: 85448, Length: 8,
+ Reference: core.NewHash("eba74343e2f15d62adedfd8c883ee0262b5c8021")},
+ {Type: core.TreeObject, Offset: 85485, Length: 73},
}
-*/