From: Patrick Steinhardt Date: Wed, 18 Nov 2026 14:09:40 GMT Subject: Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()` Message-ID: In-Reply-To: On Mon, Nov 16, 2026 at 05:28:32PM -0800, Junio C Hamano wrote: > Patrick Steinhardt 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 > > --- > > builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++------------------- > > 1 file changed, 56 insertions(+), 28 deletions(-) > > I already mentioned > > $ rungit master rerere unknown > usage: git rerere [clear | forget ... | 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. Right, but isn't this actually an improvement? It's exactly the same way that other commands with optional subcommands behave, e.g.: $ git submodule -855827c583bc30645ba427885caa40c5b81764d2 sha1collisiondetection $ git submodule unknown usage: git submodule [--quiet] [--cached] or: git submodule [--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] Ooh, no, it's the exact _other_ way round. We used to print the synopsis, now we print "too many arguments". That's annoying and a regression indeed. Will fix. > > @@ -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. That's a good point indeed. It likely doesn't matter, but better be safe than sorry. Will adapt. Patrick