aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commitnode_test.go
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-04-23 19:11:43 +0200
committerFilip Navara <filip.navara@gmail.com>2019-04-24 10:48:45 +0200
commitec65d90feaf3172a8bd1bf51bb85e7bdaaf28a54 (patch)
treef14412df58fb713e2b9698ebe2408ce4dfa82c40 /plumbing/object/commitnode_test.go
parent4a6229296f5d8991d46e581d331e4e889a5a87ec (diff)
downloadgo-git-ec65d90feaf3172a8bd1bf51bb85e7bdaaf28a54.tar.gz
plumbing: object, add APIs for traversing over commit graphs
Signed-off-by: Filip Navara <filip.navara@gmail.com>
Diffstat (limited to 'plumbing/object/commitnode_test.go')
-rw-r--r--plumbing/object/commitnode_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/plumbing/object/commitnode_test.go b/plumbing/object/commitnode_test.go
new file mode 100644
index 0000000..8f59665
--- /dev/null
+++ b/plumbing/object/commitnode_test.go
@@ -0,0 +1,81 @@
+package object
+
+import (
+ "path"
+
+ "golang.org/x/exp/mmap"
+ . "gopkg.in/check.v1"
+ "gopkg.in/src-d/go-git-fixtures.v3"
+ "gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/cache"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/commitgraph"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
+)
+
+type CommitNodeSuite struct {
+ fixtures.Suite
+}
+
+var _ = Suite(&CommitNodeSuite{})
+
+func testWalker(c *C, nodeIndex CommitNodeIndex) {
+ head, err := nodeIndex.Get(plumbing.NewHash("b9d69064b190e7aedccf84731ca1d917871f8a1c"))
+ c.Assert(err, IsNil)
+
+ iter := NewCommitNodeIterCTime(
+ head,
+ nodeIndex,
+ nil,
+ nil,
+ )
+
+ var commits []CommitNode
+ iter.ForEach(func(c CommitNode) error {
+ commits = append(commits, c)
+ return nil
+ })
+
+ c.Assert(commits, HasLen, 9)
+
+ expected := []string{
+ "b9d69064b190e7aedccf84731ca1d917871f8a1c",
+ "6f6c5d2be7852c782be1dd13e36496dd7ad39560",
+ "a45273fe2d63300e1962a9e26a6b15c276cd7082",
+ "c0edf780dd0da6a65a7a49a86032fcf8a0c2d467",
+ "bb13916df33ed23004c3ce9ed3b8487528e655c1",
+ "03d2c021ff68954cf3ef0a36825e194a4b98f981",
+ "ce275064ad67d51e99f026084e20827901a8361c",
+ "e713b52d7e13807e87a002e812041f248db3f643",
+ "347c91919944a68e9413581a1bc15519550a3afe",
+ }
+ for i, commit := range commits {
+ c.Assert(commit.ID().String(), Equals, expected[i])
+ }
+}
+
+func (s *CommitNodeSuite) TestWalkObject(c *C) {
+ f := fixtures.ByTag("commit-graph").One()
+ storer := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault())
+ p := f.Packfile()
+ defer p.Close()
+ err := packfile.UpdateObjectStorage(storer, p)
+ c.Assert(err, IsNil)
+
+ nodeIndex := NewObjectCommitNodeIndex(storer)
+ testWalker(c, nodeIndex)
+}
+
+func (s *CommitNodeSuite) TestWalkCommitGraph(c *C) {
+ f := fixtures.ByTag("commit-graph").One()
+ dotgit := f.DotGit()
+ storer := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())
+ reader, err := mmap.Open(path.Join(dotgit.Root(), "objects", "info", "commit-graph"))
+ c.Assert(err, IsNil)
+ defer reader.Close()
+ index, err := commitgraph.OpenFileIndex(reader)
+ c.Assert(err, IsNil)
+
+ nodeIndex := NewGraphCommitNodeIndex(index, storer)
+ testWalker(c, nodeIndex)
+}