aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-08-09 16:53:00 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-08-09 16:53:00 +0200
commit56c5e91b158bc4569b38bfd5d27d4b4be5e06a27 (patch)
treecb79fa3334edefbc0165aee8067cba0f9086e6e8 /storage/filesystem
parentd93b3869f366df7488286614b0205968bc6263df (diff)
downloadgo-git-56c5e91b158bc4569b38bfd5d27d4b4be5e06a27.tar.gz
plumbing: packfile, open and close packfile on FSObject reads
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/dotgit/dotgit.go5
-rw-r--r--storage/filesystem/object.go15
-rw-r--r--storage/filesystem/object_test.go40
3 files changed, 48 insertions, 12 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index dc12f23..af07eb5 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -784,6 +784,11 @@ func (d *DotGit) Alternates() ([]*DotGit, error) {
return alternates, nil
}
+// Fs returns the underlying filesystem of the DotGit folder.
+func (d *DotGit) Fs() billy.Filesystem {
+ return d.fs
+}
+
func isHex(s string) bool {
for _, b := range []byte(s) {
if isNum(b) {
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 86d0da9..6958e32 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -295,12 +295,7 @@ func (s *ObjectStorage) decodeObjectAt(
return nil, err
}
- obj, err := packfile.NewPackfile(idx, f).GetByOffset(offset)
- if err != nil {
- return nil, err
- }
-
- return packfile.MemoryObjectFromDisk(obj)
+ return packfile.NewPackfile(idx, s.dir.Fs(), f).GetByOffset(offset)
}
func (s *ObjectStorage) decodeDeltaObjectAt(
@@ -404,7 +399,7 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb
if err != nil {
return nil, err
}
- return newPackfileIter(pack, t, seen, s.index[h], s.deltaBaseCache)
+ return newPackfileIter(s.dir.Fs(), pack, t, seen, s.index[h], s.deltaBaseCache)
},
}, nil
}
@@ -466,6 +461,7 @@ type packfileIter struct {
// and object type. Packfile and index file will be closed after they're
// used.
func NewPackfileIter(
+ fs billy.Filesystem,
f billy.File,
idxFile billy.File,
t plumbing.ObjectType,
@@ -479,17 +475,18 @@ func NewPackfileIter(
return nil, err
}
- return newPackfileIter(f, t, make(map[plumbing.Hash]struct{}), idx, nil)
+ return newPackfileIter(fs, f, t, make(map[plumbing.Hash]struct{}), idx, nil)
}
func newPackfileIter(
+ fs billy.Filesystem,
f billy.File,
t plumbing.ObjectType,
seen map[plumbing.Hash]struct{},
index idxfile.Index,
cache cache.Object,
) (storer.EncodedObjectIter, error) {
- iter, err := packfile.NewPackfile(index, f).GetByType(t)
+ iter, err := packfile.NewPackfile(index, fs, f).GetByType(t)
if err != nil {
return nil, err
}
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index 88f22bf..b1408b7 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -121,7 +121,7 @@ func (s *FsSuite) TestPackfileIter(c *C) {
idxf, err := dg.ObjectPackIdx(h)
c.Assert(err, IsNil)
- iter, err := NewPackfileIter(f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t)
c.Assert(err, IsNil)
err = iter.ForEach(func(o plumbing.EncodedObject) error {
c.Assert(o.Type(), Equals, t)
@@ -169,7 +169,7 @@ func BenchmarkPackfileIter(b *testing.B) {
b.Fatal(err)
}
- iter, err := NewPackfileIter(f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t)
if err != nil {
b.Fatal(err)
}
@@ -225,7 +225,7 @@ func BenchmarkPackfileIterReadContent(b *testing.B) {
b.Fatal(err)
}
- iter, err := NewPackfileIter(f, idxf, t)
+ iter, err := NewPackfileIter(fs, f, idxf, t)
if err != nil {
b.Fatal(err)
}
@@ -256,3 +256,37 @@ func BenchmarkPackfileIterReadContent(b *testing.B) {
})
}
}
+
+func BenchmarkGetObjectFromPackfile(b *testing.B) {
+ if err := fixtures.Init(); err != nil {
+ b.Fatal(err)
+ }
+
+ defer func() {
+ if err := fixtures.Clean(); err != nil {
+ b.Fatal(err)
+ }
+ }()
+
+ for _, f := range fixtures.Basic() {
+ b.Run(f.URL, func(b *testing.B) {
+ fs := f.DotGit()
+ o, err := NewObjectStorage(dotgit.New(fs))
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ for i := 0; i < b.N; i++ {
+ expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
+ obj, err := o.EncodedObject(plumbing.AnyObject, expected)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ if obj.Hash() != expected {
+ b.Errorf("expecting %s, got %s", expected, obj.Hash())
+ }
+ }
+ })
+ }
+}