{"thread":{"id":"10758","subject":"[PATCH 09/11] rev-list: Introduce --quiet to avoid /dev/null redirects","startedAt":"2007-11-09T11:06:40Z","lastAt":"2007-11-09T11:06:40Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"59027","messageId":"20071109110640.GI19368@spearce.org","threadId":"10758","inReplyTo":null,"subject":"[PATCH 09/11] rev-list: Introduce --quiet to avoid /dev/null redirects","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-11-09T11:06:40Z","receivedAt":"2007-11-09T11:06:40Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Some uses of git-rev-list are to run it with --objects to see if\na range of objects between two or more commits is fully connected\nor not.  In such a case the caller doesn't care about the actual\nobject names or hash hints so formatting this data only for it to\nbe dumped to /dev/null by a redirect is a waste of CPU time.  If\nall the caller needs is the exit status then --quiet can be used\nto bypass the commit and object formatting.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/git-rev-list.txt |    9 +++++++++\n builtin-rev-list.c             |   26 ++++++++++++++++++++++----\n 2 files changed, 31 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt\nindex 4852804..989fbf3 100644\n--- a/Documentation/git-rev-list.txt\n+++ b/Documentation/git-rev-list.txt\n@@ -20,6 +20,7 @@ SYNOPSIS\n \t     [ \\--not ]\n \t     [ \\--all ]\n \t     [ \\--stdin ]\n+\t     [ \\--quiet ]\n \t     [ \\--topo-order ]\n \t     [ \\--parents ]\n \t     [ \\--timestamp ]\n@@ -270,6 +271,14 @@ limiting may be applied.\n \tIn addition to the '<commit>' listed on the command\n \tline, read them from the standard input.\n \n+--quiet::\n+\n+\tDon't print anything to standard output.  This form of\n+\tgit-rev-list is primarly meant to allow the caller to\n+\ttest the exit status to see if a range of objects is fully\n+\tconnected (or not).  It is faster than redirecting stdout\n+\tto /dev/null as the output does not have to be formatted.\n+\n --cherry-pick::\n \n \tOmit any commit that introduces the same change as\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 2dec887..d67724c 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -26,6 +26,7 @@ static const char rev_list_usage[] =\n \"    --remove-empty\\n\"\n \"    --all\\n\"\n \"    --stdin\\n\"\n+\"    --quiet\\n\"\n \"  ordering output:\\n\"\n \"    --topo-order\\n\"\n \"    --date-order\\n\"\n@@ -50,6 +51,7 @@ static int show_timestamp;\n static int hdr_termination;\n static const char *header_prefix;\n \n+static void finish_commit(struct commit *commit);\n static void show_commit(struct commit *commit)\n {\n \tif (show_timestamp)\n@@ -93,6 +95,11 @@ static void show_commit(struct commit *commit)\n \t\tstrbuf_release(&buf);\n \t}\n \tmaybe_flush_or_die(stdout, \"stdout\");\n+\tfinish_commit(commit);\n+}\n+\n+static void finish_commit(struct commit *commit)\n+{\n \tif (commit->parents) {\n \t\tfree_commit_list(commit->parents);\n \t\tcommit->parents = NULL;\n@@ -101,6 +108,12 @@ static void show_commit(struct commit *commit)\n \tcommit->buffer = NULL;\n }\n \n+static void finish_object(struct object_array_entry *p)\n+{\n+\tif (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))\n+\t\tdie(\"missing blob object '%s'\", sha1_to_hex(p->item->sha1));\n+}\n+\n static void show_object(struct object_array_entry *p)\n {\n \t/* An object with name \"foo\\n0000000...\" can be used to\n@@ -108,9 +121,7 @@ static void show_object(struct object_array_entry *p)\n \t */\n \tconst char *ep = strchr(p->name, '\\n');\n \n-\tif (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))\n-\t\tdie(\"missing blob object '%s'\", sha1_to_hex(p->item->sha1));\n-\n+\tfinish_object(p);\n \tif (ep) {\n \t\tprintf(\"%s %.*s\\n\", sha1_to_hex(p->item->sha1),\n \t\t       (int) (ep - p->name),\n@@ -527,6 +538,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)\n \tint read_from_stdin = 0;\n \tint bisect_show_vars = 0;\n \tint bisect_find_all = 0;\n+\tint quiet = 0;\n \n \tgit_config(git_default_config);\n \tinit_revisions(&revs, prefix);\n@@ -565,6 +577,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)\n \t\t\tread_revisions_from_stdin(&revs);\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--quiet\")) {\n+\t\t\tquiet = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tusage(rev_list_usage);\n \n \t}\n@@ -640,7 +656,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\ttraverse_commit_list(&revs, show_commit, show_object);\n+\ttraverse_commit_list(&revs,\n+\t\tquiet ? finish_commit : show_commit,\n+\t\tquiet ? finish_object : show_object);\n \n \treturn 0;\n }\n-- \n1.5.3.5.1622.g41d10\n"}]}