From c963e7aacf4d8eaed0081ad31a29344a3cd9cd5a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sat, 14 Jan 2012 15:34:18 -0800 Subject: [PATCH] Resolve ~ with no trailing number as the first parent commit This would previously throw a RevisionSyntaxException Change-Id: I42b4988c7f6c6454e2ebda13914260e25ac1a889 --- .../eclipse/jgit/lib/RepositoryResolveTest.java | 5 +++++ .../src/org/eclipse/jgit/lib/Repository.java | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java index e76994e8b8..aab3b7ade5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java @@ -111,6 +111,11 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~2").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~3").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~03").name()); + assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~").name()); + assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~~").name()); + assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~~~").name()); + assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~~1").name()); + assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~~~0").name()); } @Test diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 1b649bba52..cf74df638b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -496,14 +496,17 @@ public abstract class Repository { if (!Character.isDigit(rev[l])) break; } - String distnum = new String(rev, i + 1, l - i - 1); int dist; - try { - dist = Integer.parseInt(distnum); - } catch (NumberFormatException e) { - throw new RevisionSyntaxException( - JGitText.get().invalidAncestryLength, revstr); - } + if (l - i > 1) { + String distnum = new String(rev, i + 1, l - i - 1); + try { + dist = Integer.parseInt(distnum); + } catch (NumberFormatException e) { + throw new RevisionSyntaxException( + JGitText.get().invalidAncestryLength, revstr); + } + } else + dist = 1; while (dist > 0) { RevCommit commit = (RevCommit) ref; if (commit.getParentCount() == 0) { -- 2.39.5