git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jonas Fonseca <fonseca@diku.dk>
Date
Sep 12, 2008, 10:57 UTC
Message-ID
<20080912105729.GB7945@diku.dk>
In-Reply-To
<200809120847.13541.robin.rosenberg.lists@dewire.com>

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
Previous: Jonas FonsecaNext: Jonas Fonseca
Message 9 of 10 in “Issue 23: Resolve tag^0 as tag^{commit}”
  1. 1/2 Issue 23: Resolve tag^0 as tag^{commit}Jonas Fonseca, Sep 11, 2008
  2. Robin RosenbergSep 11, 2008
  3. Jonas FonsecaSep 12, 2008
  4. Imran M YousufSep 12, 2008
  5. Configure the maven surefire plugin to specifically include all testsJonas Fonseca, Sep 12, 2008
  6. Shawn O. PearceSep 12, 2008
  7. Robin RosenbergSep 12, 2008
  8. 1/3 Fix IncorrectObjectTypeException thrown for incorrect ^{blob}Jonas Fonseca, Sep 12, 2008
  9. 2/3 Fix off by one distance during resolving of commit~NJonas Fonseca, Sep 12, 2008
  10. 3/3 Tests and fixes for dereferencing tags in Repository.resolve()Jonas Fonseca, Sep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.