From 8e2a24a3b636d22a973e89763b5dbf11ec0d6821 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Thu, 14 Mar 2013 09:35:00 -0700 Subject: [PATCH] NameRevCommand: Use ~ notation for first parents of merges Prefer ~(N+1) to ^1~N. Although both are correct, the former is cleaner and matches "git name-rev". Change-Id: I772001a219e5eb346f5552c92e6d98c70b2cfa98 --- .../org/eclipse/jgit/api/NameRevCommandTest.java | 16 +++++++++++++++- .../src/org/eclipse/jgit/api/NameRevCommand.java | 5 ++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java index f67d66931..26dc2d05a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java @@ -144,7 +144,21 @@ public void onePathMerge() throws Exception { RevCommit c2 = tr.commit().parent(c0).create(); RevCommit c3 = tr.commit().parent(c1).parent(c2).create(); tr.update("master", c3); - assertOneResult("master^1~1", c0); + assertOneResult("master~2", c0); + } + + @Test + public void onePathMergeSecondParent() throws Exception { + // 0--1-----4 + // \-2--3-/ + RevCommit c0 = tr.commit().create(); + RevCommit c1 = tr.commit().parent(c0).create(); + RevCommit c2 = tr.commit().parent(c0).create(); + RevCommit c3 = tr.commit().parent(c2).create(); + RevCommit c4 = tr.commit().parent(c1).parent(c3).create(); + tr.update("master", c4); + assertOneResult("master^2", c3); + assertOneResult("master^2~1", c2); } @Test diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java index 073802db4..2397636f3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java @@ -147,12 +147,11 @@ public Map call() throws GitAPIException { break; if (c.getCommitTime() < cutoff) continue; - boolean merge = c.getParentCount() > 1; - long cost = c.cost + (merge ? MERGE_COST : 1); + long cost = c.cost + (c.getParentCount() > 1 ? MERGE_COST : 1); for (int i = 0; i < c.getParentCount(); i++) { NameRevCommit p = (NameRevCommit) walk.parseCommit(c.getParent(i)); if (p.tip == null || compare(c.tip, cost, p.tip, p.cost) < 0) { - if (merge) { + if (i > 0) { p.tip = c.format().append('^').append(i + 1).toString(); p.distance = 0; } else {