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). --- storage/test/storage_suite.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'storage/test') diff --git a/storage/test/storage_suite.go b/storage/test/storage_suite.go index 7cb0fe3..624dc57 100644 --- a/storage/test/storage_suite.go +++ b/storage/test/storage_suite.go @@ -403,6 +403,40 @@ func (s *BaseStorageSuite) TestModule(c *C) { c.Assert(storer, NotNil) } +func (s *BaseStorageSuite) TestDeltaObjectStorer(c *C) { + dos, ok := s.Storer.(storer.DeltaObjectStorer) + if !ok { + c.Skip("not an DeltaObjectStorer") + } + + pwr, ok := s.Storer.(storer.PackfileWriter) + if !ok { + c.Skip("not a storer.PackWriter") + } + + pw, err := pwr.PackfileWriter() + c.Assert(err, IsNil) + + f := fixtures.Basic().One() + _, err = io.Copy(pw, f.Packfile()) + c.Assert(err, IsNil) + + err = pw.Close() + c.Assert(err, IsNil) + + h := plumbing.NewHash("32858aad3c383ed1ff0a0f9bdf231d54a00c9e88") + obj, err := dos.DeltaObject(plumbing.AnyObject, h) + c.Assert(err, IsNil) + c.Assert(obj.Type(), Equals, plumbing.BlobObject) + + h = plumbing.NewHash("aa9b383c260e1d05fbbf6b30a02914555e20c725") + obj, err = dos.DeltaObject(plumbing.AnyObject, h) + c.Assert(err, IsNil) + c.Assert(obj.Type(), Equals, plumbing.OFSDeltaObject) + _, ok = obj.(plumbing.DeltaObject) + c.Assert(ok, Equals, true) +} + func objectEquals(a plumbing.EncodedObject, b plumbing.EncodedObject) error { ha := a.Hash() hb := b.Hash() -- cgit