parse-options: refactor flags for usage_with_options_internal

When reading or editing calls to usage_with_options_internal, it is difficult to tell what trailing "0, 0", "0, 1", "1, 0" arguments mean (NB there is never a "1, 1" case). Give the flags readable names to improve call-sites without changing any behavior. Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

D. Ben Knoble committed Aug 3, 2025 at 12:10 UTC fe54b9ef02cc8c5499fa83f8ed51a614b1014c0b
1 file changed +15 -5
parse-options.c
+15 -5
@@ -953,10 +953,16 @@ static void free_preprocessed_options(struct option *options)
953 free(options);
954 }
955
956 +#define USAGE_NORMAL 0
957 +#define USAGE_FULL 1
958 +#define USAGE_TO_STDOUT 0
959 +#define USAGE_TO_STDERR 1
960 +
961 static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
962 const char * const *,
963 const struct option *,
959 - int, int);
964 + int full_usage,
965 + int usage_to_stderr);
966
967 enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
968 const struct option *options,
@@ -1088,7 +1094,8 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
1094 }
1095
1096 if (internal_help && !strcmp(arg + 2, "help-all"))
1091 - return usage_with_options_internal(ctx, usagestr, options, 1, 0);
1097 + return usage_with_options_internal(ctx, usagestr, options,
1098 + USAGE_FULL, USAGE_TO_STDOUT);
1099 if (internal_help && !strcmp(arg + 2, "help"))
1100 goto show_usage;
1101 switch (parse_long_opt(ctx, arg + 2, options)) {
@@ -1129,7 +1136,8 @@ unknown:
1136 return PARSE_OPT_DONE;
1137
1138 show_usage:
1132 - return usage_with_options_internal(ctx, usagestr, options, 0, 0);
1139 + return usage_with_options_internal(ctx, usagestr, options,
1140 + USAGE_NORMAL, USAGE_TO_STDOUT);
1141 }
1142
1143 int parse_options_end(struct parse_opt_ctx_t *ctx)
@@ -1444,7 +1452,8 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
1452 void NORETURN usage_with_options(const char * const *usagestr,
1453 const struct option *opts)
1454 {
1447 - usage_with_options_internal(NULL, usagestr, opts, 0, 1);
1455 + usage_with_options_internal(NULL, usagestr, opts,
1456 + USAGE_NORMAL, USAGE_TO_STDERR);
1457 exit(129);
1458 }
1459
@@ -1453,7 +1462,8 @@ void show_usage_with_options_if_asked(int ac, const char **av,
1462 const struct option *opts)
1463 {
1464 if (ac == 2 && !strcmp(av[1], "-h")) {
1456 - usage_with_options_internal(NULL, usagestr, opts, 0, 0);
1465 + usage_with_options_internal(NULL, usagestr, opts,
1466 + USAGE_NORMAL, USAGE_TO_STDOUT);
1467 exit(129);
1468 }
1469 }