aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-09-05 14:38:56 -0700
committerJunio C Hamano <gitster@pobox.com>2023-09-05 14:38:56 -0700
commit27e2ea97da6addecb7e2d3c5f97a668276f3e951 (patch)
treecfff890d60717fb2074a185def01e88bd3ae7765
parentThe fifth batch (diff)
parentparse-options: allow omitting option help text (diff)
downloadgit-27e2ea97da6addecb7e2d3c5f97a668276f3e951.tar.gz
git-27e2ea97da6addecb7e2d3c5f97a668276f3e951.zip
Merge branch 'rs/parse-options-help-text-is-optional'
It may be tempting to leave the help text NULL for a command line option that is either hidden or too obvious, but "git subcmd -h" and "git subcmd --help-all" would have segfaulted if done so. Now the help text is optional. * rs/parse-options-help-text-is-optional: parse-options: allow omitting option help text
-rw-r--r--parse-options.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/parse-options.c b/parse-options.c
index 76d2e76b49..e8e076c3a6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1186,14 +1186,15 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
continue;
}
- for (cp = _(opts->help); *cp; cp = np) {
+ for (cp = opts->help ? _(opts->help) : ""; *cp; cp = np) {
np = strchrnul(cp, '\n');
- usage_padding(outfile, pos);
- fprintf(outfile, "%.*s\n", (int)(np - cp), cp);
if (*np)
np++;
+ usage_padding(outfile, pos);
+ fwrite(cp, 1, np - cp, outfile);
pos = 0;
}
+ fputc('\n', outfile);
if (positive_name) {
if (find_option_by_long_name(all_opts, positive_name))