diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-12 12:49:46 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-12 12:49:46 +0200 |
commit | e1f7b169aaa99d07fe8ad8e71a0cba2322e7d35f (patch) | |
tree | 50f195024fa492120db0c9822111cc84b0c659ce /formats/packfile | |
parent | 8948d4b48acfc39462f0c75525bc6b53c1ac59b2 (diff) | |
download | go-git-e1f7b169aaa99d07fe8ad8e71a0cba2322e7d35f.tar.gz |
small improvements
Diffstat (limited to 'formats/packfile')
-rw-r--r-- | formats/packfile/parser.go | 22 | ||||
-rw-r--r-- | formats/packfile/parser_test.go | 17 |
2 files changed, 22 insertions, 17 deletions
diff --git a/formats/packfile/parser.go b/formats/packfile/parser.go index 8b7a692..2930dcb 100644 --- a/formats/packfile/parser.go +++ b/formats/packfile/parser.go @@ -172,7 +172,7 @@ func moreBytesInLength(c byte) bool { return c&maskContinue > 0 } -// ReadObject reads and returns a git object from an object entry in the packfile. +// FillObject fills the given object from an object entry in the packfile. // Non-deltified and deltified objects are supported. func (p Parser) FillObject(obj core.Object) error { start, err := p.Offset() @@ -190,11 +190,11 @@ func (p Parser) FillObject(obj core.Object) error { switch t { case core.CommitObject, core.TreeObject, core.BlobObject, core.TagObject: obj.SetType(t) - err = p.ReadNonDeltaObjectContent(obj) + err = p.FillFromNonDeltaContent(obj) case core.REFDeltaObject: - err = p.ReadREFDeltaObjectContent(obj) + err = p.FillREFDeltaObjectContent(obj) case core.OFSDeltaObject: - err = p.ReadOFSDeltaObjectContent(obj, start) + err = p.FillOFSDeltaObjectContent(obj, start) default: err = ErrInvalidObject.AddDetails("tag %q", t) } @@ -202,9 +202,9 @@ func (p Parser) FillObject(obj core.Object) error { return err } -// ReadNonDeltaObjectContent reads and returns a non-deltified object +// FillFromNonDeltaContent reads and fill a non-deltified object // from it zlib stream in an object entry in the packfile. -func (p Parser) ReadNonDeltaObjectContent(obj core.Object) error { +func (p Parser) FillFromNonDeltaContent(obj core.Object) error { w, err := obj.Writer() if err != nil { return err @@ -233,9 +233,9 @@ func (p Parser) inflate(w io.Writer) (err error) { return err } -// ReadREFDeltaObjectContent reads and returns an object specified by a +// FillREFDeltaObjectContent reads and returns an object specified by a // REF-Delta entry in the packfile, form the hash onwards. -func (p Parser) ReadREFDeltaObjectContent(obj core.Object) error { +func (p Parser) FillREFDeltaObjectContent(obj core.Object) error { refHash, err := p.ReadHash() if err != nil { return err @@ -264,7 +264,7 @@ func (p Parser) ReadHash() (core.Hash, error) { return h, nil } -// ReadAndSolveDelta reads and returns the base patched with the contents +// ReadAndApplyDelta reads and apply the base patched with the contents // of a zlib compressed diff data in the delta portion of an object // entry in the packfile. func (p Parser) ReadAndApplyDelta(target, base core.Object) error { @@ -276,11 +276,11 @@ func (p Parser) ReadAndApplyDelta(target, base core.Object) error { return ApplyDelta(target, base, buf.Bytes()) } -// ReadOFSDeltaObjectContent reads an returns an object specified by an +// FillOFSDeltaObjectContent reads an fill an object specified by an // OFS-delta entry in the packfile from it negative offset onwards. The // start parameter is the offset of this particular object entry (the // current offset minus the already processed type and length). -func (p Parser) ReadOFSDeltaObjectContent(obj core.Object, start int64) error { +func (p Parser) FillOFSDeltaObjectContent(obj core.Object, start int64) error { jump, err := p.ReadNegativeOffset() if err != nil { diff --git a/formats/packfile/parser_test.go b/formats/packfile/parser_test.go index c2b99f1..5d41d69 100644 --- a/formats/packfile/parser_test.go +++ b/formats/packfile/parser_test.go @@ -238,13 +238,13 @@ func (s *ParserSuite) TestReadNonDeltaObjectContent(c *C) { c.Assert(err, IsNil, com) obj := &core.MemoryObject{} - err = p.ReadNonDeltaObjectContent(obj) + err = p.FillFromNonDeltaContent(obj) c.Assert(err, IsNil, com) c.Assert(obj.Content(), DeepEquals, test.expected, com) } } -func (s *ParserSuite) TestReadOFSDeltaObjectContent(c *C) { +func (s *ParserSuite) TestFillOFSDeltaObjectContent(c *C) { for i, test := range [...]struct { fixID string offset int64 @@ -294,14 +294,14 @@ func (s *ParserSuite) TestReadOFSDeltaObjectContent(c *C) { c.Assert(err, IsNil, com) obj := &core.MemoryObject{} - err = p.ReadOFSDeltaObjectContent(obj, test.offset) + err = p.FillOFSDeltaObjectContent(obj, test.offset) c.Assert(err, IsNil, com) c.Assert(obj.Type(), Equals, test.expType, com) c.Assert(obj.Content(), DeepEquals, test.expContent, com) } } -func (s *ParserSuite) TestReadREFDeltaObjectContent(c *C) { +func (s *ParserSuite) TestFillREFDeltaObjectContent(c *C) { for i, test := range [...]struct { fixID string offset int64 @@ -358,7 +358,7 @@ func (s *ParserSuite) TestReadREFDeltaObjectContent(c *C) { c.Assert(err, IsNil, com) obj := &core.MemoryObject{} - err = p.ReadREFDeltaObjectContent(obj) + err = p.FillREFDeltaObjectContent(obj) c.Assert(err, IsNil, com) c.Assert(obj.Type(), Equals, test.expType, com) c.Assert(obj.Content(), DeepEquals, test.expContent, com) @@ -368,7 +368,12 @@ func (s *ParserSuite) TestReadREFDeltaObjectContent(c *C) { } func newObject(t core.ObjectType, c []byte) core.Object { - return core.NewMemoryObject(t, int64(len(c)), c) + o := &core.MemoryObject{} + o.SetType(t) + o.SetSize(int64(len(c))) + o.Write(c) + + return o } func (s *ParserSuite) TestReadHeaderBadSignatureError(c *C) { |