summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-12-07 16:49:51 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-12-07 16:49:51 -0800
commita02be9725c9f83f0a0280a9a1f00e8d484825885 (patch)
treef816874ef8ce86655e21912952e252e632184f92 /org.eclipse.jgit/src/org
parent45731756a56361a51e839e26d3b0bed1c06ee37a (diff)
downloadjgit-a02be9725c9f83f0a0280a9a1f00e8d484825885.tar.gz
jgit-a02be9725c9f83f0a0280a9a1f00e8d484825885.zip
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>
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java8
8 files changed, 6 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
index 12a5201f6e..fcc58d1791 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
@@ -138,7 +138,6 @@ public class AddCommand extends GitCommand<DirCache> {
DirCacheBuilder builder = dc.builder();
final TreeWalk tw = new TreeWalk(repo);
- tw.reset();
tw.addTree(new DirCacheBuildIterator(builder));
if (workingTreeIterator == null)
workingTreeIterator = new FileTreeIterator(repo);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index fa0cb9c473..adcf0d8d60 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -431,7 +431,6 @@ public class DiffFormatter {
assertHaveRepository();
TreeWalk walk = new TreeWalk(reader);
- walk.reset();
walk.addTree(a);
walk.addTree(b);
walk.setRecursive(true);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java
index 5665002dc7..ed09de3322 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java
@@ -165,7 +165,6 @@ public class DirCacheBuilder extends BaseDirCacheEditor {
public void addTree(final byte[] pathPrefix, final int stage,
final ObjectReader reader, final AnyObjectId tree) throws IOException {
final TreeWalk tw = new TreeWalk(reader);
- tw.reset();
tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree
.toObjectId()));
tw.setRecursive(true);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index 11003ff4f0..01cecf40f8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -243,7 +243,6 @@ public class DirCacheCheckout {
walk = new NameConflictTreeWalk(repo);
builder = dc.builder();
- walk.reset();
addTree(walk, headCommitTree);
addTree(walk, mergeCommitTree);
walk.addTree(new DirCacheBuildIterator(builder));
@@ -285,7 +284,6 @@ public class DirCacheCheckout {
builder = dc.builder();
walk = new NameConflictTreeWalk(repo);
- walk.reset();
walk.addTree(mergeCommitTree);
walk.addTree(new DirCacheBuildIterator(builder));
walk.addTree(workingTree);
@@ -795,7 +793,6 @@ public class DirCacheCheckout {
private boolean isModified(String path) throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
- tw.reset();
tw.addTree(new DirCacheIterator(dc));
tw.addTree(new FileTreeIterator(repo.getWorkTree(), repo.getFS(),
WorkingTreeOptions.createDefaultInstance()));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index b9291f11dd..d0ef337035 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -169,7 +169,6 @@ public class IndexDiff {
boolean changesExist = false;
DirCache dirCache = repository.readDirCache();
TreeWalk treeWalk = new TreeWalk(repository);
- treeWalk.reset();
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
if (tree != null)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 135597f659..4cf57e8400 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/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.diff.DiffAlgorithm;
-import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.diff.Sequence;
+import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuildIterator;
import org.eclipse.jgit.dircache.DirCacheBuilder;
@@ -183,7 +183,6 @@ public class ResolveMerger extends ThreeWayMerger {
DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
tw = new NameConflictTreeWalk(db);
- tw.reset();
tw.addTree(mergeBase());
tw.addTree(sourceTrees[0]);
tw.addTree(sourceTrees[1]);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
index b8bd4758c0..adb2278d89 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
@@ -112,7 +112,6 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy {
@Override
protected boolean mergeImpl() throws IOException {
- tw.reset();
tw.addTree(mergeBase());
tw.addTree(sourceTrees[0]);
tw.addTree(sourceTrees[1]);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
index 992928bc43..93ca33e4c9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/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.
*/
public class TreeWalk {
+ private static final AbstractTreeIterator[] NO_TREES = {};
+
/**
* Open a tree walk and filter to exactly one path.
* <p>
@@ -226,7 +228,7 @@ public class TreeWalk {
public TreeWalk(final ObjectReader or) {
reader = or;
filter = TreeFilter.ALL;
- trees = new AbstractTreeIterator[] { new EmptyTreeIterator() };
+ trees = NO_TREES;
}
/** @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. */
public void reset() {
- trees = new AbstractTreeIterator[0];
+ trees = NO_TREES;
advance = false;
depth = 0;
}
@@ -400,7 +402,7 @@ public class TreeWalk {
* @throws IOException
* 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 {
final int oldLen = trees.length;
final int newLen = ids.length;