From: Patrick Steinhardt Date: Thu, 19 Nov 2026 11:47:11 GMT Subject: [PATCH v5 10/13] builtin/rerere: turn "gc" into a proper subcommand Message-ID: <20261119-pks-rerere-subcommands-v5-10-0c1092b88958@pks.im> In-Reply-To: <20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im> As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step. Note that this results in an intentional change in behaviour, as we previously accepted the "--skip-lock" flag both before the subcommand and after the subcommand name, whereas after this change we only allow it after the subcommand name. But that flag has only recently been introduced via 5f6b6aa3ab4 (rerere: add "gc --skip-locked" for auto maintenance, 2026-10-13), which is not yet part of any release, so it's unlikely that anybody will complain about this change. Signed-off-by: Patrick Steinhardt --- builtin/rerere.c | 43 ++++++++++++++++++++++++++++++------------- t/t4200-rerere.sh | 5 ----- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/builtin/rerere.c b/builtin/rerere.c index 40bae5cb9cc..3162b074ec6 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc, return ret; } +static int cmd_rerere_gc(int argc, + const char **argv, + const char *prefix, + struct repository *repo) +{ + int skip_locked = 0; + struct option options[] = { + OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked, + N_("skip gc while another process holds the lock")), + OPT_END(), + }; + struct string_list merge_rr = STRING_LIST_INIT_DUP; + + argc = parse_options(argc, argv, prefix, options, rerere_usage, 0); + if (argc) + usage(_("too many arguments")); + + rerere_gc(repo, &merge_rr, + skip_locked ? RERERE_NOWAIT : 0); + + string_list_clear(&merge_rr, 1); + return 0; +} + static int cmd_rerere_remaining(int argc, const char **argv, const char *prefix, @@ -187,21 +211,16 @@ int cmd_rerere(int argc, const char *prefix, struct repository *repo) { - struct string_list merge_rr = STRING_LIST_INIT_DUP; - int autoupdate = -1, skip_locked = 0, flags = 0; + int autoupdate = -1, flags = 0; struct option options[] = { OPT_SET_INT(0, "rerere-autoupdate", &autoupdate, N_("register clean resolutions in index"), 1), - OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked, - N_("skip gc while another process holds the lock")), OPT_END(), }; - argc = parse_options(argc, argv, prefix, options, rerere_usage, 0); - - if (skip_locked && (argc < 1 || strcmp(argv[0], "gc"))) - die(_("the option '%s' requires '%s'"), "--skip-locked", "gc"); + argc = parse_options(argc, argv, prefix, options, rerere_usage, + PARSE_OPT_KEEP_UNKNOWN_OPT); repo_config(repo, git_xmerge_config, NULL); @@ -215,11 +234,10 @@ int cmd_rerere(int argc, if (!strcmp(argv[0], "forget")) return cmd_rerere_forget(argc, argv, prefix, repo); - else if (!strcmp(argv[0], "clear")) { + else if (!strcmp(argv[0], "clear")) return cmd_rerere_clear(argc, argv, prefix, repo); - } else if (!strcmp(argv[0], "gc")) - rerere_gc(repo, &merge_rr, - skip_locked ? RERERE_NOWAIT : 0); + 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")) @@ -229,6 +247,5 @@ int cmd_rerere(int argc, else usage_with_options(rerere_usage, options); - string_list_clear(&merge_rr, 1); return 0; } diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index ab412ecc6e8..0d4cbf5114a 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' ' test_path_is_missing $rr2/preimage ' -test_expect_success '--skip-locked is only accepted by gc' ' - test_must_fail git rerere --skip-locked clear 2>err && - test_grep "option .--skip-locked. requires .gc." err -' - test_expect_success 'a held lock is waited out within rerere.lockTimeout' ' git reset --hard && rm -rf $rr && -- 2.56.1.831.g720f3f5937.dirty