diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-09-08 17:51:38 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-09-09 12:00:17 -0700 |
commit | 841b62a321b3739381b48aeea7364126d1c54520 (patch) | |
tree | 6d09c53325a7c31e15aa794631ec41c0b36b038c /plumbing/object/commit_walker_test.go | |
parent | bb3217ce5d5ed682a5c830c40ea031d3c92a8a7e (diff) | |
download | go-git-841b62a321b3739381b48aeea7364126d1c54520.tar.gz |
plumbing: the commit walker can skip externally-seen commits
When the revlist is computing the set of hashes needed to transfer, it
doesn't need to walk over commits it has already processed. So, it
can instruct the commit walker not to walk those commits by passing in
its own `seen` map.
For a 36K object repo, this brought the time for `revlist.Objects`
down from 50s to 30s.
Diffstat (limited to 'plumbing/object/commit_walker_test.go')
-rw-r--r-- | plumbing/object/commit_walker_test.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/plumbing/object/commit_walker_test.go b/plumbing/object/commit_walker_test.go index 48b504d..a27104e 100644 --- a/plumbing/object/commit_walker_test.go +++ b/plumbing/object/commit_walker_test.go @@ -16,7 +16,7 @@ func (s *CommitWalkerSuite) TestCommitPreIterator(c *C) { commit := s.commit(c, s.Fixture.Head) var commits []*Commit - NewCommitPreorderIter(commit, nil).ForEach(func(c *Commit) error { + NewCommitPreorderIter(commit, nil, nil).ForEach(func(c *Commit) error { commits = append(commits, c) return nil }) @@ -42,7 +42,7 @@ func (s *CommitWalkerSuite) TestCommitPreIteratorWithIgnore(c *C) { commit := s.commit(c, s.Fixture.Head) var commits []*Commit - NewCommitPreorderIter(commit, []plumbing.Hash{ + NewCommitPreorderIter(commit, nil, []plumbing.Hash{ plumbing.NewHash("af2d6a6954d532f8ffb47615169c8fdf9d383a1a"), }).ForEach(func(c *Commit) error { commits = append(commits, c) @@ -60,6 +60,30 @@ func (s *CommitWalkerSuite) TestCommitPreIteratorWithIgnore(c *C) { } } +func (s *CommitWalkerSuite) TestCommitPreIteratorWithSeenExternal(c *C) { + commit := s.commit(c, s.Fixture.Head) + + var commits []*Commit + seenExternal := map[plumbing.Hash]bool{ + plumbing.NewHash("af2d6a6954d532f8ffb47615169c8fdf9d383a1a"): true, + } + NewCommitPreorderIter(commit, seenExternal, nil). + ForEach(func(c *Commit) error { + commits = append(commits, c) + return nil + }) + + c.Assert(commits, HasLen, 2) + + expected := []string{ + "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", + "918c48b83bd081e863dbe1b80f8998f058cd8294", + } + for i, commit := range commits { + c.Assert(commit.Hash.String(), Equals, expected[i]) + } +} + func (s *CommitWalkerSuite) TestCommitPostIterator(c *C) { commit := s.commit(c, s.Fixture.Head) |