git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: "Roger C. Soares" <rogersoares@intelinet.com.br>,
	Dave Watson <dwatson@mimvista.com>,
	"Shawn O. Pearce" <spearce@spearce.org>,
	Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 2/2] Resort entries in "normal" order before looking for conflicts
Date: Wed,  6 Feb 2008 00:46:06 +0100	[thread overview]
Message-ID: <1202255166-4581-3-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1202255166-4581-2-git-send-email-robin.rosenberg@dewire.com>

When checking out another branch we get a problem if our version contains
a tree name that is longer, but has another tree as a prefix.

        Our tree
          a/a
          a.a/b

        Other tree
          a/a

The conflict comes from names not being compared properly in git
order.

Directory/File conflicts are not easy to handle. This solution
is cheating, but solved a real user's problem.

This commit adds test cases for the particular problem plus one
similar test that didn't fail before either.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../tst/org/spearce/jgit/lib/ReadTreeTest.java     |   16 ++++++++-
 .../src/org/spearce/jgit/lib/IndexTreeWalker.java  |   35 ++++++++++++--------
 2 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ReadTreeTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ReadTreeTest.java
index 7ac48c9..6faedc7 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ReadTreeTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ReadTreeTest.java
@@ -477,7 +477,21 @@ public class ReadTreeTest extends RepositoryTestCase {
 		
 		assertNoConflicts();
 	}
-	
+
+	public void testCloseNameConflictsX0() throws IOException {
+		setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "b.b/b.b","b.b/b.bs"), mkmap("a/a", "a/a-c") );
+		checkout();
+		go();
+		assertNoConflicts();
+	}
+
+	public void testCloseNameConflicts1() throws IOException {
+		setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "a.a/a.a","a.a/a.a"), mkmap("a/a", "a/a-c") );
+		checkout();
+		go();
+		assertNoConflicts();
+	}
+
 	private void checkout() throws IOException {
 		readTree = new WorkDirCheckout(db, trash, head, index, merge);
 		readTree.checkout();
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java b/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java
index 93d5bb2..bc2fb23 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java
@@ -19,6 +19,8 @@ package org.spearce.jgit.lib;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
 
 import org.spearce.jgit.lib.GitIndex.Entry;
 
@@ -85,9 +87,28 @@ public class IndexTreeWalker {
 		walk(mainTree, newTree, "/");
 	}
 
+	static Comparator<TreeEntry> treeEntryPlainComparator() {
+		return new Comparator<TreeEntry>() {
+			public int compare(TreeEntry o1, TreeEntry o2) {
+				return o1.getName().compareTo(o2.getName());
+			}
+		};
+	}
+
+	static Comparator<Entry> indexEntryPlainComparator() {
+		return new Comparator<Entry>() {
+			public int compare(Entry o1, Entry o2) {
+				return o1.getName().compareTo(o2.getName());
+			}
+		};
+	}
+
 	private void walk(Tree tree, Tree auxTree, String curDir) throws IOException {
 		TreeEntry[] treeMembers = tree == null ? new TreeEntry[0] : tree.members();
 		TreeEntry[] auxTreeMembers = auxTree == null ? new TreeEntry[0] : auxTree.members();
+		Arrays.sort(treeMembers, treeEntryPlainComparator());
+		Arrays.sort(auxTreeMembers, treeEntryPlainComparator());
+		Arrays.sort(indexMembers, indexEntryPlainComparator());
 		int treeCounter = 0;
 		int auxTreeCounter = 0;
 		
@@ -308,18 +329,4 @@ public class IndexTreeWalker {
 		}
 		return t1.getName().compareTo(t2.getName());
 	}
-	
-	static int compare(byte[] name1, byte[] name2) {
-		for (int i = 0; i < name1.length && i < name2.length; i++) {
-			if (name1[i] < name2[i])
-				return -1;
-			if (name1[i] > name2[i])
-				return 1;
-		}
-		if (name1.length < name2.length)
-			return -1;
-		if (name2.length < name1.length)
-			return 1;
-		return 0;
-	}
 }
-- 
1.5.4.rc4.25.g81cc

  reply	other threads:[~2008-02-05 23:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-05 23:46 [EGIT Patches] Sort order from hell fixes Robin Rosenberg
2008-02-05 23:46 ` [EGIT PATCH 1/2] Fix git sort order compare bug Robin Rosenberg
2008-02-05 23:46   ` Robin Rosenberg [this message]
2008-02-06  0:50     ` [EGIT PATCH 2/2] Resort entries in "normal" order before looking for conflicts Robin Rosenberg
2008-02-10 20:13       ` Robin Rosenberg
2008-02-10 20:18         ` Robin Rosenberg
2008-02-10 21:11           ` David Watson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1202255166-4581-3-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=dwatson@mimvista.com \
    --cc=git@vger.kernel.org \
    --cc=rogersoares@intelinet.com.br \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).