From: Patrick Steinhardt Date: Fri, 06 Nov 2026 15:13:59 GMT Subject: [PATCH v3 05/12] builtin/rerere: turn "forget" into a proper subcommand Message-ID: <20261106-pks-rerere-subcommands-v3-5-4ff164d8fb81@pks.im> In-Reply-To: <20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im> The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work: - Options from other subcommands apply to each other. - We don't have proper usage strings. - Running `git rerere -h` doesn't print the options that are supported by that subcommand, but instead it just prints the help of git-rerere(1) itself. A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`. Signed-off-by: Patrick Steinhardt --- builtin/rerere.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/builtin/rerere.c b/builtin/rerere.c index 405276cc94b..5d2ae154ff8 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1, return ret; } +static int cmd_rerere_forget(int argc, + const char **argv, + const char *prefix, + struct repository *repo) +{ + struct option options[] = { + OPT_END(), + }; + struct pathspec pathspec; + int ret; + + argc = parse_options(argc, argv, prefix, options, rerere_usage, 0); + if (!argc) + warning(_("'git rerere forget' without paths is deprecated")); + parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv); + + ret = rerere_forget(repo, &pathspec); + + clear_pathspec(&pathspec); + return ret; +} + int cmd_rerere(int argc, const char **argv, const char *prefix, @@ -83,20 +105,8 @@ int cmd_rerere(int argc, if (argc < 1) return rerere(repo, flags); - if (!strcmp(argv[0], "forget")) { - struct pathspec pathspec; - int ret; - - if (argc < 2) - warning(_("'git rerere forget' without paths is deprecated")); - parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, - prefix, argv + 1); - - ret = rerere_forget(repo, &pathspec); - - clear_pathspec(&pathspec); - return ret; - } + if (!strcmp(argv[0], "forget")) + return cmd_rerere_forget(argc, argv, prefix, repo); if (!strcmp(argv[0], "clear")) { rerere_clear(repo, &merge_rr); -- 2.56.0.500.g5d06dc02cd.dirty