Thread View: linux.kernel.git
2 messages
2 total messages
Started by Junio C Hamano
Tue, 17 Nov 2026 01:28
Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`
Author: Junio C Hamano
Date: Tue, 17 Nov 2026 01:28
Date: Tue, 17 Nov 2026 01:28
83 lines
15551 bytes
15551 bytes
Patrick Steinhardt <ps@pks.im> writes:
> 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 index
vs
$ rungit seen rerere unknown
usage: too many arguments
and it is this step that may be responsible for some of it.
> @@ -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.
> + ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
> +
> + strvec_clear(&args);
> + free(args_copy);
> + return ret;
> + }
> +
> + return fn(argc, argv, prefix, repo);
> }
Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`
Author: Junio C Hamano
Date: Wed, 18 Nov 2026 17:02
Date: Wed, 18 Nov 2026 17:02
17 lines
13249 bytes
13249 bytes
Patrick Steinhardt <ps@pks.im> writes: >> > + 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. > > That's a good point indeed. It likely doesn't matter, but better be safe > than sorry. Will adapt. The COPY_ARRAY() call can stay as-is. CALLOC_ARRAY() needs to allocate one more element.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads