From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: David Watson <dwatson@mimvista.com>,
Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 05/10] Fix git sort order compare bug
Date: Sun, 24 Feb 2008 00:50:38 +0100 [thread overview]
Message-ID: <1203810643-28819-6-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1203810643-28819-5-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../tst/org/spearce/jgit/lib/T0002_Tree.java | 44 ++++++++++++++++++++
.../src/org/spearce/jgit/lib/Tree.java | 10 ++++-
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0002_Tree.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0002_Tree.java
index 24b368f..7c7f6c0 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0002_Tree.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0002_Tree.java
@@ -17,6 +17,7 @@
package org.spearce.jgit.lib;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -24,6 +25,49 @@ public class T0002_Tree extends RepositoryTestCase {
private static final ObjectId SOME_FAKE_ID = new ObjectId(
"0123456789abcdef0123456789abcdef01234567");
+ private int compareNamesUsingSpecialCompare(String a,String b) throws UnsupportedEncodingException {
+ char lasta = '\0';
+ byte[] abytes;
+ if (a.length() > 0 && a.charAt(a.length()-1) == '/') {
+ lasta = '/';
+ a = a.substring(0, a.length() - 1);
+ }
+ abytes = a.getBytes("ISO-8859-1");
+ char lastb = '\0';
+ byte[] bbytes;
+ if (b.length() > 0 && b.charAt(b.length()-1) == '/') {
+ lastb = '/';
+ b = b.substring(0, b.length() - 1);
+ }
+ bbytes = b.getBytes("ISO-8859-1");
+ return Tree.compareNames(abytes, bbytes, lasta, lastb);
+ }
+
+ public void test000_sort_01() throws UnsupportedEncodingException {
+ assertEquals(0, compareNamesUsingSpecialCompare("a","a"));
+ }
+ public void test000_sort_02() throws UnsupportedEncodingException {
+ assertEquals(-1, compareNamesUsingSpecialCompare("a","b"));
+ assertEquals(1, compareNamesUsingSpecialCompare("b","a"));
+ }
+ public void test000_sort_03() throws UnsupportedEncodingException {
+ assertEquals(1, compareNamesUsingSpecialCompare("a:","a"));
+ assertEquals(1, compareNamesUsingSpecialCompare("a/","a"));
+ assertEquals(-1, compareNamesUsingSpecialCompare("a","a/"));
+ assertEquals(-1, compareNamesUsingSpecialCompare("a","a:"));
+ assertEquals(1, compareNamesUsingSpecialCompare("a:","a/"));
+ assertEquals(-1, compareNamesUsingSpecialCompare("a/","a:"));
+ }
+ public void test000_sort_04() throws UnsupportedEncodingException {
+ assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a"));
+ assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a"));
+ }
+ public void test000_sort_05() throws UnsupportedEncodingException {
+ assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/"));
+ assertEquals(1, compareNamesUsingSpecialCompare("a/","a."));
+
+ }
+
public void test001_createEmpty() throws IOException {
final Tree t = new Tree(db);
assertTrue("isLoaded", t.isLoaded());
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
index ab83917..5d8e0e0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
@@ -65,7 +65,10 @@ public class Tree extends TreeEntry implements Treeish {
else if (aj > lastb)
return 1;
else
- return 0;
+ if (j == a.length - 1)
+ return 0;
+ else
+ return -1;
}
if (k < nameEnd) {
int bk = nameUTF8[k] & 0xff;
@@ -74,7 +77,10 @@ public class Tree extends TreeEntry implements Treeish {
else if (lasta > bk)
return 1;
else
- return 0;
+ if (k == nameEnd - 1)
+ return 0;
+ else
+ return 1;
}
if (lasta < lastb)
return -1;
--
1.5.4.2
next prev parent reply other threads:[~2008-02-23 23:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-23 23:50 [EGIT] Sort order from hell fixes, take 2 Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 01/10] Tighten IndexDiffTest to make it test better what it claims to test Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 02/10] Extend IndexDiffTest with more tests Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 03/10] WorkdirCheckout: more test for names that are close Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 04/10] Split a big test in ReadTreeTest into smaller tests Robin Rosenberg
2008-02-23 23:50 ` Robin Rosenberg [this message]
2008-02-23 23:50 ` [EGIT PATCH 06/10] Use the proper comparison algorithm Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 07/10] GitIndex: Get access to raw name and file mode Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 08/10] TreeEntry: Accessors for full raw name and mode bits Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 09/10] Implement a Tree iterator Robin Rosenberg
2008-02-23 23:50 ` [EGIT PATCH 10/10] Rewritten IndexTreeWalker Robin Rosenberg
2008-03-03 14:17 ` [EGIT] Sort order from hell fixes, take 2 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=1203810643-28819-6-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=dwatson@mimvista.com \
--cc=git@vger.kernel.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).