Browse Source

Remove empty iterator from TreeWalk

Its confusing that a new TreeWalk() needs to have reset() invoked
on it before addTree().  This is a historical accident caused by
how TreeWalk was abused within ObjectWalk.

Drop the initial empty tree from the TreeWalk and thus remove a
number of pointless reset() operations from unit tests and some of
the internal JGit code.

Existing application code which is still calling reset() will simply
be incurring a few unnecessary field assignments, but they should
consider cleaning up their code in the future.

Change-Id: I434e94ffa43491019e7dff52ca420a4d2245f48b
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.10
Shawn O. Pearce 14 years ago
parent
commit
a02be9725c
  1. 1
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java
  2. 1
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
  3. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  4. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
  5. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
  6. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
  7. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  8. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
  9. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
  10. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java
  11. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
  12. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java
  13. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java
  14. 1
      org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
  15. 1
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  16. 1
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java
  17. 3
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
  18. 1
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
  19. 3
      org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
  20. 1
      org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
  21. 8
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java

1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java

@ -74,7 +74,6 @@ class DiffTree extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db); final TreeWalk walk = new TreeWalk(db);
walk.reset();
walk.setRecursive(recursive); walk.setRecursive(recursive);
for (final AbstractTreeIterator i : trees) for (final AbstractTreeIterator i : trees)
walk.addTree(i); walk.addTree(i);

1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java

@ -62,7 +62,6 @@ class LsTree extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db); final TreeWalk walk = new TreeWalk(db);
walk.reset(); // drop the first empty tree, which we do not need here
walk.setRecursive(recursive); walk.setRecursive(recursive);
walk.addTree(tree); walk.addTree(tree);

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -59,7 +59,6 @@ import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.errors.LargeObjectException; import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.MutableObjectId;
@ -190,7 +189,7 @@ class DiffAlgorithms extends TextBuiltin {
RevCommit p = c.getParent(0); RevCommit p = c.getParent(0);
rw.parseHeaders(p); rw.parseHeaders(p);
tw.reset(new AnyObjectId[] { p.getTree(), c.getTree() }); tw.reset(p.getTree(), c.getTree());
while (tw.next()) { while (tw.next()) {
if (!isFile(tw, 0) || !isFile(tw, 1)) if (!isFile(tw, 0) || !isFile(tw, 1))
continue; continue;

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java vendored

@ -71,7 +71,6 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
final int expIdx = 2; final int expIdx = 2;
final DirCacheBuilder b = dc.builder(); final DirCacheBuilder b = dc.builder();
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheBuildIterator(b)); tw.addTree(new DirCacheBuildIterator(b));
tw.setRecursive(true); tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(Collections tw.setFilter(PathFilterGroup.createFromStrings(Collections

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java vendored

@ -90,7 +90,6 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
{ {
final Iterator<CGitIndexRecord> rItr = ls.values().iterator(); final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
while (rItr.hasNext()) { while (rItr.hasNext()) {

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java vendored

@ -64,7 +64,6 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
assertFalse(tw.next()); assertFalse(tw.next());
} }
@ -112,7 +111,6 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(i); tw.addTree(i);
int pathIdx = 0; int pathIdx = 0;
while (tw.next()) { while (tw.next()) {
@ -149,7 +147,6 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(i); tw.addTree(i);
tw.setRecursive(false); tw.setRecursive(false);
int pathIdx = 0; int pathIdx = 0;
@ -189,7 +186,6 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(i); tw.addTree(i);
tw.setRecursive(true); tw.setRecursive(true);
int pathIdx = 0; int pathIdx = 0;
@ -223,7 +219,6 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish(); b.finish();
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
tw.setRecursive(true); tw.setRecursive(true);
int pathIdx = 0; int pathIdx = 0;

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java

@ -158,7 +158,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
private void beginWalk() throws CorruptObjectException { private void beginWalk() throws CorruptObjectException {
walk = new TreeWalk(db); walk = new TreeWalk(db);
walk.reset();
walk.addTree(new FileTreeIterator(db)); walk.addTree(new FileTreeIterator(db));
} }

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java

@ -77,7 +77,6 @@ public class RacyGitTests extends RepositoryTestCase {
FileTreeIteratorWithTimeControl fileIt = new FileTreeIteratorWithTimeControl( FileTreeIteratorWithTimeControl fileIt = new FileTreeIteratorWithTimeControl(
db, modTimes); db, modTimes);
NameConflictTreeWalk tw = new NameConflictTreeWalk(db); NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(fileIt); tw.addTree(fileIt);
tw.setRecursive(true); tw.setRecursive(true);
FileTreeIterator t; FileTreeIterator t;

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java

@ -685,7 +685,6 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
public void assertWorkDir(HashMap<String, String> i) public void assertWorkDir(HashMap<String, String> i)
throws CorruptObjectException, IOException { throws CorruptObjectException, IOException {
TreeWalk walk = new TreeWalk(db); TreeWalk walk = new TreeWalk(db);
walk.reset();
walk.setRecursive(true); walk.setRecursive(true);
walk.addTree(new FileTreeIterator(db)); walk.addTree(new FileTreeIterator(db));
String expectedValue; String expectedValue;

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java

@ -82,7 +82,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
} }
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
@ -113,7 +112,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
@ -149,7 +147,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
@ -185,7 +182,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));
@ -222,7 +218,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
} }
final NameConflictTreeWalk tw = new NameConflictTreeWalk(db); final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree0));
tw.addTree(new DirCacheIterator(tree1)); tw.addTree(new DirCacheIterator(tree1));

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java

@ -98,7 +98,6 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
} }
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.setPostOrderTraversal(false); tw.setPostOrderTraversal(false);
tw.addTree(new DirCacheIterator(tree)); tw.addTree(new DirCacheIterator(tree));
@ -127,7 +126,6 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
} }
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.setPostOrderTraversal(true); tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree)); tw.addTree(new DirCacheIterator(tree));
@ -162,7 +160,6 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
} }
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset();
tw.setPostOrderTraversal(true); tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree)); tw.addTree(new DirCacheIterator(tree));

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java

@ -105,7 +105,7 @@ public class TreeWalkBasicDiffTest extends RepositoryTestCase {
inserter.release(); inserter.release();
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.reset(new ObjectId[] { oldTree, newTree }); tw.reset(oldTree, newTree);
tw.setRecursive(true); tw.setRecursive(true);
tw.setFilter(TreeFilter.ANY_DIFF); tw.setFilter(TreeFilter.ANY_DIFF);

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java

@ -44,11 +44,13 @@
package org.eclipse.jgit.treewalk.filter; package org.eclipse.jgit.treewalk.filter;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
public class TreeFilterTest extends RepositoryTestCase { public class TreeFilterTest extends RepositoryTestCase {
public void testALL_IncludesAnything() throws Exception { public void testALL_IncludesAnything() throws Exception {
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ALL.include(tw)); assertTrue(TreeFilter.ALL.include(tw));
} }
@ -62,11 +64,13 @@ public class TreeFilterTest extends RepositoryTestCase {
public void testNotALL_IncludesNothing() throws Exception { public void testNotALL_IncludesNothing() throws Exception {
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.addTree(new EmptyTreeIterator());
assertFalse(TreeFilter.ALL.negate().include(tw)); assertFalse(TreeFilter.ALL.negate().include(tw));
} }
public void testANY_DIFF_IncludesSingleTreeCase() throws Exception { public void testANY_DIFF_IncludesSingleTreeCase() throws Exception {
final TreeWalk tw = new TreeWalk(db); final TreeWalk tw = new TreeWalk(db);
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ANY_DIFF.include(tw)); assertTrue(TreeFilter.ANY_DIFF.include(tw));
} }

1
org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java

@ -138,7 +138,6 @@ public class AddCommand extends GitCommand<DirCache> {
DirCacheBuilder builder = dc.builder(); DirCacheBuilder builder = dc.builder();
final TreeWalk tw = new TreeWalk(repo); final TreeWalk tw = new TreeWalk(repo);
tw.reset();
tw.addTree(new DirCacheBuildIterator(builder)); tw.addTree(new DirCacheBuildIterator(builder));
if (workingTreeIterator == null) if (workingTreeIterator == null)
workingTreeIterator = new FileTreeIterator(repo); workingTreeIterator = new FileTreeIterator(repo);

1
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -431,7 +431,6 @@ public class DiffFormatter {
assertHaveRepository(); assertHaveRepository();
TreeWalk walk = new TreeWalk(reader); TreeWalk walk = new TreeWalk(reader);
walk.reset();
walk.addTree(a); walk.addTree(a);
walk.addTree(b); walk.addTree(b);
walk.setRecursive(true); walk.setRecursive(true);

1
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java vendored

@ -165,7 +165,6 @@ public class DirCacheBuilder extends BaseDirCacheEditor {
public void addTree(final byte[] pathPrefix, final int stage, public void addTree(final byte[] pathPrefix, final int stage,
final ObjectReader reader, final AnyObjectId tree) throws IOException { final ObjectReader reader, final AnyObjectId tree) throws IOException {
final TreeWalk tw = new TreeWalk(reader); final TreeWalk tw = new TreeWalk(reader);
tw.reset();
tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree
.toObjectId())); .toObjectId()));
tw.setRecursive(true); tw.setRecursive(true);

3
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -243,7 +243,6 @@ public class DirCacheCheckout {
walk = new NameConflictTreeWalk(repo); walk = new NameConflictTreeWalk(repo);
builder = dc.builder(); builder = dc.builder();
walk.reset();
addTree(walk, headCommitTree); addTree(walk, headCommitTree);
addTree(walk, mergeCommitTree); addTree(walk, mergeCommitTree);
walk.addTree(new DirCacheBuildIterator(builder)); walk.addTree(new DirCacheBuildIterator(builder));
@ -285,7 +284,6 @@ public class DirCacheCheckout {
builder = dc.builder(); builder = dc.builder();
walk = new NameConflictTreeWalk(repo); walk = new NameConflictTreeWalk(repo);
walk.reset();
walk.addTree(mergeCommitTree); walk.addTree(mergeCommitTree);
walk.addTree(new DirCacheBuildIterator(builder)); walk.addTree(new DirCacheBuildIterator(builder));
walk.addTree(workingTree); walk.addTree(workingTree);
@ -795,7 +793,6 @@ public class DirCacheCheckout {
private boolean isModified(String path) throws CorruptObjectException, IOException { private boolean isModified(String path) throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo); NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
tw.reset();
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
tw.addTree(new FileTreeIterator(repo.getWorkTree(), repo.getFS(), tw.addTree(new FileTreeIterator(repo.getWorkTree(), repo.getFS(),
WorkingTreeOptions.createDefaultInstance())); WorkingTreeOptions.createDefaultInstance()));

1
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

@ -169,7 +169,6 @@ public class IndexDiff {
boolean changesExist = false; boolean changesExist = false;
DirCache dirCache = repository.readDirCache(); DirCache dirCache = repository.readDirCache();
TreeWalk treeWalk = new TreeWalk(repository); TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.reset();
treeWalk.setRecursive(true); treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir) // add the trees (tree, dirchache, workdir)
if (tree != null) if (tree != null)

3
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

@ -59,10 +59,10 @@ import java.util.Map;
import org.eclipse.jgit.JGitText; import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.diff.DiffAlgorithm; import org.eclipse.jgit.diff.DiffAlgorithm;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.diff.Sequence; import org.eclipse.jgit.diff.Sequence;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuildIterator; import org.eclipse.jgit.dircache.DirCacheBuildIterator;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
@ -183,7 +183,6 @@ public class ResolveMerger extends ThreeWayMerger {
DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
tw = new NameConflictTreeWalk(db); tw = new NameConflictTreeWalk(db);
tw.reset();
tw.addTree(mergeBase()); tw.addTree(mergeBase());
tw.addTree(sourceTrees[0]); tw.addTree(sourceTrees[0]);
tw.addTree(sourceTrees[1]); tw.addTree(sourceTrees[1]);

1
org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java

@ -112,7 +112,6 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy {
@Override @Override
protected boolean mergeImpl() throws IOException { protected boolean mergeImpl() throws IOException {
tw.reset();
tw.addTree(mergeBase()); tw.addTree(mergeBase());
tw.addTree(sourceTrees[0]); tw.addTree(sourceTrees[0]);
tw.addTree(sourceTrees[1]); tw.addTree(sourceTrees[1]);

8
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java

@ -84,6 +84,8 @@ import org.eclipse.jgit.util.RawParseUtils;
* permitted, even from concurrent threads. * permitted, even from concurrent threads.
*/ */
public class TreeWalk { public class TreeWalk {
private static final AbstractTreeIterator[] NO_TREES = {};
/** /**
* Open a tree walk and filter to exactly one path. * Open a tree walk and filter to exactly one path.
* <p> * <p>
@ -226,7 +228,7 @@ public class TreeWalk {
public TreeWalk(final ObjectReader or) { public TreeWalk(final ObjectReader or) {
reader = or; reader = or;
filter = TreeFilter.ALL; filter = TreeFilter.ALL;
trees = new AbstractTreeIterator[] { new EmptyTreeIterator() }; trees = NO_TREES;
} }
/** @return the reader this walker is using to load objects. */ /** @return the reader this walker is using to load objects. */
@ -337,7 +339,7 @@ public class TreeWalk {
/** Reset this walker so new tree iterators can be added to it. */ /** Reset this walker so new tree iterators can be added to it. */
public void reset() { public void reset() {
trees = new AbstractTreeIterator[0]; trees = NO_TREES;
advance = false; advance = false;
depth = 0; depth = 0;
} }
@ -400,7 +402,7 @@ public class TreeWalk {
* @throws IOException * @throws IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public void reset(final AnyObjectId[] ids) throws MissingObjectException, public void reset(final AnyObjectId... ids) throws MissingObjectException,
IncorrectObjectTypeException, CorruptObjectException, IOException { IncorrectObjectTypeException, CorruptObjectException, IOException {
final int oldLen = trees.length; final int oldLen = trees.length;
final int newLen = ids.length; final int newLen = ids.length;

Loading…
Cancel
Save