{"thread":{"id":"10723","subject":"[PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","startedAt":"2007-11-08T08:00:52Z","lastAt":"2007-11-09T09:12:19Z","messageCount":6,"participants":["Shawn O. Pearce","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"58815","messageId":"20071108080052.GB16690@spearce.org","threadId":"10723","inReplyTo":null,"subject":"[PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-11-08T08:00:52Z","receivedAt":"2007-11-08T08:00:52Z","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 --no-output can be\nused to 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..66ddbd3 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     [ \\--no-output ]\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+--no-output::\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..634b1f4 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+\"    --no-output\\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 noshow_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+\tnoshow_commit(commit);\n+}\n+\n+static void noshow_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 noshow_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+\tnoshow_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 nooutput = 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, \"--no-output\")) {\n+\t\t\tnooutput = 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\tnooutput ? noshow_commit : show_commit,\n+\t\tnooutput ? noshow_object : show_object);\n \n \treturn 0;\n }\n-- \n1.5.3.5.1590.gfadfad\n"},{"id":"58990","messageId":"20071108234418.GE4899@steel.home","threadId":"10723","inReplyTo":"20071108080052.GB16690@spearce.org","subject":"Re: [PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-08T23:44:18Z","receivedAt":"2007-11-08T23:44:18Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Shawn O. Pearce, Thu, Nov 08, 2007 09:00:52 +0100:\n> Some uses of git-rev-list are to run it with --objects to see if\n> a range of objects between two or more commits is fully connected\n> or not.  In such a case the caller doesn't care about the actual\n> object names or hash hints so formatting this data only for it to\n> be dumped to /dev/null by a redirect is a waste of CPU time.  If\n> all the caller needs is the exit status then --no-output can be\n> used to bypass the commit and object formatting.\n\nWe already have --quiet and even --exit-code.\n"},{"id":"58999","messageId":"7vejezx4b2.fsf@gitster.siamese.dyndns.org","threadId":"10723","inReplyTo":"20071108080052.GB16690@spearce.org","subject":"Re: [PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Junio C Hamano","fromEmail":"junio@pobox.com","sentAt":"2007-11-09T07:32:01Z","receivedAt":"2007-11-09T07:32:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\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\tnooutput ? noshow_commit : show_commit,\n> +\t\tnooutput ? noshow_object : show_object);\n>  \n>  \treturn 0;\n>  }\n\nThe function names noshow_xxx() looked a bit funny, but I do not\noffhand have better alternatives to offer.\n\nThis allows \"--bisect-vars --no-output\" and \"--bisect-all\n--bisect-vars --no-output\" but makes them behave differently.  I\ndo not think --no-output is useful with bisection anyway but\nmaybe it makes sense to forbid the combination?\n"},{"id":"59004","messageId":"20071109081204.GB2794@steel.home","threadId":"10723","inReplyTo":"7vejezx4b2.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-09T08:12:04Z","receivedAt":"2007-11-09T08:12:04Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Fri, Nov 09, 2007 08:32:01 +0100:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \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\tnooutput ? noshow_commit : show_commit,\n> > +\t\tnooutput ? noshow_object : show_object);\n> >  \n> >  \treturn 0;\n> >  }\n> \n> The function names noshow_xxx() looked a bit funny, but I do not\n> offhand have better alternatives to offer.\n\n\"hide\", \"skip\", \"ignore\"?\n"},{"id":"59007","messageId":"7vsl3fvlrb.fsf@gitster.siamese.dyndns.org","threadId":"10723","inReplyTo":"20071109081204.GB2794@steel.home","subject":"Re: [PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-09T08:58:00Z","receivedAt":"2007-11-09T08:58:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> Junio C Hamano, Fri, Nov 09, 2007 08:32:01 +0100:\n>> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>> \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\tnooutput ? noshow_commit : show_commit,\n>> > +\t\tnooutput ? noshow_object : show_object);\n>> >  \n>> >  \treturn 0;\n>> >  }\n>> \n>> The function names noshow_xxx() looked a bit funny, but I do not\n>> offhand have better alternatives to offer.\n>\n> \"hide\", \"skip\", \"ignore\"?\n\nBut look at what the functions do.  The original show_xxx() was\nto print and then process.  Shawn splitted them into show_xxx()\nand noshow_xxx(), leaft the printing part in the former, made\nthe former call the latter at the end, and moved the processing\nto the latter.  So it is not any of the three words.\n"},{"id":"59012","messageId":"20071109091219.GQ14735@spearce.org","threadId":"10723","inReplyTo":"7vsl3fvlrb.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/3] rev-list: Introduce --no-output to avoid /dev/null redirects","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-11-09T09:12:19Z","receivedAt":"2007-11-09T09:12:19Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> > Junio C Hamano, Fri, Nov 09, 2007 08:32:01 +0100:\n> >> \n> >> The function names noshow_xxx() looked a bit funny, but I do not\n> >> offhand have better alternatives to offer.\n> >\n> > \"hide\", \"skip\", \"ignore\"?\n> \n> But look at what the functions do.  The original show_xxx() was\n> to print and then process.  Shawn splitted them into show_xxx()\n> and noshow_xxx(), leaft the printing part in the former, made\n> the former call the latter at the end, and moved the processing\n> to the latter.  So it is not any of the three words.\n\nIn my latest patch series I've gone with \"finish_xxx()\" as it is\nfinishing our usage of that object.  I'll be resubmitting a new\nseries soon.\n\n-- \nShawn.\n"}]}