aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-09-01 12:31:37 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-09-02 11:38:39 -0700
commit6f00a3e651e91592e2eb4f239b243a0aa2fe4610 (patch)
tree7dc9f848bf103e6e8f6f8e3e2122b57bcbe0846f /org.eclipse.jgit/src/org/eclipse
parent244b1580b5155099bfdf98692d76c1b2a6183126 (diff)
downloadjgit-6f00a3e651e91592e2eb4f239b243a0aa2fe4610.tar.gz
jgit-6f00a3e651e91592e2eb4f239b243a0aa2fe4610.zip
Fix TreeWalk bug comparing DirCache and WorkingTree with ANY_DIFF
When comparing a DirCache and a WorkingTree using ANY_DIFF we sometimes didn't recursive into a subtree of both sides gave us zeroId() back for the identity of a subtree. This happens when the DirCache doesn't have a valid cache tree for the subtree, as then it uses zeroId() for the ObjectId of the subtree, which then appears to be equal to the zeroId() of the WorkingTreeIterator's subtree. We work around this by adding a hasId() method that returns true only if this iterator has a valid ObjectId. The idEquals method on TreeWalk than only performs a compare between two iterators if both iterators have a valid id. Change-Id: I695f7fafbeb452e8c0703a05c02921fae0822d3f Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java7
6 files changed, 32 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java
index aa8d9fb85d..e685e0cad8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java
@@ -45,7 +45,6 @@
package org.eclipse.jgit.dircache;
import java.io.IOException;
-import java.util.Arrays;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Constants;
@@ -142,9 +141,16 @@ public class DirCacheIterator extends AbstractTreeIterator {
}
@Override
+ public boolean hasId() {
+ if (currentSubtree != null)
+ return currentSubtree.isValid();
+ return currentEntry != null;
+ }
+
+ @Override
public byte[] idBuffer() {
if (currentSubtree != null)
- return subtreeId;
+ return currentSubtree.isValid() ? subtreeId : zeroid;
if (currentEntry != null)
return currentEntry.idBuffer();
return zeroid;
@@ -218,8 +224,6 @@ public class DirCacheIterator extends AbstractTreeIterator {
if (s.isValid())
s.getObjectId().copyRawTo(subtreeId, 0);
- else
- Arrays.fill(subtreeId, (byte) 0);
mode = FileMode.TREE.getBits();
path = cep;
pathLen = pathOffset + s.nameLength();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java
index eee62c63a5..79b57d1eb6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java
@@ -369,6 +369,9 @@ public abstract class AbstractTreeIterator {
otherIterator.idBuffer(), otherIterator.idOffset());
}
+ /** @return true if the entry has a valid ObjectId. */
+ public abstract boolean hasId();
+
/**
* Get the object id of the current entry.
*
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
index 01b8274253..1e49d380a8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
@@ -234,6 +234,11 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
}
@Override
+ public boolean hasId() {
+ return true;
+ }
+
+ @Override
public byte[] idBuffer() {
return raw;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java
index 49d75871e8..8dbf80e6a8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java
@@ -93,6 +93,11 @@ public class EmptyTreeIterator extends AbstractTreeIterator {
}
@Override
+ public boolean hasId() {
+ return false;
+ }
+
+ @Override
public ObjectId getEntryObjectId() {
return ObjectId.zeroId();
}
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 16859646b6..992928bc43 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -683,8 +683,6 @@ public class TreeWalk {
final AbstractTreeIterator ch = currentHead;
final AbstractTreeIterator a = trees[nthA];
final AbstractTreeIterator b = trees[nthB];
- if (a.matches == ch && b.matches == ch)
- return a.idEqual(b);
if (a.matches != ch && b.matches != ch) {
// If neither tree matches the current path node then neither
// tree has this entry. In such case the ObjectId is zero(),
@@ -692,6 +690,10 @@ public class TreeWalk {
//
return true;
}
+ if (!a.hasId() || !b.hasId())
+ return false;
+ if (a.matches == ch && b.matches == ch)
+ return a.idEqual(b);
return false;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index 51c3483699..5cc061bbb4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -195,6 +195,13 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
}
@Override
+ public boolean hasId() {
+ if (contentIdFromPtr == ptr)
+ return true;
+ return (mode & FileMode.TYPE_MASK) == FileMode.TYPE_FILE;
+ }
+
+ @Override
public byte[] idBuffer() {
if (contentIdFromPtr == ptr)
return contentId;