]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: simplify usage_padding()
authorRené Scharfe <l.s.r@web.de>
Sat, 5 Aug 2023 14:52:42 +0000 (16:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Aug 2023 00:16:51 +0000 (17:16 -0700)
c512643e67 (short help: allow a gap smaller than USAGE_GAP, 2023-07-18)
effectively did away with the two-space gap between options and their
description; one space is enough now.  Incorporate USAGE_GAP into
USAGE_OPTS_WIDTH, merge the two cases with enough space on the line and
incorporate the newline into the format for the remaining case.  The
output remains the same.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c

index 4a8d380ceb59e097668dc64418bfbbb77d8e3460..b00d868816a9ce0d32fa523279958cd250a30a84 100644 (file)
@@ -1025,21 +1025,14 @@ static int usage_indent(FILE *outfile)
        return fprintf(outfile, "    ");
 }
 
-#define USAGE_OPTS_WIDTH 24
-#define USAGE_GAP         2
+#define USAGE_OPTS_WIDTH 26
 
 static void usage_padding(FILE *outfile, size_t pos)
 {
-       int pad;
-       if (pos == USAGE_OPTS_WIDTH + 1)
-               pad = -1;
-       else if (pos <= USAGE_OPTS_WIDTH)
-               pad = USAGE_OPTS_WIDTH - pos;
-       else {
-               fputc('\n', outfile);
-               pad = USAGE_OPTS_WIDTH;
-       }
-       fprintf(outfile, "%*s", pad + USAGE_GAP, "");
+       if (pos < USAGE_OPTS_WIDTH)
+               fprintf(outfile, "%*s", USAGE_OPTS_WIDTH - (int)pos, "");
+       else
+               fprintf(outfile, "\n%*s", USAGE_OPTS_WIDTH, "");
 }
 
 static const struct option *find_option_by_long_name(const struct option *opts,