{"thread":{"id":"13635","subject":"[PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref","startedAt":"2008-05-23T14:13:05Z","lastAt":"2008-05-24T00:02:00Z","messageCount":2,"participants":["Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"77542","messageId":"4836D0F1.4090007@viscovery.net","threadId":"13635","inReplyTo":null,"subject":"[PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-05-23T14:13:05Z","receivedAt":"2008-05-23T14:13:05Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Johannes Sixt <johannes.sixt@telecom.at>\n\nThe intention of --symbolic-full-name is to not print anything if a\nrevision is not an exact ref. But this command:\n\n    $ git-rev-parse --symbolic-full-name --not master~1\n\nstill emitted a sole '^' to stdout (provided that there's no other ref at\nmaster~1). This fixes it.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n builtin-rev-parse.c |   18 ++++++++++++------\n 1 files changed, 12 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 0e59707..afa4d6d 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -96,6 +96,14 @@ static void show(const char *arg)\n \t\tputs(arg);\n }\n\n+/* Like show(), but with a negation prefix according to type */\n+static void show_with_type(int type, const char *arg)\n+{\n+\tif (type != show_type)\n+\t\tputchar('^');\n+\tshow(arg);\n+}\n+\n /* Output a revision, only if filter allows it */\n static void show_rev(int type, const unsigned char *sha1, const char *name)\n {\n@@ -104,8 +112,6 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)\n \tdef = NULL;\n \trevs_count++;\n\n-\tif (type != show_type)\n-\t\tputchar('^');\n \tif (symbolic && name) {\n \t\tif (symbolic == SHOW_SYMBOLIC_FULL) {\n \t\t\tunsigned char discard[20];\n@@ -122,20 +128,20 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)\n \t\t\t\t */\n \t\t\t\tbreak;\n \t\t\tcase 1: /* happy */\n-\t\t\t\tshow(full);\n+\t\t\t\tshow_with_type(type, full);\n \t\t\t\tbreak;\n \t\t\tdefault: /* ambiguous */\n \t\t\t\terror(\"refname '%s' is ambiguous\", name);\n \t\t\t\tbreak;\n \t\t\t}\n \t\t} else {\n-\t\t\tshow(name);\n+\t\t\tshow_with_type(type, name);\n \t\t}\n \t}\n \telse if (abbrev)\n-\t\tshow(find_unique_abbrev(sha1, abbrev));\n+\t\tshow_with_type(type, find_unique_abbrev(sha1, abbrev));\n \telse\n-\t\tshow(sha1_to_hex(sha1));\n+\t\tshow_with_type(type, sha1_to_hex(sha1));\n }\n\n /* Output a flag, only if filter allows it. */\n-- \n1.5.5.1.125.gb9f88\n"},{"id":"77623","messageId":"7v3ao8r2mf.fsf@gitster.siamese.dyndns.org","threadId":"13635","inReplyTo":"4836D0F1.4090007@viscovery.net","subject":"Re: [PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-24T00:02:00Z","receivedAt":"2008-05-24T00:02:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> From: Johannes Sixt <johannes.sixt@telecom.at>\n>\n> The intention of --symbolic-full-name is to not print anything if a\n> revision is not an exact ref. But this command:\n>\n>     $ git-rev-parse --symbolic-full-name --not master~1\n>\n> still emitted a sole '^' to stdout (provided that there's no other ref at\n> master~1).\n\nWell spotted.  Thanks.\n"}]}