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

3 messages from 2017-03-18 to 2017-03-18. Participants: Andreas Gruenbacher, Junio C Hamano.
Thread: https://gitlist.dev/t/45424

## Andreas Gruenbacher, 2017-03-18 19:51

Subject: [PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@
Message-ID: <1489866696-17487-1-git-send-email-agruenba@redhat.com>
URL: https://gitlist.dev/e/1489866696-17487-1-git-send-email-agruenba%40redhat.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


```

## Junio C Hamano, 2017-03-18 20:18

Subject: Re: [PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@
Message-ID: <xmqq7f3m1gqd.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq7f3m1gqd.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <1489866696-17487-1-git-send-email-agruenba@redhat.com>

```
Andreas Gruenbacher <agruenba@redhat.com> writes:

> 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.

Hmph, would ^A..B and ^A...B also be turned into B..A and B...A in a
similar way?  I think the latter would not make much sense but ^A..B
might.

In any case, accepting ^rev^@ may make sense nevertheless.


```

## Andreas Gruenbacher, 2017-03-18 21:26

Subject: Re: [PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@
Message-ID: <CAHc6FU7xdyU-c5x3jGqy20g9N=BQo9KcWsZjh39eFX1mk+kSvQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAHc6FU7xdyU-c5x3jGqy20g9N%3DBQo9KcWsZjh39eFX1mk%2BkSvQ%40mail.gmail.com
In-Reply-To: <xmqq7f3m1gqd.fsf@gitster.mtv.corp.google.com>

```
On Sat, Mar 18, 2017 at 9:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Andreas Gruenbacher <agruenba@redhat.com> writes:
>
>> 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.
>
> Hmph, would ^A..B and ^A...B also be turned into B..A and B...A in a
> similar way?  I think the latter would not make much sense but ^A..B
> might.

The previous patch supports neither. I agree about ^A...B, and I don't
think supporting ^A..B is relevant.

> In any case, accepting ^rev^@ may make sense nevertheless.

Andreas

```
