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

Re: [PATCH 07/10] commit-graph: stop using optname()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 1, 2021, 13:16 UTC
Message-ID
<87tui0ri8j.fsf@evledraar.gmail.com>
In-Reply-To
<YVSiOMaKNoDZ3SlO@nand.local>
On Wed, Sep 29 2021, Taylor Blau wrote:
Show 18 quoted lines
> On Tue, Sep 28, 2021 at 03:14:28PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> Stop using optname() in builtin/commit-graph.c to emit an error with
>> the --max-new-filters option. This changes code added in 809e0327f57
>> (builtin/commit-graph.c: introduce '--max-new-filters=<n>',
>> 2020-09-18).
>>
>> See 9440b831ad5 (parse-options: replace opterror() with optname(),
>> 2018-11-10) for why using optname() like this is considered bad,
>> i.e. it's assembling human-readable output piecemeal, and the "option
>> `X'" at the start can't be translated.
>
> In fact, using optname there (which blames to me) was a mistake for an
> even simpler reason: there is no abbreviated form of
> `--max-new-filters`, and we know that by the time this error is emitted
> that we got the positive form instead of `--no-max-new-filters`.
>
> So we could have just written the option's name verbatim, and given
> translators something easier to work with.
As an aside: Did you intend for this to work:
    git commit-graph write --max-new-filters=123 --no-max-new-filters

It's in the docstring, but then you're using OPT_CALLBACK_F(), but just to set a flag of "0", so a OPT_CALLBACK() would do, along with a PARSE_OPT_NONEG.

I'm about to re-roll this, but won't change that, but I think it probably makes sense as a follow-on cleanuup.

I think you'd probably want a BUG_ON_OPT_NEG() instead for the "unset" handling here. This seems like another case of mixing the state of parse_options() with that of flags for the underlying API that we discussed elsewhere either for this command or multi-pack-index. But more on that below...

Also the usage if --no-* is wanted should not be:
    [--no-max-new-filters] [--max-new-filters <n>]
But is currently:
    [--[no-]max-new-filters <n>]
Which says the --no-* will take the <n>, but it won't.
Show 25 quoted lines
>> It didn't matter in this case, but this code was also buggy in its use
>> of "opt->flags" to optname(), that function expects flags, but not
>> *those* flags.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  builtin/commit-graph.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
>> index 0386f5c7755..36552db89fe 100644
>> --- a/builtin/commit-graph.c
>> +++ b/builtin/commit-graph.c
>> @@ -172,8 +172,7 @@ static int write_option_max_new_filters(const struct option *opt,
>>  		const char *s;
>>  		*to = strtol(arg, (char **)&s, 10);
>>  		if (*s)
>> -			return error(_("%s expects a numerical value"),
>> -				     optname(opt, opt->flags));
>> +			return error(_("option `max-new-filters' expects a numerical value"));
>
> Makes sense. The `'-style quoting is still weird to me. It is consistent
> with some of the conversions in 9440b831ad5, but most importantly with
> how parse-options.c:get_value() behaves (because it calls optname
> underneath).
Yeah I just reproduced the existing output here.
Show 5 quoted lines
> (This has nothing to do with your patch, but I thought the custom
> write_option_max_new_filters callback was weird when I wrote it. It's
> working around trying to make the negated form set a value to `-1`
> instead of `0`. But it's an annoying hack, because we have to call
> strtol() ourselves when we're not negated. *sigh*).

...on the "more on that below", looks like you intended that -1 handling in some way, but I don't really see why yet, other than the "mixing the state" I noted above.

Previous: Taylor BlauNext: Ævar Arnfjörð Bjarmason
Message 18 of 61 in “fix bug, use existing enums”
  1. 00/10 fix bug, use existing enumsÆvar Arnfjörð Bjarmason, Sep 28, 2021
  2. 01/10 parse-options.h: move PARSE_OPT_SHELL_EVAL between enumsÆvar Arnfjörð Bjarmason, Sep 28, 2021
  3. 02/10 parse-options.[ch]: consistently use "enum parse_opt_flags"Ævar Arnfjörð Bjarmason, Sep 28, 2021
  4. Junio C HamanoSep 29, 2021
  5. Ævar Arnfjörð BjarmasonSep 29, 2021
  6. Junio C HamanoSep 29, 2021
  7. Junio C HamanoSep 29, 2021
  8. 03/10 parse-options.[ch]: consistently use "enum parse_opt_result"Ævar Arnfjörð Bjarmason, Sep 28, 2021
  9. Junio C HamanoSep 29, 2021
  10. 04/10 parse-options.c: use exhaustive "case" arms for "enum parse_opt_type"Ævar Arnfjörð Bjarmason, Sep 28, 2021
  11. Junio C HamanoSep 29, 2021
  12. Ævar Arnfjörð BjarmasonSep 29, 2021
  13. Junio C HamanoSep 29, 2021
  14. 05/10 parse-options.h: make the "flags" in "struct option" an enumÆvar Arnfjörð Bjarmason, Sep 28, 2021
  15. Junio C HamanoSep 29, 2021
  16. 07/10 commit-graph: stop using optname()Ævar Arnfjörð Bjarmason, Sep 28, 2021
  17. Taylor BlauSep 29, 2021
  18. Ævar Arnfjörð BjarmasonOct 1, 2021
  19. 06/10 parse-options.c: move optname() earlier in the fileÆvar Arnfjörð Bjarmason, Sep 28, 2021
  20. 08/10 parse-options.[ch]: make opt{bug,name}() "static"Ævar Arnfjörð Bjarmason, Sep 28, 2021
  21. 09/10 parse-options tests: test optname() outputÆvar Arnfjörð Bjarmason, Sep 28, 2021
  22. 10/10 parse-options: change OPT_{SHORT,UNSET} to an enumÆvar Arnfjörð Bjarmason, Sep 28, 2021
  23. Junio C HamanoSep 29, 2021
  24. 00/11 fix bug, use existing enumsÆvar Arnfjörð Bjarmason, Oct 1, 2021
  25. 01/11 parse-options.h: move PARSE_OPT_SHELL_EVAL between enumsÆvar Arnfjörð Bjarmason, Oct 1, 2021
  26. 02/11 parse-options.[ch]: consistently use "enum parse_opt_flags"Ævar Arnfjörð Bjarmason, Oct 1, 2021
  27. Junio C HamanoOct 1, 2021
  28. 03/11 parse-options.[ch]: consistently use "enum parse_opt_result"Ævar Arnfjörð Bjarmason, Oct 1, 2021
  29. 04/11 parse-options.c: use exhaustive "case" arms for "enum parse_opt_result"Ævar Arnfjörð Bjarmason, Oct 1, 2021
  30. 05/11 parse-options.c: use exhaustive "case" arms for "enum parse_opt_type"Ævar Arnfjörð Bjarmason, Oct 1, 2021
  31. 06/11 parse-options.h: make the "flags" in "struct option" an enumÆvar Arnfjörð Bjarmason, Oct 1, 2021
  32. 07/11 parse-options.c: move optname() earlier in the fileÆvar Arnfjörð Bjarmason, Oct 1, 2021
  33. 08/11 commit-graph: stop using optname()Ævar Arnfjörð Bjarmason, Oct 1, 2021
  34. René ScharfeOct 1, 2021
  35. 09/11 parse-options.[ch]: make opt{bug,name}() "static"Ævar Arnfjörð Bjarmason, Oct 1, 2021
  36. 10/11 parse-options tests: test optname() outputÆvar Arnfjörð Bjarmason, Oct 1, 2021
  37. 11/11 parse-options: change OPT_{SHORT,UNSET} to an enumÆvar Arnfjörð Bjarmason, Oct 1, 2021
  38. Junio C HamanoOct 1, 2021
  39. Junio C HamanoOct 1, 2021
  40. 00/10 fix bug, use more enumsÆvar Arnfjörð Bjarmason, Oct 8, 2021
  41. 01/10 parse-options.h: move PARSE_OPT_SHELL_EVAL between enumsÆvar Arnfjörð Bjarmason, Oct 8, 2021
  42. 03/10 parse-options.[ch]: consistently use "enum parse_opt_result"Ævar Arnfjörð Bjarmason, Oct 8, 2021
  43. SZEDER GáborNov 6, 2021
  44. Ævar Arnfjörð BjarmasonNov 6, 2021
  45. 0/2 parse-options.[ch]: enum fixup & enum nitÆvar Arnfjörð Bjarmason, Nov 9, 2021
  46. 1/2 parse-options.[ch]: revert use of "enum" for parse_options()Ævar Arnfjörð Bjarmason, Nov 9, 2021
  47. Junio C HamanoNov 9, 2021
  48. 2/2 parse-options.c: use "enum parse_opt_result" for parse_nodash_opt()Ævar Arnfjörð Bjarmason, Nov 9, 2021
  49. Junio C HamanoNov 9, 2021
  50. Ævar Arnfjörð BjarmasonNov 9, 2021
  51. Junio C HamanoNov 9, 2021
  52. parse-options.c: use "enum parse_opt_result" for parse_nodash_opt()Ævar Arnfjörð Bjarmason, Nov 10, 2021
  53. Junio C HamanoNov 11, 2021
  54. 02/10 parse-options.[ch]: consistently use "enum parse_opt_flags"Ævar Arnfjörð Bjarmason, Oct 8, 2021
  55. 05/10 parse-options.h: make the "flags" in "struct option" an enumÆvar Arnfjörð Bjarmason, Oct 8, 2021
  56. 04/10 parse-options.c: use exhaustive "case" arms for "enum parse_opt_result"Ævar Arnfjörð Bjarmason, Oct 8, 2021
  57. 06/10 parse-options.c: move optname() earlier in the fileÆvar Arnfjörð Bjarmason, Oct 8, 2021
  58. 07/10 commit-graph: stop using optname()Ævar Arnfjörð Bjarmason, Oct 8, 2021
  59. 08/10 parse-options.[ch]: make opt{bug,name}() "static"Ævar Arnfjörð Bjarmason, Oct 8, 2021
  60. 09/10 parse-options tests: test optname() outputÆvar Arnfjörð Bjarmason, Oct 8, 2021
  61. 10/10 parse-options: change OPT_{SHORT,UNSET} to an enumÆvar Arnfjörð Bjarmason, Oct 8, 2021

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.