Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 17, 2026, 01:28 UTC
- Message-ID
- <xmqqwlqcgsan.fsf@gitster.g>
- In-Reply-To
- <20261111-pks-rerere-subcommands-v4-11-df0c8bf79e16@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> In git-rerere(1) we have our own custom logic to parse subcommands. In > preceding commits we have refactored all of those subcommands so that > they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use > these so that we get rid of our custom subcommand parsing. > > Unfortunately this means that we have a backwards-incompatible change > because we no longer accept the "--[no-]rerere-autoupdate" flag for all > subcommands. But this was arguably broken and misleading as we ignore > this flag for any other subcommand aynway. So we cheat a bit and simply > call it a bug that those flags were accepted in the first place. > > Signed-off-by: Patrick Steinhardt <ps@pks.im> > --- > builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++------------------- > 1 file changed, 56 insertions(+), 28 deletions(-)
I already mentioned
$ rungit master rerere unknown usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
--[no-]rerere-autoupdate
register clean resolutions in indexvs
$ rungit seen rerere unknown usage: too many arguments
and it is this step that may be responsible for some of it.
Show 33 quoted lines
> @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
> const char *prefix,
> struct repository *repo)
> {
> + parse_opt_subcommand_fn *fn = NULL;
> + OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
> + OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
> + OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
> + OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
> + OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
> + OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
> OPT_END(),
> };
>
> argc = parse_options(argc, argv, prefix, options, rerere_usage,
> + PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
> repo_config(repo, git_xmerge_config, NULL);
>
> + if (!fn) {
> + struct strvec args = STRVEC_INIT;
> + const char **args_copy;
> + int ret;
>
> + strvec_push(&args, "perform");
> + strvec_pushv(&args, argv);
>
> + /*
> + * We need to copy the array as it will be modified by
> + * `parse_options()`, and if so we leak the strings
> + * referenced by `args`.
> + */
> + CALLOC_ARRAY(args_copy, args.nr);
> + COPY_ARRAY(args_copy, args.v, args.nr);Does args.nr count the terminating NULL pointer? We mimic the familiar (ac, av) convention of the C language; av[ac] being NULL is also part of the convention, so if CALLOC_ARRAY() is not allocating an entry for the terminating NULL and COPY_ARRAY() is not copying args together with the NULL, this may want to be corrected.
Show 9 quoted lines
> + ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo); > + > + strvec_clear(&args); > + free(args_copy); > + return ret; > + } > + > + return fn(argc, argv, prefix, repo); > }