[JGIT PATCH] Fix prefixCompare for AbbreviatedObjectId for sizes multiples of eight

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

 



This tests the special cases for the mask computed for comparisons.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---
 .../spearce/jgit/lib/AbbreviatedObjectIdTest.java  |   60 ++++++++++++++++++++
 .../org/spearce/jgit/lib/AbbreviatedObjectId.java  |    2 +-
 2 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/AbbreviatedObjectIdTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/AbbreviatedObjectIdTest.java
index 3f82d50..a6272e6 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/AbbreviatedObjectIdTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/AbbreviatedObjectIdTest.java
@@ -263,6 +263,66 @@ public void testPrefixCompare_1() {
 		assertFalse(i3.startsWith(a));
 	}
 
+	public void testPrefixCompare_7() {
+		final String sa = "7b6e806";
+		final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
+
+		final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
+		final ObjectId i1 = ObjectId.fromString(s1);
+		assertEquals(0, a.prefixCompare(i1));
+		assertTrue(i1.startsWith(a));
+
+		final String s2 = "7b6e8167ec86acef9a4184b43210d583b6d2f99a";
+		final ObjectId i2 = ObjectId.fromString(s2);
+		assertTrue(a.prefixCompare(i2) < 0);
+		assertFalse(i2.startsWith(a));
+
+		final String s3 = "7b6e8057eca6acef9a4184b43210d583b6d2f99a";
+		final ObjectId i3 = ObjectId.fromString(s3);
+		assertTrue(a.prefixCompare(i3) > 0);
+		assertFalse(i3.startsWith(a));
+	}
+
+	public void testPrefixCompare_8() {
+		final String sa = "7b6e8067";
+		final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
+
+		final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
+		final ObjectId i1 = ObjectId.fromString(s1);
+		assertEquals(0, a.prefixCompare(i1));
+		assertTrue(i1.startsWith(a));
+
+		final String s2 = "7b6e8167ec86acef9a4184b43210d583b6d2f99a";
+		final ObjectId i2 = ObjectId.fromString(s2);
+		assertTrue(a.prefixCompare(i2) < 0);
+		assertFalse(i2.startsWith(a));
+
+		final String s3 = "7b6e8057eca6acef9a4184b43210d583b6d2f99a";
+		final ObjectId i3 = ObjectId.fromString(s3);
+		assertTrue(a.prefixCompare(i3) > 0);
+		assertFalse(i3.startsWith(a));
+	}
+
+	public void testPrefixCompare_9() {
+		final String sa = "7b6e8067e";
+		final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
+
+		final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
+		final ObjectId i1 = ObjectId.fromString(s1);
+		assertEquals(0, a.prefixCompare(i1));
+		assertTrue(i1.startsWith(a));
+
+		final String s2 = "7b6e8167ec86acef9a4184b43210d583b6d2f99a";
+		final ObjectId i2 = ObjectId.fromString(s2);
+		assertTrue(a.prefixCompare(i2) < 0);
+		assertFalse(i2.startsWith(a));
+
+		final String s3 = "7b6e8057eca6acef9a4184b43210d583b6d2f99a";
+		final ObjectId i3 = ObjectId.fromString(s3);
+		assertTrue(a.prefixCompare(i3) > 0);
+		assertFalse(i3.startsWith(a));
+	}
+
 	public void testPrefixCompare_17() {
 		final String sa = "7b6e8067ec96acef9";
 		final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java
index d76e5b5..ed03fb5 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java
@@ -129,7 +129,7 @@ static int mask(final int nibbles, final int word, final int v) {
 			return v;
 		}
 
-		if (nibbles < b) {
+		if (nibbles <= b) {
 			// We have none of the bits required for this word.
 			//
 			return 0;
-- 
1.6.2.2.446.gfbdc0

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