Make all AbstractTreeIterator implementations bi-directional
commit2923e1357ecb013cacdd23fda025937d7e70e14c
authorShawn O. Pearce <spearce@spearce.org>
Mon, 18 Aug 2008 23:53:18 +0000 (18 16:53 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 20 Aug 2008 21:08:19 +0000 (20 23:08 +0200)
tree8aa34924f59e37efe0a30c719bb0fa961e654938
parente2fc776b081b3c2417db38afcba2e8eeac7f4e21
Make all AbstractTreeIterator implementations bi-directional

To support scanning ahead and then rewinding back to our prior
location we need to allow all tree iterators to be moved both
forward and backwards through their entries. The next(int)
API replaces the simple next() by supplying the amount that
the iterator needs to move forward. A corresponding back(int)
method supplies the opposite direction of travel.

Some iterators, like WorkingTreeIterator, can efficiently move
forward and backward any distance because they have a direct 1:1
mapping between positions of the iterator and an array index.
Others like CanonicalTreeParser must scan through their input
buffer, but can try to reduce the work needed on larger steps
as they move past the undesired entries. DirCacheIterator is
a challenge because it needs to match each entry to the
DirCacheTrees available at this level.

This API (and its implementation) is really meant for peeking at
the next entry (or two) forward to see if there is a name (but
not mode) match during a TreeWalk. This is to help TreeWalk
catch a directory/file mode conflict and report it, despite
the directory and file variants of a name appearing at two
very different positions in the trees.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheIteratorTest.java
org.spearce.jgit.test/tst/org/spearce/jgit/treewalk/CanonicalTreeParserTest.java [new file with mode: 0644]
org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuildIterator.java
org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheIterator.java
org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
org.spearce.jgit/src/org/spearce/jgit/treewalk/EmptyTreeIterator.java
org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java