diff options
author | Antonio Navarro Perez <antnavper@gmail.com> | 2016-12-16 19:30:36 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-16 19:30:36 +0100 |
commit | 950676c36030a8796c0a69a8aae606ff1f448b03 (patch) | |
tree | 8edfd1baa31e83a396d263c2d0fed1a4d09a83dc /plumbing/format/packfile/encoder_test.go | |
parent | c49d8e374443180ff68404c904ccad5d87f9073e (diff) | |
download | go-git-950676c36030a8796c0a69a8aae606ff1f448b03.tar.gz |
packfile: delta selection logic (#182)
* packfile: delta selection logic
- Implemented logic to assign deltas to objects
* Requested changes
* Improved tests and fix errors
Diffstat (limited to 'plumbing/format/packfile/encoder_test.go')
-rw-r--r-- | plumbing/format/packfile/encoder_test.go | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go index 1a94d16..dde8570 100644 --- a/plumbing/format/packfile/encoder_test.go +++ b/plumbing/format/packfile/encoder_test.go @@ -22,7 +22,7 @@ var _ = Suite(&EncoderSuite{}) func (s *EncoderSuite) SetUpTest(c *C) { s.buf = bytes.NewBuffer(nil) s.store = memory.NewStorage() - s.enc = NewEncoder(s.buf, s.store) + s.enc = NewEncoder(s.buf, s.store, false) } func (s *EncoderSuite) TestCorrectPackHeader(c *C) { @@ -149,26 +149,30 @@ func (s *EncoderSuite) TestDecodeEncodeDecode(c *C) { } func (s *EncoderSuite) TestDecodeEncodeWithDeltaDecodeREF(c *C) { - s.simpleDeltaTest(c, plumbing.REFDeltaObject) + s.enc = NewEncoder(s.buf, s.store, true) + s.simpleDeltaTest(c) } func (s *EncoderSuite) TestDecodeEncodeWithDeltaDecodeOFS(c *C) { - s.simpleDeltaTest(c, plumbing.OFSDeltaObject) + s.enc = NewEncoder(s.buf, s.store, false) + s.simpleDeltaTest(c) } func (s *EncoderSuite) TestDecodeEncodeWithDeltasDecodeREF(c *C) { - s.deltaOverDeltaTest(c, plumbing.REFDeltaObject) + s.enc = NewEncoder(s.buf, s.store, true) + s.deltaOverDeltaTest(c) } func (s *EncoderSuite) TestDecodeEncodeWithDeltasDecodeOFS(c *C) { - s.deltaOverDeltaTest(c, plumbing.OFSDeltaObject) + s.enc = NewEncoder(s.buf, s.store, false) + s.deltaOverDeltaTest(c) } -func (s *EncoderSuite) simpleDeltaTest(c *C, t plumbing.ObjectType) { +func (s *EncoderSuite) simpleDeltaTest(c *C) { srcObject := newObject(plumbing.BlobObject, []byte("0")) targetObject := newObject(plumbing.BlobObject, []byte("01")) - deltaObject, err := delta(srcObject, targetObject, t) + deltaObject, err := GetDelta(srcObject, targetObject) c.Assert(err, IsNil) srcToPack := newObjectToPack(srcObject) @@ -196,16 +200,16 @@ func (s *EncoderSuite) simpleDeltaTest(c *C, t plumbing.ObjectType) { c.Assert(decTarget, DeepEquals, targetObject) } -func (s *EncoderSuite) deltaOverDeltaTest(c *C, t plumbing.ObjectType) { +func (s *EncoderSuite) deltaOverDeltaTest(c *C) { srcObject := newObject(plumbing.BlobObject, []byte("0")) targetObject := newObject(plumbing.BlobObject, []byte("01")) otherTargetObject := newObject(plumbing.BlobObject, []byte("011111")) - deltaObject, err := delta(srcObject, targetObject, t) + deltaObject, err := GetDelta(srcObject, targetObject) c.Assert(err, IsNil) c.Assert(deltaObject.Hash(), Not(Equals), plumbing.ZeroHash) - otherDeltaObject, err := delta(targetObject, otherTargetObject, t) + otherDeltaObject, err := GetDelta(targetObject, otherTargetObject) c.Assert(err, IsNil) c.Assert(otherDeltaObject.Hash(), Not(Equals), plumbing.ZeroHash) @@ -238,23 +242,3 @@ func (s *EncoderSuite) deltaOverDeltaTest(c *C, t plumbing.ObjectType) { c.Assert(err, IsNil) c.Assert(decOtherTarget, DeepEquals, otherTargetObject) } - -func delta(base, target plumbing.EncodedObject, t plumbing.ObjectType) (plumbing.EncodedObject, error) { - switch t { - case plumbing.OFSDeltaObject: - return GetOFSDelta(base, target) - case plumbing.REFDeltaObject: - return GetRefDelta(base, target) - default: - panic("delta type not found") - } -} - -func newObject(t plumbing.ObjectType, cont []byte) plumbing.EncodedObject { - o := plumbing.MemoryObject{} - o.SetType(t) - o.SetSize(int64(len(cont))) - o.Write(cont) - - return &o -} |