path: root/builtin/rev-parse.c
diff options
authorJeff King <>2016-11-16 08:46:26 (GMT)
committerJunio C Hamano <>2016-11-16 19:12:15 (GMT)
commita2e7b04c443e63696d3c61bac0734486132eedbf (patch)
treebfe11f2b7e876da705a9d898caff2f885212639b /builtin/rev-parse.c
parent8c98a68981177013dfa0380968b57a1a37a45539 (diff)
rev-parse: fix parent shorthands with --symbolic
The try_parent_shorthands() function shows each parent via show_rev(). We pass the correct parent sha1, but our "name" parameter still points at the original refname. So asking for a regular rev-parse works fine (it prints the sha1s), but asking for the symbolic name gives nonsense like: $ git rev-parse --symbolic HEAD^-1 HEAD ^HEAD which is always an empty set of commits. Asking for "^!" is likewise broken, with the added bonus that its prints ^HEAD for _each_ parent. And "^@" just prints HEAD repeatedly. Arguably it would be correct to just pass NULL as the name here, and always get the parent expressed as a sha1. The "--symbolic" documentaton claims only "as close to the original input as possible", and we certainly fallback to sha1s where necessary. But it's pretty easy to generate a symbolic name on the fly from the original. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/rev-parse.c')
1 files changed, 6 insertions, 1 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 4da1f1d..c352f2f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -342,11 +342,16 @@ static int try_parent_shorthands(const char *arg)
for (parents = commit->parents, parent_number = 1;
parents = parents->next, parent_number++) {
+ char *name = NULL;
if (exclude_parent && parent_number != exclude_parent)
+ if (symbolic)
+ name = xstrfmt("%s^%d", arg, parent_number);
show_rev(include_parents ? NORMAL : REVERSED,
- parents->item->object.oid.hash, arg);
+ parents->item->object.oid.hash, name);
+ free(name);
*dotdot = '^';