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

[PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@

From
AGAndreas Gruenbacher <agruenba@redhat.com>
Date
Mar 18, 2017, 19:51 UTC
Message-ID
<1489866696-17487-1-git-send-email-agruenba@redhat.com>
Hello,

the log and rev-parse commands both support the rev^@ syntax which stands for all parents of rev. The log command also supports ^rev^@ to exclude all of the parents of rev, but rev-parse does not. Should this be fixed?

If so, the following patch would be a start.

Thanks, Andreas

--
rev-parse: Add support for ^rev^@

Add support for the ^rev^@ syntax to exclude all of the parents of rev. This syntax is already supported by git log.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 builtin/rev-parse.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 2549643..ab84c49 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -293,7 +293,7 @@ static int try_difference(const char *arg)
 	return 0;
 }
 
-static int try_parent_shorthands(const char *arg)
+static int try_parent_shorthands(int type, const char *arg)
 {
 	char *dotdot;
 	unsigned char sha1[20];
@@ -339,7 +339,7 @@ static int try_parent_shorthands(const char *arg)
 	}
 
 	if (include_rev)
-		show_rev(NORMAL, sha1, arg);
+		show_rev(type, sha1, arg);
 	for (parents = commit->parents, parent_number = 1;
 	     parents;
 	     parents = parents->next, parent_number++) {
@@ -350,7 +350,7 @@ static int try_parent_shorthands(const char *arg)
 
 		if (symbolic)
 			name = xstrfmt("%s^%d", arg, parent_number);
-		show_rev(include_parents ? NORMAL : REVERSED,
+		show_rev(include_parents ? type : !type,
 			 parents->item->object.oid.hash, name);
 		free(name);
 	}
@@ -896,14 +896,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 		/* Not a flag argument */
 		if (try_difference(arg))
 			continue;
-		if (try_parent_shorthands(arg))
-			continue;
 		name = arg;
 		type = NORMAL;
 		if (*arg == '^') {
 			name++;
 			type = REVERSED;
 		}
+		if (try_parent_shorthands(type, name))
+			continue;
 		if (!get_sha1_with_context(name, flags, sha1, &unused)) {
 			if (verify)
 				revs_count++;
-- 
2.7.4
Next: Junio C Hamano
Message 1 of 3 in “Inconsistency between git log and git rev-parse for ^HEAD^@”
  1. Inconsistency between git log and git rev-parse for ^HEAD^@Andreas Gruenbacher, Mar 18, 2017
  2. Junio C HamanoMar 18, 2017
  3. Andreas GruenbacherMar 18, 2017

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.