git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/7] parse-options: add precision handling for PARSE_OPT_CMDMODE

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 9, 2025, 15:56 UTC
Message-ID
<xmqqple9nysq.fsf@gitster.g>
In-Reply-To
<aG51nFpH6kMT95uf@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 26 quoted lines
>> 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.

Previous: Patrick SteinhardtNext: René Scharfe
Message 26 of 31 in “parse-options: add more precision handling”
  1. 0/6 parse-options: add more precision handlingRené Scharfe, Jun 29, 2025
  2. 1/6 parse-options: add precision handling for PARSE_OPT_CMDMODERené Scharfe, Jun 29, 2025
  3. Patrick SteinhardtJul 1, 2025
  4. René ScharfeJul 1, 2025
  5. 2/6 parse-options: add precision handling for OPTION_SET_INTRené Scharfe, Jun 29, 2025
  6. Patrick SteinhardtJul 1, 2025
  7. René ScharfeJul 1, 2025
  8. Patrick SteinhardtJul 2, 2025
  9. 3/6 parse-options: add precision handling for OPTION_BITRené Scharfe, Jun 29, 2025
  10. 4/6 parse-options: add precision handling for OPTION_NEGBITRené Scharfe, Jun 29, 2025
  11. 5/6 parse-options: add precision handling for OPTION_BITOPRené Scharfe, Jun 29, 2025
  12. Patrick SteinhardtJul 1, 2025
  13. René ScharfeJul 1, 2025
  14. Patrick SteinhardtJul 2, 2025
  15. 6/6 parse-options: add precision handling for OPTION_COUNTUPRené Scharfe, Jun 29, 2025
  16. Patrick SteinhardtJul 1, 2025
  17. René ScharfeJul 1, 2025
  18. Patrick SteinhardtJul 2, 2025
  19. 0/7 parse-options: add more precision handlingRené Scharfe, Jul 9, 2025
  20. 1/7 parse-options: require PARSE_OPT_NOARG for OPTION_BITOPRené Scharfe, Jul 9, 2025
  21. Patrick SteinhardtJul 9, 2025
  22. 2/7 parse-options: add precision handling for PARSE_OPT_CMDMODERené Scharfe, Jul 9, 2025
  23. Patrick SteinhardtJul 9, 2025
  24. René ScharfeJul 9, 2025
  25. Patrick SteinhardtJul 9, 2025
  26. Junio C HamanoJul 9, 2025
  27. 3/7 parse-options: add precision handling for OPTION_SET_INTRené Scharfe, Jul 9, 2025
  28. 4/7 parse-options: add precision handling for OPTION_BITRené Scharfe, Jul 9, 2025
  29. 5/7 parse-options: add precision handling for OPTION_NEGBITRené Scharfe, Jul 9, 2025
  30. 6/7 parse-options: add precision handling for OPTION_BITOPRené Scharfe, Jul 9, 2025
  31. 7/7 parse-options: add precision handling for OPTION_COUNTUPRené Scharfe, Jul 9, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.