From 4a91b92f1314a4219c465ed6166986afe65b1ff7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 18 Aug 2008 16:53:14 -0700 Subject: [PATCH] Refactor AbstractTreeIterator.pathCompare to force another mode 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 Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/treewalk/AbstractTreeIterator.java | 14 +++++++++----- 1 file 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 232204a3..bd75d2d4 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 @@ public abstract class AbstractTreeIterator { * 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 abstract class AbstractTreeIterator { 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 @@ public abstract class AbstractTreeIterator { 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 @@ public abstract class AbstractTreeIterator { 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 @@ public abstract class AbstractTreeIterator { return 1; } - private int lastPathChar() { + private static int lastPathChar(final int mode) { return FileMode.TREE.equals(mode) ? '/' : '\0'; } -- 2.11.4.GIT