[JGIT PATCH 06/14] Refactor AbstractTreeIterator.pathCompare to force another mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When handling D/F (directory/file) conflicts we need to pretend that one
of the two iterators has the other "type" of mode so we can search for
possible matches.  Rather than editing the mode instance member we now
overload pathCompare to accept the 2nd iterator's mode as an argument.

We can now force a tree entry to compare as a normal file by passing
in a mode of 0, or we can force a file entry to compare as a tree by
passing in FileMode.TREE.getBits().

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../jgit/treewalk/AbstractTreeIterator.java        |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 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 232204a..bd75d2d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
@@ -227,6 +227,10 @@ protected void growPath(final int len) {
 	 *         p's entry sorts first.
 	 */
 	public int pathCompare(final AbstractTreeIterator p) {
+		return pathCompare(p, p.mode);
+	}
+
+	int pathCompare(final AbstractTreeIterator p, final int pMode) {
 		final byte[] a = path;
 		final byte[] b = p.path;
 		final int aLen = pathLen;
@@ -241,7 +245,7 @@ public int pathCompare(final AbstractTreeIterator p) {
 
 		if (cPos < aLen) {
 			final int aj = a[cPos] & 0xff;
-			final int lastb = p.lastPathChar();
+			final int lastb = lastPathChar(pMode);
 			if (aj < lastb)
 				return -1;
 			else if (aj > lastb)
@@ -254,7 +258,7 @@ else if (cPos == aLen - 1)
 
 		if (cPos < bLen) {
 			final int bk = b[cPos] & 0xff;
-			final int lasta = lastPathChar();
+			final int lasta = lastPathChar(mode);
 			if (lasta < bk)
 				return -1;
 			else if (lasta > bk)
@@ -265,8 +269,8 @@ else if (cPos == bLen - 1)
 				return 1;
 		}
 
-		final int lasta = lastPathChar();
-		final int lastb = p.lastPathChar();
+		final int lasta = lastPathChar(mode);
+		final int lastb = lastPathChar(pMode);
 		if (lasta < lastb)
 			return -1;
 		else if (lasta > lastb)
@@ -280,7 +284,7 @@ else if (aLen < bLen)
 			return 1;
 	}
 
-	private int lastPathChar() {
+	private static int lastPathChar(final int mode) {
 		return FileMode.TREE.equals(mode) ? '/' : '\0';
 	}
 
-- 
1.6.0.87.g2858d

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux