summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorBrandon Casey <drafnel@gmail.com>2017-09-24 21:08:05 -0700
committerJunio C Hamano <gitster@pobox.com>2017-09-25 14:35:53 +0900
commita6304fa4c2f57b08ec0acea9f91c188f284f8374 (patch)
tree99d61834e5b76b3ffa3d39f3628f0ef212213201 /parse-options.c
parent1a9bf1e176439d415b97fb8c5a556f69ea503877 (diff)
downloadgit-a6304fa4c2f57b08ec0acea9f91c188f284f8374.tar.gz
parse-options: only insert newline in help text if neededbc/rev-parse-parseopt-fix
Currently, when parse_options() produces a help message it always emits a blank line after the usage text to separate it from the options text. If the option spec does not define any switches, or only defines hidden switches that will not be displayed, then the help text will end up with two trailing blank lines instead of one. Let's defer emitting the blank line between the usage text and the options text until it is clear that the options section will not be empty. Fixes t1502.5, t1502.6. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/parse-options.c b/parse-options.c
index 6a03a5269a..fca7159646 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -581,6 +581,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
const struct option *opts, int full, int err)
{
FILE *outfile = err ? stderr : stdout;
+ int need_newline;
if (!usagestr)
return PARSE_OPT_HELP;
@@ -603,8 +604,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
usagestr++;
}
- if (opts->type != OPTION_GROUP)
- fputc('\n', outfile);
+ need_newline = 1;
for (; opts->type != OPTION_END; opts++) {
size_t pos;
@@ -612,6 +612,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
if (opts->type == OPTION_GROUP) {
fputc('\n', outfile);
+ need_newline = 0;
if (*opts->help)
fprintf(outfile, "%s\n", _(opts->help));
continue;
@@ -619,6 +620,11 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
if (!full && (opts->flags & PARSE_OPT_HIDDEN))
continue;
+ if (need_newline) {
+ fputc('\n', outfile);
+ need_newline = 0;
+ }
+
pos = fprintf(outfile, " ");
if (opts->short_name) {
if (opts->flags & PARSE_OPT_NODASH)