{"thread":{"id":"46667","subject":"[PATCH] usage_with_options: omit double new line on empty option list","startedAt":"2017-08-25T16:48:46Z","lastAt":"2017-08-25T17:31:56Z","messageCount":5,"participants":["Stefan Beller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"327191","messageId":"20170825164837.30118-1-sbeller@google.com","threadId":"46667","inReplyTo":null,"subject":"[PATCH] usage_with_options: omit double new line on empty option list","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-08-25T16:48:37Z","receivedAt":"2017-08-25T16:48:46Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Currently the worktree command gives its usage, when no subcommand is\ngiven. However there are no general options, all options are related to\nthe subcommands itself, such that:\n\n    $ git worktree\n    usage: git worktree add [<options>] <path> [<branch>]\n       or: git worktree list [<options>]\n       or: git worktree lock [<options>] <path>\n       or: git worktree prune [<options>]\n       or: git worktree unlock <path>\n\n\n    $\n\nNote the two empty lines at the end of the usage string. This is because\nthe toplevel usage is printed with an empty options list.\n\nOnly print one new line after the usage string if the option list is empty.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n parse-options.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 0dd9fc6a0d..1307c82861 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,\n \t\tusagestr++;\n \t}\n \n-\tif (opts->type != OPTION_GROUP)\n+\tif (opts->type != OPTION_GROUP && opts->type != OPTION_END)\n \t\tfputc('\\n', outfile);\n \n \tfor (; opts->type != OPTION_END; opts++) {\n-- \n2.14.0.rc0.3.g6c2e499285\n\n"},{"id":"327197","messageId":"xmqq7exrtvl1.fsf@gitster.mtv.corp.google.com","threadId":"46667","inReplyTo":"20170825164837.30118-1-sbeller@google.com","subject":"Re: [PATCH] usage_with_options: omit double new line on empty option list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-25T17:18:18Z","receivedAt":"2017-08-25T17:18:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> Currently the worktree command gives its usage, when no subcommand is\n> given. However there are no general options, all options are related to\n> the subcommands itself, such that:\n>\n>     $ git worktree\n>     usage: git worktree add [<options>] <path> [<branch>]\n>        or: git worktree list [<options>]\n>        or: git worktree lock [<options>] <path>\n>        or: git worktree prune [<options>]\n>        or: git worktree unlock <path>\n>\n>\n>     $\n>\n> Note the two empty lines at the end of the usage string. This is because\n> the toplevel usage is printed with an empty options list.\n>\n> Only print one new line after the usage string if the option list is empty.\n\nGood find.  Shouldn't the last word in the sentence \"non-empty\", though?\n\n>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> ---\n>  parse-options.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/parse-options.c b/parse-options.c\n> index 0dd9fc6a0d..1307c82861 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,\n>  \t\tusagestr++;\n>  \t}\n>  \n> -\tif (opts->type != OPTION_GROUP)\n> +\tif (opts->type != OPTION_GROUP && opts->type != OPTION_END)\n>  \t\tfputc('\\n', outfile);\n>  \n>  \tfor (; opts->type != OPTION_END; opts++) {\n"},{"id":"327198","messageId":"CAGZ79ka-PSt95TjVaUVf8yTZCdP8XuSfhJjBowJmgJbV2t0Tkg@mail.gmail.com","threadId":"46667","inReplyTo":"xmqq7exrtvl1.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] usage_with_options: omit double new line on empty option list","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-08-25T17:19:47Z","receivedAt":"2017-08-25T17:19:53Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Aug 25, 2017 at 10:18 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> Currently the worktree command gives its usage, when no subcommand is\n>> given. However there are no general options, all options are related to\n>> the subcommands itself, such that:\n>>\n>>     $ git worktree\n>>     usage: git worktree add [<options>] <path> [<branch>]\n>>        or: git worktree list [<options>]\n>>        or: git worktree lock [<options>] <path>\n>>        or: git worktree prune [<options>]\n>>        or: git worktree unlock <path>\n>>\n>>\n>>     $\n>>\n>> Note the two empty lines at the end of the usage string. This is because\n>> the toplevel usage is printed with an empty options list.\n>>\n>> Only print one new line after the usage string if the option list is empty.\n>\n> Good find.  Shouldn't the last word in the sentence \"non-empty\", though?\\\n\nYes.\n\nOriginally I wrote a lot more and then deleted it all, mixing up the negations\nof what I was trying to say.\n"},{"id":"327199","messageId":"xmqq378ftvfs.fsf@gitster.mtv.corp.google.com","threadId":"46667","inReplyTo":"xmqq7exrtvl1.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] usage_with_options: omit double new line on empty option list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-25T17:21:27Z","receivedAt":"2017-08-25T17:21:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> Currently the worktree command gives its usage, when no subcommand is\n>> given. However there are no general options, all options are related to\n>> the subcommands itself, such that:\n>>\n>>     $ git worktree\n>>     usage: git worktree add [<options>] <path> [<branch>]\n>>        or: git worktree list [<options>]\n>>        or: git worktree lock [<options>] <path>\n>>        or: git worktree prune [<options>]\n>>        or: git worktree unlock <path>\n>>\n>>\n>>     $\n>>\n>> Note the two empty lines at the end of the usage string. This is because\n>> the toplevel usage is printed with an empty options list.\n>>\n>> Only print one new line after the usage string if the option list is empty.\n>\n> Good find.  Shouldn't the last word in the sentence \"non-empty\", though?\n\nAh, the \"do this\" part was hard to understand and I misread it.  I\nthought you were saying \"only give a blank if we have something that\nneed to be separated from the stuff above\".\n\nSo what you wrote above is not incorrect per-se, but I think it is\nprone to be misunderstood.\n\n>\n>>\n>> Signed-off-by: Stefan Beller <sbeller@google.com>\n>> ---\n>>  parse-options.c | 2 +-\n>>  1 file changed, 1 insertion(+), 1 deletion(-)\n>>\n>> diff --git a/parse-options.c b/parse-options.c\n>> index 0dd9fc6a0d..1307c82861 100644\n>> --- a/parse-options.c\n>> +++ b/parse-options.c\n>> @@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,\n>>  \t\tusagestr++;\n>>  \t}\n>>  \n>> -\tif (opts->type != OPTION_GROUP)\n>> +\tif (opts->type != OPTION_GROUP && opts->type != OPTION_END)\n>>  \t\tfputc('\\n', outfile);\n>>  \n>>  \tfor (; opts->type != OPTION_END; opts++) {\n"},{"id":"327201","messageId":"xmqqy3q7sge2.fsf@gitster.mtv.corp.google.com","threadId":"46667","inReplyTo":"20170825164837.30118-1-sbeller@google.com","subject":"Re: [PATCH] usage_with_options: omit double new line on empty option list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-25T17:31:49Z","receivedAt":"2017-08-25T17:31:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> Currently the worktree command gives its usage, when no subcommand is\n> given. However there are no general options, all options are related to\n> the subcommands itself, such that:\n>\n>     $ git worktree\n>     usage: git worktree add [<options>] <path> [<branch>]\n>        or: git worktree list [<options>]\n>        or: git worktree lock [<options>] <path>\n>        or: git worktree prune [<options>]\n>        or: git worktree unlock <path>\n>\n>\n>     $\n>\n> Note the two empty lines at the end of the usage string. This is because\n> the toplevel usage is printed with an empty options list.\n\nI have this feeling that this patch may not be sufficient.  \n\nThe reason for the first blank line is because we unconditionally\nemit one, expecting that we would have a list of options to show and\nwant to separate the usage from that list, and the fix in this patch\nis correct---it is the right way to suppress it.\n\nBut why do we need the second blank line in this case?  There is a\nsimilar unconditional LF near the end of this function.  Is somebody\nelse (other than usage_with_options() which will exit immeidately)\ncalls this function and expects to say something more after what\nthis function said, and is this extra blank line at the end is to\nprepare for that caller?\n\n> Only print one new line after the usage string if the option list is empty.\n>\n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> ---\n>  parse-options.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/parse-options.c b/parse-options.c\n> index 0dd9fc6a0d..1307c82861 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,\n>  \t\tusagestr++;\n>  \t}\n>  \n> -\tif (opts->type != OPTION_GROUP)\n> +\tif (opts->type != OPTION_GROUP && opts->type != OPTION_END)\n>  \t\tfputc('\\n', outfile);\n>  \n>  \tfor (; opts->type != OPTION_END; opts++) {\n"}]}