[JGIT PATCH 2/3] Fix off by one distance during resolving of commit~N

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jonas Fonseca
Date: Friday, September 12, 2008 - 3:57 am

To be compatible with git-rev-parse, commit~0 should resolve to commit,
commit~1 to commit^, etc.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 .../org/spearce/jgit/lib/T0008_testparserev.java   |    9 +++++----
 .../src/org/spearce/jgit/lib/Repository.java       |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
index 8883b8b..506f51f 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
@@ -82,10 +82,11 @@ public void testRef_refname() throws IOException {
 	}
 
 	public void testDistance() throws IOException {
-		assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~0").name());
-		assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~1").name());
-		assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~2").name());
-		assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~02").name());
+		assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~0").name());
+		assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~1").name());
+		assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~2").name());
+		assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~3").name());
+		assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~03").name());
 	}
 
 	public void testTree() throws IOException {
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 730a267..894fe3b 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -688,7 +688,7 @@ else if (item.equals("")) {
 					throw new RevisionSyntaxException(
 							"Invalid ancestry length", revstr);
 				}
-				while (dist >= 0) {
+				while (dist > 0) {
 					final ObjectId[] parents = ((Commit) ref).getParentIds();
 					if (parents.length == 0) {
 						refId = null;
-- 
1.6.0.1.451.gc8d31

-- 
Jonas Fonseca
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[JGIT PATCH 1/2] Issue 23: Resolve tag^0 as tag^{commit}, Jonas Fonseca, (Thu Sep 11, 2:39 pm)
Re: [JGIT PATCH 1/2] Issue 23: Resolve tag^0 as tag^{commit}, Robin Rosenberg, (Thu Sep 11, 3:47 pm)
Re: [JGIT PATCH 1/2] Issue 23: Resolve tag^0 as tag^{commit}, Robin Rosenberg, (Thu Sep 11, 11:47 pm)
[JGIT PATCH 2/3] Fix off by one distance during resolving ..., Jonas Fonseca, (Fri Sep 12, 3:57 am)