{"thread":{"id":"13267","subject":"[PATCH] rev-parse: teach \"--verify\" to be quiet when using \"-q\" or \"--quiet\"","startedAt":"2008-04-26T11:57:23Z","lastAt":"2008-04-27T06:16:59Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"75214","messageId":"20080426135723.2b9e7c16.chriscool@tuxfamily.org","threadId":"13267","inReplyTo":null,"subject":"[PATCH] rev-parse: teach \"--verify\" to be quiet when using \"-q\" or \"--quiet\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-04-26T11:57:23Z","receivedAt":"2008-04-26T11:57:23Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Currently \"git rev-parse --verify <something>\" is often used with\nits error output redirected to /dev/null. This patch makes it\neasier to do that.\n\nThe -q|--quiet option is designed to work the same way as it does\nfor \"git symbolic-ref\".\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-rev-parse.txt |    5 +++++\n builtin-rev-parse.c             |   20 ++++++++++++++++----\n 2 files changed, 21 insertions(+), 4 deletions(-)\n\n\tBy the way it's strange that for example:\n\n\t$ git rev-parse --verify <good-rev> <junk>\n\n\tworks whatever <junk> is, as long as <good-rev> can be\n\tparsed.\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 6513c2e..110e7ba 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -52,6 +52,11 @@ OPTIONS\n \tThe parameter given must be usable as a single, valid\n \tobject name.  Otherwise barf and abort.\n \n+-q, --quiet::\n+\tOnly meaningful in `--verify` mode. Do not output an error\n+\tmessage if the first argument is not a valid object name;\n+\tinstead exit with non-zero status silently.\n+\n --sq::\n \tUsually the output is made one line per flag and\n \tparameter.  This option makes output a single line,\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 0351d54..9384a99 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -365,9 +365,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n+static void die_no_single_rev(int quiet)\n+{\n+\tif (quiet)\n+\t\texit(1);\n+\telse\n+\t\tdie(\"Needed a single revision\");\n+}\n+\n int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n {\n-\tint i, as_is = 0, verify = 0;\n+\tint i, as_is = 0, verify = 0, quiet = 0;\n \tunsigned char sha1[20];\n \n \tif (argc > 1 && !strcmp(\"--parseopt\", argv[1]))\n@@ -432,6 +440,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tverify = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--quiet\") || !strcmp(arg, \"-q\")) {\n+\t\t\t\tquiet = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--short\") ||\n \t\t\t    !prefixcmp(arg, \"--short=\")) {\n \t\t\t\tfilter &= ~(DO_FLAGS|DO_NOREV);\n@@ -549,7 +561,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (show_flag(arg) && verify)\n-\t\t\t\tdie(\"Needed a single revision\");\n+\t\t\t\tdie_no_single_rev(quiet);\n \t\t\tcontinue;\n \t\t}\n \n@@ -568,11 +580,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\tif (!show_file(arg))\n \t\t\tcontinue;\n \t\tif (verify)\n-\t\t\tdie(\"Needed a single revision\");\n+\t\t\tdie_no_single_rev(quiet);\n \t\tverify_filename(prefix, arg);\n \t}\n \tshow_default();\n \tif (verify && revs_count != 1)\n-\t\tdie(\"Needed a single revision\");\n+\t\tdie_no_single_rev(quiet);\n \treturn 0;\n }\n-- \n1.5.5.130.g68d41\n"},{"id":"75263","messageId":"7vabjfizz8.fsf@gitster.siamese.dyndns.org","threadId":"13267","inReplyTo":"20080426135723.2b9e7c16.chriscool@tuxfamily.org","subject":"Re: [PATCH] rev-parse: teach \"--verify\" to be quiet when using \"-q\" or \"--quiet\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-04-27T06:16:59Z","receivedAt":"2008-04-27T06:16:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Currently \"git rev-parse --verify <something>\" is often used with\n> its error output redirected to /dev/null. This patch makes it\n> easier to do that.\n>\n> The -q|--quiet option is designed to work the same way as it does\n> for \"git symbolic-ref\".\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  Documentation/git-rev-parse.txt |    5 +++++\n>  builtin-rev-parse.c             |   20 ++++++++++++++++----\n>  2 files changed, 21 insertions(+), 4 deletions(-)\n>\n> \tBy the way it's strange that for example:\n>\n> \t$ git rev-parse --verify <good-rev> <junk>\n>\n> \tworks whatever <junk> is, as long as <good-rev> can be\n> \tparsed.\n\nVery much so.  The earlier plumbing programs tend to have this \"works if\nyou give correct input but sometimes ignores bogosity\" tendency.  They are\nloose not by design, and we should be able to tighten without worrying\nabout breaking existing scripts.\n"}]}