From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org,
"Mark C. Chu-Carroll" <markchucarroll@fastmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`
Date: Fri, 6 Nov 2026 15:25:28 +0100 [thread overview]
Message-ID: <au3jWCIwBKLV8DXT@pks.im> (raw)
In-Reply-To: <CAOLa=ZQrOyA2k+5EDmh+VJD=gC=68m3D17uKvNUTmaxH2FuNZg@mail.gmail.com>
On Fri, Nov 06, 2026 at 03:44:38AM -0800, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/builtin/rerere.c b/builtin/rerere.c
> > index 3162b074ec6..97c791e420b 100644
> > --- a/builtin/rerere.c
> > +++ b/builtin/rerere.c
> > @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
> > const char *prefix,
> > struct repository *repo)
> > {
> > - int autoupdate = -1, flags = 0;
> > -
> > + parse_opt_subcommand_fn *fn = NULL;
> > struct option options[] = {
> > - OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
> > - N_("register clean resolutions in index"), 1),
> > + 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_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
>
> So this matches what I thought.
>
> > repo_config(repo, git_xmerge_config, NULL);
> >
> > - if (autoupdate == 1)
> > - flags = RERERE_AUTOUPDATE;
> > - if (autoupdate == 0)
> > - flags = RERERE_NOAUTOUPDATE;
> > + if (!fn) {
>
> Okay if there's no function we call the default case. I wonder if we
> could've done the inverse to reduce code block. if (fn) reutrn fn(...).
> Doesn't matter much anyway.
I think that the result is actually harder to read in that case, even
though that might just be my personal opinion. But having a return in
the middle of the function is awkward, and I like that the variables
that are specific to the default subcommand are nicely scoped to the
block so that they obviously cannot be used by any other subcommand.
So I prefer to keep this as-is.
> > + struct strvec args = STRVEC_INIT;
> > + const char **args_copy;
> > + int ret;
> >
> > - if (argc < 1)
> > - return rerere(repo, flags);
> > -
> > - if (!strcmp(argv[0], "forget"))
> > - return cmd_rerere_forget(argc, argv, prefix, repo);
> > - else if (!strcmp(argv[0], "clear"))
> > - return cmd_rerere_clear(argc, argv, prefix, repo);
> > - else if (!strcmp(argv[0], "gc"))
> > - return cmd_rerere_gc(argc, argv, prefix, repo);
> > - else if (!strcmp(argv[0], "status"))
> > - return cmd_rerere_status(argc, argv, prefix, repo);
> > - else if (!strcmp(argv[0], "remaining"))
> > - return cmd_rerere_remaining(argc, argv, prefix, repo);
> > - else if (!strcmp(argv[0], "diff"))
> > - return cmd_rerere_diff(argc, argv, prefix, repo);
> > - else
> > - usage_with_options(rerere_usage, options);
> > + strvec_push(&args, "perform");
>
> Worthwhile adding a comment that this is a dummy placeholder subcommand?
Hmm. I could add something like this:
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 97c791e420b..f88bc43e363 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -257,6 +257,7 @@ int cmd_rerere(int argc,
const char **args_copy;
int ret;
+ /* This is a dummy subcommand name. */
strvec_push(&args, "perform");
strvec_pushv(&args, argv);
But does that really add much value? I myself don't think so, but if you
feel that it does I'm happy to add it in.
Thanks!
Patrick
next prev parent reply other threads:[~2026-11-06 14:25 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 10:46 [PATCH 00/12] builtin/rerere: convert to use subcommands Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 01/12] rerere: rename `repo_rerere()` Patrick Steinhardt
2026-10-27 19:48 ` Junio C Hamano
2026-10-28 8:33 ` Patrick Steinhardt
2026-10-28 16:25 ` Junio C Hamano
2026-10-27 10:46 ` [PATCH 02/12] rerere: convert flags into an enum Patrick Steinhardt
2026-10-27 14:47 ` Mark C. Chu-Carroll
2026-10-27 19:40 ` Junio C Hamano
2026-10-28 8:33 ` Patrick Steinhardt
2026-10-28 14:11 ` Mark C. Chu-Carroll
2026-10-28 16:25 ` Junio C Hamano
2026-10-27 10:46 ` [PATCH 03/12] builtin/rerere: drop `the_repository` Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 04/12] builtin/rerere: stop passing flags to subcommands that ignore them Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 05/12] builtin/rerere: turn "forget" into a proper subcommand Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 06/12] builtin/rerere: turn "clear" " Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 07/12] builtin/rerere: turn "status" " Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 08/12] builtin/rerere: turn "remaining" " Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 09/12] builtin/rerere: turn "diff" " Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 10/12] builtin/rerere: turn "gc" " Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 11/12] builtin/rerere: use `OPT_SUBCOMMAND()` Patrick Steinhardt
2026-10-27 10:46 ` [PATCH 12/12] builtin/rerere: introduce proper usage strings for subcommands Patrick Steinhardt
2026-10-27 19:52 ` [PATCH 00/12] builtin/rerere: convert to use subcommands Junio C Hamano
2026-10-29 9:57 ` [PATCH v2 " Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 01/12] rerere: rename `repo_rerere()` Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 02/12] rerere: convert flags into an enum Patrick Steinhardt
2026-11-06 10:51 ` Karthik Nayak
2026-11-06 11:39 ` Patrick Steinhardt
2026-11-06 13:50 ` Karthik Nayak
2026-10-29 9:57 ` [PATCH v2 03/12] builtin/rerere: drop `the_repository` Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 04/12] builtin/rerere: stop passing flags to subcommands that ignore them Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 05/12] builtin/rerere: turn "forget" into a proper subcommand Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 06/12] builtin/rerere: turn "clear" " Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 07/12] builtin/rerere: turn "status" " Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 08/12] builtin/rerere: turn "remaining" " Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 09/12] builtin/rerere: turn "diff" " Patrick Steinhardt
2026-10-29 9:57 ` [PATCH v2 10/12] builtin/rerere: turn "gc" " Patrick Steinhardt
2026-11-06 10:56 ` Karthik Nayak
2026-10-29 9:57 ` [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()` Patrick Steinhardt
2026-11-06 11:44 ` Karthik Nayak
2026-11-06 14:25 ` Patrick Steinhardt [this message]
2026-10-29 9:57 ` [PATCH v2 12/12] builtin/rerere: introduce proper usage strings for subcommands Patrick Steinhardt
2026-11-06 11:45 ` [PATCH v2 00/12] builtin/rerere: convert to use subcommands Karthik Nayak
2026-11-06 15:13 ` [PATCH v3 " Patrick Steinhardt
2026-11-06 15:13 ` [PATCH v3 01/12] rerere: rename `repo_rerere()` Patrick Steinhardt
2026-11-06 15:13 ` [PATCH v3 02/12] rerere: convert flags into an enum Patrick Steinhardt
2026-11-06 16:39 ` Junio C Hamano
2026-11-06 15:13 ` [PATCH v3 03/12] builtin/rerere: drop `the_repository` Patrick Steinhardt
2026-11-06 15:13 ` [PATCH v3 04/12] builtin/rerere: stop passing flags to subcommands that ignore them Patrick Steinhardt
2026-11-06 15:13 ` [PATCH v3 05/12] builtin/rerere: turn "forget" into a proper subcommand Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 06/12] builtin/rerere: turn "clear" " Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 07/12] builtin/rerere: turn "status" " Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 08/12] builtin/rerere: turn "remaining" " Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 09/12] builtin/rerere: turn "diff" " Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 10/12] builtin/rerere: turn "gc" " Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 11/12] builtin/rerere: use `OPT_SUBCOMMAND()` Patrick Steinhardt
2026-11-06 15:14 ` [PATCH v3 12/12] builtin/rerere: introduce proper usage strings for subcommands Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=au3jWCIwBKLV8DXT@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=markchucarroll@fastmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox