{"thread":{"id":"27194","subject":"[PATCH/RFC] Implemented return value for rev-list --quiet","startedAt":"2011-04-26T22:36:37Z","lastAt":"2011-04-26T23:47:46Z","messageCount":4,"participants":["Jonas Gehring","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"166417","messageId":"4DB748F5.4050300@boolsoft.org","threadId":"27194","inReplyTo":null,"subject":"[PATCH/RFC] Implemented return value for rev-list --quiet","fromName":"Jonas Gehring","fromEmail":"jonas.gehring@boolsoft.org","sentAt":"2011-04-26T22:36:37Z","receivedAt":"2011-04-26T22:36:37Z","isPatch":true,"sender":{"key":"jonas.gehring@boolsoft.org","avatar":null},"body":"If --quiet is given, the program will return non-zero if the traversed\ncommit set was empty. This way, rev-list can be used to check commit\nancestry as described by the documentation for --quiet.\n\n\"Non-zero\" is implemented as 1 in order to avoid confusion with the\nusual 128 for die_builtin().\n\nSigned-off-by: Jonas Gehring <jonas.gehring@boolsoft.org>\n---\n builtin/rev-list.c        |    8 ++++++++\n revision.h                |    1 +\n t/t6041-rev-list-quiet.sh |   27 +++++++++++++++++++++++++++\n 3 files changed, 36 insertions(+), 0 deletions(-)\n create mode 100755 t/t6041-rev-list-quiet.sh\n\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex 9bfb942..001d6af 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -157,12 +157,17 @@ static void show_commit(struct commit *commit, void *data)\n \n static void finish_commit(struct commit *commit, void *data)\n {\n+\tstruct rev_list_info *info = data;\n+\tstruct rev_info *revs = info->revs;\n+\n \tif (commit->parents) {\n \t\tfree_commit_list(commit->parents);\n \t\tcommit->parents = NULL;\n \t}\n \tfree(commit->buffer);\n \tcommit->buffer = NULL;\n+\n+\trevs->count_finished++;\n }\n \n static void finish_object(struct object *obj, const struct name_path *path, const char *name)\n@@ -412,5 +417,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(\"%d\\n\", revs.count_left + revs.count_right);\n \t}\n \n+\tif (quiet)\n+\t\t/* Return non-zero if no commits have been traversed. */\n+\t\treturn (revs.count_finished == 0 ? 1 : 0);\n \treturn 0;\n }\ndiff --git a/revision.h b/revision.h\nindex 9fd8f30..ddc35d2 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -141,6 +141,7 @@ struct rev_info {\n \t/* commit counts */\n \tint count_left;\n \tint count_right;\n+\tint count_finished;\n };\n \n #define REV_TREE_SAME\t\t0\ndiff --git a/t/t6041-rev-list-quiet.sh b/t/t6041-rev-list-quiet.sh\nnew file mode 100755\nindex 0000000..6cb9120\n--- /dev/null\n+++ b/t/t6041-rev-list-quiet.sh\n@@ -0,0 +1,27 @@\n+#!/bin/sh\n+\n+test_description='Non-zero return value for empty commit sets and --quiet'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\techo >fileA fileA\n+\tgit add fileA\n+\tgit commit -a -m \"Initial\"\n+\techo >fileA fileA modified\n+\tgit commit -a -m \"fileA modified\"\n+'\n+\n+test_expect_success 'not quiet' '\n+\ttest $(git rev-list master | wc -l) = 2 &&\n+\ttest $(git rev-list master..master^ | wc -l) = 0 &&\n+\ttest $(git rev-list master^..master | wc -l) = 1\n+'\n+\n+test_expect_success '--quiet' '\n+\ttest $(git rev-list --quiet master; echo $?) = 0 &&\n+\ttest $(git rev-list --quiet master..master^; echo $?) != 0 &&\n+\ttest $(git rev-list --quiet master^..master; echo $?) = 0\n+'\n+\n+test_done\n-- \n1.7.4.4\n"},{"id":"166418","messageId":"7vwrigbor6.fsf@alter.siamese.dyndns.org","threadId":"27194","inReplyTo":"4DB748F5.4050300@boolsoft.org","subject":"Re: [PATCH/RFC] Implemented return value for rev-list --quiet","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-26T23:02:05Z","receivedAt":"2011-04-26T23:02:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonas Gehring <jonas.gehring@boolsoft.org> writes:\n\n> If --quiet is given, the program will return non-zero if the traversed\n> commit set was empty. This way, rev-list can be used to check commit\n> ancestry as described by the documentation for --quiet.\n\nGiven two commits A and X, \"rev-list --objects A..X\" is a way to make sure\nthat everything between A and X exists.  When your ref is at A, you are\ntrying to fetch from a remote that wants to update you to X, and when you\nhappen to have X already, you run that command and see if it dies due to\ndisconnect in the history.  If it doesn't, you know you do not actually\nhave to transfer anything (this is called quickfetch test).  For the\npurpose of this test, the caller is not interested in the output, so it is\nperfectly OK to give --quiet to the command.\n\nIn reality, you would feed all the refs you locally have on the negative\nside (i.e. \"rev-list --objects --quiet X --not A B C D ...\") to check if X\nis connected to something you know you have a connected history behind it.\nReturning non-zero to a quickfetch test when X is reachable from some of\nyour refs will break existing scripts.\n"},{"id":"166419","messageId":"4DB755D2.10303@boolsoft.org","threadId":"27194","inReplyTo":"7vwrigbor6.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] Implemented return value for rev-list --quiet","fromName":"Jonas Gehring","fromEmail":"jonas.gehring@boolsoft.org","sentAt":"2011-04-26T23:31:30Z","receivedAt":"2011-04-26T23:31:30Z","isPatch":true,"sender":{"key":"jonas.gehring@boolsoft.org","avatar":null},"body":"On 04/27/2011 01:02 AM, Junio C Hamano wrote:\n> Given two commits A and X, \"rev-list --objects A..X\" is a way to make sure\n> that everything between A and X exists.\n\nThank you for this explanation, this really cleared up the intended\nusage of --quiet for me. I wanted to use it for ancestry testing of two\ncommits, noticed the hard-coded return value of '0' in cmd_rev_list()\nand thought that the implementation is probably missing.\n\nAfter some additional digging, I realized that git-merge-base is the\nright tool for my task.\n\nRegards,\nJonas\n"},{"id":"166420","messageId":"7vpqo8bmn1.fsf@alter.siamese.dyndns.org","threadId":"27194","inReplyTo":"4DB755D2.10303@boolsoft.org","subject":"Re: [PATCH/RFC] Implemented return value for rev-list --quiet","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-26T23:47:46Z","receivedAt":"2011-04-26T23:47:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonas Gehring <jonas.gehring@boolsoft.org> writes:\n\n> Thank you for this explanation, this really cleared up the intended\n> ... I wanted to use it for ancestry testing of two\n> commits,...\n>\n> After some additional digging, I realized that git-merge-base is the\n> right tool for my task.\n\nEither\n\n\ttest \"$(git merge-base A B)\" = \"$(git rev-parse A)\"\n\nor\n\n\ttest -z \"$(git rev-list -1 A..B)\"\n\nwould be valid ways to see if A is an ancestor of B.\n"}]}