From 87413ced43b02a41359ce7a1a07ab41aec6ee313 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Tue, 25 Jul 2017 15:00:01 +0200 Subject: storage: reuse deltas from packfiles * plumbing: add DeltaObject interface for EncodedObjects that are deltas and hold additional information about them, such as the hash of the base object. * plumbing/storer: add DeltaObjectStorer interface for object storers that can return DeltaObject. Note that calls to EncodedObject will never return instances of DeltaObject. That requires explicit calls to DeltaObject. * storage/filesystem: implement DeltaObjectStorer interface. * plumbing/packfile: packfile encoder now supports reusing deltas that are already computed (e.g. from an existing packfile) if the storage implements DeltaObjectStorer. Reusing deltas boosts performance of packfile generation (e.g. on push). --- plumbing/format/packfile/encoder_test.go | 76 -------------------------------- 1 file changed, 76 deletions(-) (limited to 'plumbing/format/packfile/encoder_test.go') diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go index 551d7ec..b5b0c42 100644 --- a/plumbing/format/packfile/encoder_test.go +++ b/plumbing/format/packfile/encoder_test.go @@ -2,11 +2,9 @@ package packfile import ( "bytes" - "io" "github.com/src-d/go-git-fixtures" "gopkg.in/src-d/go-git.v4/plumbing" - "gopkg.in/src-d/go-git.v4/plumbing/storer" "gopkg.in/src-d/go-git.v4/storage/memory" . "gopkg.in/check.v1" @@ -88,80 +86,6 @@ func (s *EncoderSuite) TestHashNotFound(c *C) { c.Assert(err, Equals, plumbing.ErrObjectNotFound) } -func (s *EncoderSuite) TestDecodeEncodeDecode(c *C) { - fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) { - pf := f.Packfile() - ph := f.PackfileHash - storage := memory.NewStorage() - s.testDecodeEncodeDecode(c, pf, ph, storage) - }) -} - -func (s *EncoderSuite) testDecodeEncodeDecode(c *C, - pf io.ReadCloser, - ph plumbing.Hash, - storage storer.Storer) { - - defer func() { - c.Assert(pf.Close(), IsNil) - }() - - scanner := NewScanner(pf) - - d, err := NewDecoder(scanner, storage) - c.Assert(err, IsNil) - - ch, err := d.Decode() - c.Assert(err, IsNil) - c.Assert(ch, Equals, ph) - - objIter, err := storage.IterEncodedObjects(plumbing.AnyObject) - c.Assert(err, IsNil) - - expectedObjects := map[plumbing.Hash]bool{} - var hashes []plumbing.Hash - err = objIter.ForEach(func(o plumbing.EncodedObject) error { - expectedObjects[o.Hash()] = true - hashes = append(hashes, o.Hash()) - return err - - }) - c.Assert(err, IsNil) - - enc := NewEncoder(s.buf, storage, false) - _, err = enc.Encode(hashes) - c.Assert(err, IsNil) - - scanner = NewScanner(s.buf) - storage = memory.NewStorage() - d, err = NewDecoder(scanner, storage) - c.Assert(err, IsNil) - _, err = d.Decode() - c.Assert(err, IsNil) - - objIter, err = storage.IterEncodedObjects(plumbing.AnyObject) - c.Assert(err, IsNil) - obtainedObjects := map[plumbing.Hash]bool{} - err = objIter.ForEach(func(o plumbing.EncodedObject) error { - obtainedObjects[o.Hash()] = true - return nil - }) - c.Assert(err, IsNil) - c.Assert(obtainedObjects, DeepEquals, expectedObjects) - - for h := range obtainedObjects { - if !expectedObjects[h] { - c.Errorf("obtained unexpected object: %s", h) - } - } - - for h := range expectedObjects { - if !obtainedObjects[h] { - c.Errorf("missing object: %s", h) - } - } -} - func (s *EncoderSuite) TestDecodeEncodeWithDeltaDecodeREF(c *C) { s.enc = NewEncoder(s.buf, s.store, true) s.simpleDeltaTest(c) -- cgit