diff options
Diffstat (limited to 'storage/filesystem')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 13 | ||||
-rw-r--r-- | storage/filesystem/object.go | 15 | ||||
-rw-r--r-- | storage/filesystem/object_test.go | 20 |
3 files changed, 36 insertions, 12 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index e22ed58..cacda68 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -236,6 +236,7 @@ type PackWriter struct { checksum core.Hash index idxfile.Idxfile result chan error + Notify func(h core.Hash, i idxfile.Idxfile) } func newPackWrite(fs fs.Filesystem) (*PackWriter, error) { @@ -265,7 +266,7 @@ func newPackWrite(fs fs.Filesystem) (*PackWriter, error) { func (w *PackWriter) buildIndex() { defer w.sr.Close() o := memory.NewStorage().ObjectStorage() - s := packfile.NewScannerFromReader(w.sr) + s := packfile.NewScanner(w.sr) d := packfile.NewDecoder(s, o) checksum, err := d.Decode() @@ -307,7 +308,15 @@ func (w *PackWriter) Close() error { return err } - return w.save() + if err := w.save(); err != nil { + return err + } + + if w.Notify != nil { + w.Notify(w.checksum, w.index) + } + + return nil } func (w *PackWriter) save() error { diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 0b82524..dc21d0b 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -67,7 +67,19 @@ func (s *ObjectStorage) NewObject() core.Object { // Writer method not supported on Memory storage func (s *ObjectStorage) Writer() (io.WriteCloser, error) { - return s.dir.NewObjectPack() + w, err := s.dir.NewObjectPack() + if err != nil { + return nil, err + } + + w.Notify = func(h core.Hash, idx idxfile.Idxfile) { + s.index[h] = make(index) + for _, e := range idx.Entries { + s.index[h][e.Hash] = int64(e.Offset) + } + } + + return w, nil } // Set adds a new object to the storage. As this functionality is not @@ -150,6 +162,7 @@ func (s *ObjectStorage) getFromPackfile(h core.Hash) (core.Object, error) { p := packfile.NewScanner(f) d := packfile.NewDecoder(p, memory.NewStorage().ObjectStorage()) + d.SetOffsets(s.index[pack]) return d.ReadObjectAt(offset) } diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index 14c77e4..07fa646 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -17,7 +17,7 @@ func (s *FsSuite) SetUpSuite(c *C) { } func (s *FsSuite) TestGetFromObjectFile(c *C) { - fs := fixtures.ByTag(".git").ByTag("unpacked").DotGit() + fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() o, err := newObjectStorage(dotgit.New(fs)) c.Assert(err, IsNil) @@ -28,18 +28,20 @@ func (s *FsSuite) TestGetFromObjectFile(c *C) { } func (s *FsSuite) TestGetFromPackfile(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() - o, err := newObjectStorage(dotgit.New(fs)) - c.Assert(err, IsNil) + fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) { + fs := f.DotGit() + o, err := newObjectStorage(dotgit.New(fs)) + c.Assert(err, IsNil) - expected := core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5") - obj, err := o.Get(core.AnyObject, expected) - c.Assert(err, IsNil) - c.Assert(obj.Hash(), Equals, expected) + expected := core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + obj, err := o.Get(core.AnyObject, expected) + c.Assert(err, IsNil) + c.Assert(obj.Hash(), Equals, expected) + }) } func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) { - fs := fixtures.ByTag(".git").ByTag("multi-packfile").DotGit() + fs := fixtures.ByTag(".git").ByTag("multi-packfile").One().DotGit() o, err := newObjectStorage(dotgit.New(fs)) c.Assert(err, IsNil) |