{"thread":{"id":"45424","subject":"[PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@","startedAt":"2017-03-18T19:51:48Z","lastAt":"2017-03-18T21:26:53Z","messageCount":3,"participants":["Andreas Gruenbacher","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"314540","messageId":"1489866696-17487-1-git-send-email-agruenba@redhat.com","threadId":"45424","inReplyTo":null,"subject":"[PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@","fromName":"Andreas Gruenbacher","fromEmail":"agruenba@redhat.com","sentAt":"2017-03-18T19:51:36Z","receivedAt":"2017-03-18T19:51:48Z","isPatch":true,"sender":{"key":"agruenba@redhat.com","avatar":null},"body":"Hello,\n\nthe log and rev-parse commands both support the rev^@ syntax which stands for\nall parents of rev.  The log command also supports ^rev^@ to exclude all of the\nparents of rev, but rev-parse does not.  Should this be fixed?\n\nIf so, the following patch would be a start.\n\nThanks,\nAndreas\n\n--\n\nrev-parse: Add support for ^rev^@\n\nAdd support for the ^rev^@ syntax to exclude all of the parents of rev.  This\nsyntax is already supported by git log.\n\nSigned-off-by: Andreas Gruenbacher <agruenba@redhat.com>\n---\n builtin/rev-parse.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 2549643..ab84c49 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -293,7 +293,7 @@ static int try_difference(const char *arg)\n \treturn 0;\n }\n \n-static int try_parent_shorthands(const char *arg)\n+static int try_parent_shorthands(int type, const char *arg)\n {\n \tchar *dotdot;\n \tunsigned char sha1[20];\n@@ -339,7 +339,7 @@ static int try_parent_shorthands(const char *arg)\n \t}\n \n \tif (include_rev)\n-\t\tshow_rev(NORMAL, sha1, arg);\n+\t\tshow_rev(type, sha1, arg);\n \tfor (parents = commit->parents, parent_number = 1;\n \t     parents;\n \t     parents = parents->next, parent_number++) {\n@@ -350,7 +350,7 @@ static int try_parent_shorthands(const char *arg)\n \n \t\tif (symbolic)\n \t\t\tname = xstrfmt(\"%s^%d\", arg, parent_number);\n-\t\tshow_rev(include_parents ? NORMAL : REVERSED,\n+\t\tshow_rev(include_parents ? type : !type,\n \t\t\t parents->item->object.oid.hash, name);\n \t\tfree(name);\n \t}\n@@ -896,14 +896,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t/* Not a flag argument */\n \t\tif (try_difference(arg))\n \t\t\tcontinue;\n-\t\tif (try_parent_shorthands(arg))\n-\t\t\tcontinue;\n \t\tname = arg;\n \t\ttype = NORMAL;\n \t\tif (*arg == '^') {\n \t\t\tname++;\n \t\t\ttype = REVERSED;\n \t\t}\n+\t\tif (try_parent_shorthands(type, name))\n+\t\t\tcontinue;\n \t\tif (!get_sha1_with_context(name, flags, sha1, &unused)) {\n \t\t\tif (verify)\n \t\t\t\trevs_count++;\n-- \n2.7.4\n\n"},{"id":"314544","messageId":"xmqq7f3m1gqd.fsf@gitster.mtv.corp.google.com","threadId":"45424","inReplyTo":"1489866696-17487-1-git-send-email-agruenba@redhat.com","subject":"Re: [PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-18T20:18:18Z","receivedAt":"2017-03-18T20:23:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Gruenbacher <agruenba@redhat.com> writes:\n\n> Hello,\n>\n> the log and rev-parse commands both support the rev^@ syntax which stands for\n> all parents of rev.  The log command also supports ^rev^@ to exclude all of the\n> parents of rev, but rev-parse does not.  Should this be fixed?\n>\n> If so, the following patch would be a start.\n\nHmph, would ^A..B and ^A...B also be turned into B..A and B...A in a\nsimilar way?  I think the latter would not make much sense but ^A..B\nmight.\n\nIn any case, accepting ^rev^@ may make sense nevertheless.\n\n"},{"id":"314556","messageId":"CAHc6FU7xdyU-c5x3jGqy20g9N=BQo9KcWsZjh39eFX1mk+kSvQ@mail.gmail.com","threadId":"45424","inReplyTo":"xmqq7f3m1gqd.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] Inconsistency between git log and git rev-parse for ^HEAD^@","fromName":"Andreas Gruenbacher","fromEmail":"agruenba@redhat.com","sentAt":"2017-03-18T21:26:06Z","receivedAt":"2017-03-18T21:26:53Z","isPatch":true,"sender":{"key":"agruenba@redhat.com","avatar":null},"body":"On Sat, Mar 18, 2017 at 9:18 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Andreas Gruenbacher <agruenba@redhat.com> writes:\n>\n>> Hello,\n>>\n>> the log and rev-parse commands both support the rev^@ syntax which stands for\n>> all parents of rev.  The log command also supports ^rev^@ to exclude all of the\n>> parents of rev, but rev-parse does not.  Should this be fixed?\n>>\n>> If so, the following patch would be a start.\n>\n> Hmph, would ^A..B and ^A...B also be turned into B..A and B...A in a\n> similar way?  I think the latter would not make much sense but ^A..B\n> might.\n\nThe previous patch supports neither. I agree about ^A...B, and I don't\nthink supporting ^A..B is relevant.\n\n> In any case, accepting ^rev^@ may make sense nevertheless.\n\nAndreas\n"}]}