Re: [PATCH v2 2/7] parse-options: add precision handling for PARSE_OPT_CMDMODE
From: Junio C Hamano <hidden>
Date: 2025-07-09 15:56:08
Patrick Steinhardt [off-list ref] writes:
quoted
diff --git a/builtin/am.c b/builtin/am.c index a800003340..c9d925f7b9 100644 --- a/builtin/am.c +++ b/builtin/am.c@@ -2406,6 +2406,7 @@ int cmd_am(int argc, .type = OPTION_CALLBACK, .long_name = "show-current-patch", .value = &resume_mode, + .precision = sizeof(resume_mode), .argh = "(diff|raw)", .help = N_("show the patch being applied"), .flags = PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,diff --git a/parse-options.c b/parse-options.c index 68ff494492..ddac008a5e 100644 --- a/parse-options.c +++ b/parse-options.c@@ -68,6 +68,26 @@ static char *fix_filename(const char *prefix, const char *file) return prefix_filename_except_for_dash(prefix, file); } +static int do_get_int_value(const void *value, size_t precision, intmax_t *ret)Nit: after the fourth patch we have `do_get_int_value()` and `get_int_value()`, where the major difference is that the latter dies if we failed to parse the value. It might be easier to discern which is which if we called them `get_int_value()` and `get_int_value_or_die()`.
Seeing the symmetry between set_int_value() and do_get_int_value(), I tend to agree that it would be easier to remember what the latter does if it were named get_int_value(). I am not so sure about _or_die(), though. The only kind of error the current get_int_value() detects and acts on is the mismatched precision bug, which is a programmer error; there is no "die" but we call "BUG". get_int_value_with_precision_check() is quite a mouthful, but it is known that I am bad at naming X-<, so I dunno.