diff options
author | Antonio Navarro Perez <antnavper@gmail.com> | 2017-01-12 08:46:32 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-12 08:46:32 +0100 |
commit | f9c7c8c2158140d75d4d5a2fa925fc35ad77be9b (patch) | |
tree | f0878e352cfa3f48cea2981b0202dbb494baada4 /storage/filesystem/object_test.go | |
parent | 65d23b4620a76418dc4aeca83ce7a991a1945ef0 (diff) | |
download | go-git-f9c7c8c2158140d75d4d5a2fa925fc35ad77be9b.tar.gz |
packfile/decoder: speed up packfile iterator when specific type (#200)
Diffstat (limited to 'storage/filesystem/object_test.go')
-rw-r--r-- | storage/filesystem/object_test.go | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index a3a5e68..6841ac4 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -10,9 +10,17 @@ import ( type FsSuite struct { fixtures.Suite + Types []plumbing.ObjectType } -var _ = Suite(&FsSuite{}) +var _ = Suite(&FsSuite{ + Types: []plumbing.ObjectType{ + plumbing.CommitObject, + plumbing.TagObject, + plumbing.TreeObject, + plumbing.BlobObject, + }, +}) func (s *FsSuite) TestGetFromObjectFile(c *C) { fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() @@ -76,18 +84,47 @@ func (s *FsSuite) TestIter(c *C) { func (s *FsSuite) TestIterWithType(c *C) { fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) { - fs := f.DotGit() - o, err := newObjectStorage(dotgit.New(fs)) - c.Assert(err, IsNil) + for _, t := range s.Types { + fs := f.DotGit() + o, err := newObjectStorage(dotgit.New(fs)) + c.Assert(err, IsNil) - iter, err := o.IterEncodedObjects(plumbing.CommitObject) - c.Assert(err, IsNil) + iter, err := o.IterEncodedObjects(t) + c.Assert(err, IsNil) - err = iter.ForEach(func(o plumbing.EncodedObject) error { - c.Assert(o.Type(), Equals, plumbing.CommitObject) - return nil - }) + err = iter.ForEach(func(o plumbing.EncodedObject) error { + c.Assert(o.Type(), Equals, t) + return nil + }) + + c.Assert(err, IsNil) + } - c.Assert(err, IsNil) }) } + +func (s *FsSuite) TestPackfileIter(c *C) { + fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) { + fs := f.DotGit() + dg := dotgit.New(fs) + + for _, t := range s.Types { + ph, err := dg.ObjectPacks() + c.Assert(err, IsNil) + + for _, h := range ph { + f, err := dg.ObjectPack(h) + c.Assert(err, IsNil) + iter, err := NewPackfileIter(f, t) + c.Assert(err, IsNil) + err = iter.ForEach(func(o plumbing.EncodedObject) error { + c.Assert(o.Type(), Equals, t) + return nil + }) + + c.Assert(err, IsNil) + } + } + }) + +} |