When iterating a subset of the working directory over the full repository tree (e.g. a CanonicalTreeParser run in parallel in the same TreeWalk) we need the working directory to know what prefix it must apply to all of its own generated paths so they match up with the paths of the CanonicalTreeParser coming from the object database. The prefix is only set on the root level, as we only need to inject it into the first iterator. After that the shared path buffer will ensure the subtree iterators (if any are created) will have the proper path in them too. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../jgit/treewalk/AbstractTreeIterator.java | 36 ++++++++++++++++++++ .../spearce/jgit/treewalk/WorkingTreeIterator.java | 20 +++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java index 64bb5be..cf67836 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java @@ -39,6 +39,8 @@ package org.spearce.jgit.treewalk; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; import org.spearce.jgit.errors.CorruptObjectException; import org.spearce.jgit.errors.IncorrectObjectTypeException; @@ -128,6 +130,40 @@ public abstract class AbstractTreeIterator { } /** + * Create a new iterator with no parent and a prefix. + * <p> + * The prefix path supplied is inserted in front of all paths generated by + * this iterator. It is intended to be used when an iterator is being + * created for a subsection of an overall repository and needs to be + * combined with other iterators that are created to run over the entire + * repository namespace. + * + * @param prefix + * position of this iterator in the repository tree. The value + * may be null or the empty string to indicate the prefix is the + * root of the repository. A trailing slash ('/') is + * automatically appended if the prefix does not end in '/'. + */ + protected AbstractTreeIterator(final String prefix) { + parent = null; + + if (prefix != null && prefix.length() > 0) { + final ByteBuffer b; + + b = Constants.CHARSET.encode(CharBuffer.wrap(prefix)); + pathLen = b.limit(); + path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)]; + b.get(path, 0, pathLen); + if (path[pathLen - 1] != '/') + path[pathLen++] = '/'; + pathOffset = pathLen; + } else { + path = new byte[DEFAULT_PATH_SIZE]; + pathOffset = 0; + } + } + + /** * Create an iterator for a subtree of an existing iterator. * * @param p diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java index 73c4b8b..afac77b 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java @@ -100,6 +100,26 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { } /** + * Create a new iterator with no parent and a prefix. + * <p> + * The prefix path supplied is inserted in front of all paths generated by + * this iterator. It is intended to be used when an iterator is being + * created for a subsection of an overall repository and needs to be + * combined with other iterators that are created to run over the entire + * repository namespace. + * + * @param prefix + * position of this iterator in the repository tree. The value + * may be null or the empty string to indicate the prefix is the + * root of the repository. A trailing slash ('/') is + * automatically appended if the prefix does not end in '/'. + */ + protected WorkingTreeIterator(final String prefix) { + super(prefix); + nameEncoder = Constants.CHARSET.newEncoder(); + } + + /** * Create an iterator for a subtree of an existing iterator. * * @param p -- 1.6.0.rc2.219.g1250ab -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html