aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-08-09 12:16:57 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-08-09 12:16:57 +0200
commit34cc506735ee0cd29362da51592b49a217df8159 (patch)
treef81df515e1471ddea1ed0f35e9ac3983ad5460c2
parent71a3c9161d4d8d2baf16440a86a02e8f5678aef2 (diff)
downloadgo-git-34cc506735ee0cd29362da51592b49a217df8159.tar.gz
storage: filesystem, benchmark PackfileIter
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
-rw-r--r--storage/filesystem/object.go30
-rw-r--r--storage/filesystem/object_test.go79
2 files changed, 94 insertions, 15 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 2032eac..4757938 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -509,9 +509,20 @@ func (iter *packfileIter) Next() (plumbing.EncodedObject, error) {
}
}
-// ForEach is never called since is used inside of a MultiObjectIterator
func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error {
- return nil
+ for {
+ o, err := iter.Next()
+ if err != nil {
+ if err == io.EOF {
+ return nil
+ }
+ return err
+ }
+
+ if err := cb(o); err != nil {
+ return err
+ }
+ }
}
func (iter *packfileIter) Close() {
@@ -543,9 +554,20 @@ func (iter *objectsIter) Next() (plumbing.EncodedObject, error) {
return obj, err
}
-// ForEach is never called since is used inside of a MultiObjectIterator
func (iter *objectsIter) ForEach(cb func(plumbing.EncodedObject) error) error {
- return nil
+ for {
+ o, err := iter.Next()
+ if err != nil {
+ if err == io.EOF {
+ return nil
+ }
+ return err
+ }
+
+ if err := cb(o); err != nil {
+ return err
+ }
+ }
}
func (iter *objectsIter) Close() {
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go
index ae11c3b..0dc19fe 100644
--- a/storage/filesystem/object_test.go
+++ b/storage/filesystem/object_test.go
@@ -1,6 +1,8 @@
package filesystem
import (
+ "testing"
+
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
@@ -10,17 +12,16 @@ import (
type FsSuite struct {
fixtures.Suite
- Types []plumbing.ObjectType
}
-var _ = Suite(&FsSuite{
- Types: []plumbing.ObjectType{
- plumbing.CommitObject,
- plumbing.TagObject,
- plumbing.TreeObject,
- plumbing.BlobObject,
- },
-})
+var objectTypes = []plumbing.ObjectType{
+ plumbing.CommitObject,
+ plumbing.TagObject,
+ plumbing.TreeObject,
+ plumbing.BlobObject,
+}
+
+var _ = Suite(&FsSuite{})
func (s *FsSuite) TestGetFromObjectFile(c *C) {
fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
@@ -84,7 +85,7 @@ func (s *FsSuite) TestIter(c *C) {
func (s *FsSuite) TestIterWithType(c *C) {
fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) {
- for _, t := range s.Types {
+ for _, t := range objectTypes {
fs := f.DotGit()
o, err := NewObjectStorage(dotgit.New(fs))
c.Assert(err, IsNil)
@@ -108,7 +109,7 @@ func (s *FsSuite) TestPackfileIter(c *C) {
fs := f.DotGit()
dg := dotgit.New(fs)
- for _, t := range s.Types {
+ for _, t := range objectTypes {
ph, err := dg.ObjectPacks()
c.Assert(err, IsNil)
@@ -132,3 +133,59 @@ func (s *FsSuite) TestPackfileIter(c *C) {
})
}
+
+func BenchmarkPackfileIter(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.ByTag(".git") {
+ b.Run(f.URL, func(b *testing.B) {
+ fs := f.DotGit()
+ dg := dotgit.New(fs)
+
+ for i := 0; i < b.N; i++ {
+ for _, t := range objectTypes {
+ ph, err := dg.ObjectPacks()
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ for _, h := range ph {
+ f, err := dg.ObjectPack(h)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ idxf, err := dg.ObjectPackIdx(h)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ iter, err := NewPackfileIter(f, idxf, t)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ err = iter.ForEach(func(o plumbing.EncodedObject) error {
+ if o.Type() != t {
+ b.Errorf("expecting %s, got %s", t, o.Type())
+ }
+ return nil
+ })
+
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+ }
+ }
+ })
+ }
+}