{"thread":{"id":"66677","subject":"[PATCH 00/12] builtin/rerere: convert to use subcommands","startedAt":"2026-10-27T10:46:43Z","lastAt":"2026-11-19T22:43:25Z","messageCount":108,"participants":["Patrick Steinhardt","Mark C. Chu-Carroll","Junio C Hamano","Karthik Nayak","Tuomas Ahola","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"556462","messageId":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":null,"subject":"[PATCH 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:43Z","receivedAt":"2026-10-27T10:46:43Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nwhile reviewing some patch series around git-rerere(1) recently I was a\nbit appalled by our custom subcommand parsing that we do here. This\npatch series here thus cleans up and modernizes that part a bit so that\ngit-rerere(1) behaves like every other Git command that happens to have\nsubcommands.\n\nThis series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\nps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\nrerere cache state, 2026-10-23) merged into it.\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (12):\n      rerere: rename `repo_rerere()`\n      rerere: convert flags into an enum\n      builtin/rerere: drop `the_repository`\n      builtin/rerere: stop passing flags to subcommands that ignore them\n      builtin/rerere: turn \"forget\" into a proper subcommand\n      builtin/rerere: turn \"clear\" into a proper subcommand\n      builtin/rerere: turn \"status\" into a proper subcommand\n      builtin/rerere: turn \"remaining\" into a proper subcommand\n      builtin/rerere: turn \"diff\" into a proper subcommand\n      builtin/rerere: turn \"gc\" into a proper subcommand\n      builtin/rerere: use `OPT_SUBCOMMAND()`\n      builtin/rerere: introduce proper usage strings for subcommands\n\n Documentation/git-rerere.adoc |   8 +-\n apply.c                       |   2 +-\n builtin/am.c                  |   4 +-\n builtin/commit.c              |   2 +-\n builtin/merge.c               |   2 +-\n builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------\n builtin/stash.c               |   2 +-\n rerere.c                      |   7 +-\n rerere.h                      |  21 +--\n sequencer.c                   |   4 +-\n t/t4200-rerere.sh             |   5 -\n 11 files changed, 275 insertions(+), 101 deletions(-)\n\n\n---\nbase-commit: 710910c03a22ac663885049213b9fef5853ea8e0\nchange-id: 20261027-pks-rerere-subcommands-318d41553438\n\n\n"},{"id":"556463","messageId":"20261027-pks-rerere-subcommands-v1-1-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 01/12] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:44Z","receivedAt":"2026-10-27T10:46:44Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `repo_rerere()` function is the only function in \"rerere.h\" that\ndoes not have a `rerere_` prefix. And while it does indeed receive a\nrepository as first parameter, that's not a good-enough reason to give\nit a `repo_` prefix.\n\nRename the function to `rerere_record()` to be consistent with all the\nother functions.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n apply.c          | 2 +-\n builtin/am.c     | 4 ++--\n builtin/commit.c | 2 +-\n builtin/merge.c  | 2 +-\n builtin/rerere.c | 2 +-\n builtin/stash.c  | 2 +-\n rerere.c         | 2 +-\n rerere.h         | 2 +-\n sequencer.c      | 4 ++--\n 9 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex a0b7119c639..d0b100ca065 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t * tree with conflict markers, but that isn't written with --cached.\n \t\t */\n \t\tif (!state->cached)\n-\t\t\trepo_rerere(state->repo, 0);\n+\t\t\trerere_record(state->repo, 0);\n \t}\n \n \treturn errs;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e9623b83077..1d156cf877c 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\to.verbosity = 0;\n \n \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n-\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n+\t\trerere_record(the_repository, state->allow_rerere_autoupdate);\n \t\tfree(their_tree_name);\n \t\treturn error(_(\"Failed to merge in the changes.\"));\n \t}\n@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t\tgoto next;\n \t}\n \n-\trepo_rerere(the_repository, 0);\n+\trerere_record(the_repository, 0);\n \n \tdo_commit(state);\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8ffd42681bb..c472e8f6638 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,\n \n \tgit_test_write_commit_graph_or_die(the_repository);\n \n-\trepo_rerere(the_repository, 0);\n+\trerere_record(the_repository, 0);\n \trun_auto_maintenance(the_repository, quiet);\n \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n \t\t\tNULL, \"post-commit\", NULL);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d7bf209114f..aaf15fdd69d 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\n-\trepo_rerere(the_repository, allow_rerere_auto);\n+\trerere_record(the_repository, allow_rerere_auto);\n \tprintf(_(\"Automatic merge failed; \"\n \t\t\t\"fix conflicts and then commit the result.\\n\"));\n \treturn 1;\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2c17f02f56d..1717fb7a65d 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -83,7 +83,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn repo_rerere(the_repository, flags);\n+\t\treturn rerere_record(the_repository, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex e1a3a76bd04..1b9c7f0eb6b 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,\n \t\tret = error(_(\"could not write index\"));\n \n \tif (ret) {\n-\t\trepo_rerere(the_repository, 0);\n+\t\trerere_record(the_repository, 0);\n \n \t\tif (index)\n \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\ndiff --git a/rerere.c b/rerere.c\nindex e0897612085..fd1c1ed6015 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -956,7 +956,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n  * perform mergy operations, possibly leaving conflicted index entries\n  * and working tree files.\n  */\n-int repo_rerere(struct repository *r, int flags)\n+int rerere_record(struct repository *r, int flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\ndiff --git a/rerere.h b/rerere.h\nindex d3cbd10e13f..a19d2407b59 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -45,7 +45,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       int flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int repo_rerere(struct repository *, int);\n+int rerere_record(struct repository *, int);\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\ndiff --git a/sequencer.c b/sequencer.c\nindex 508ec717920..58e58503794 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(r, commit), msg.subject);\n \t\tprint_advice(r, res == 1, opts);\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere_record(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere_record(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556464","messageId":"20261027-pks-rerere-subcommands-v1-2-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:45Z","receivedAt":"2026-10-27T10:46:45Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Our modern coding guidelines say that flags should typically be passed\naround as enums so that it becomes trivial to see what kind of flags are\nexpected. Adapt the rerere flags accordingly.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n rerere.c |  7 ++++---\n rerere.h | 21 ++++++++++++---------\n 2 files changed, 16 insertions(+), 12 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex fd1c1ed6015..1ae7983445a 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags)\n+\t\t       enum rerere_flags flags)\n {\n \tint lock_timeout_ms = 1000;\n \tint fd;\n@@ -956,7 +956,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n  * perform mergy operations, possibly leaving conflicted index entries\n  * and working tree files.\n  */\n-int rerere_record(struct repository *r, int flags)\n+int rerere_record(struct repository *r, enum rerere_flags flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n@@ -1341,7 +1341,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)\n \treturn needed;\n }\n \n-void rerere_gc(struct repository *r, struct string_list *rr, int flags)\n+void rerere_gc(struct repository *r, struct string_list *rr,\n+\t       enum rerere_flags flags)\n {\n \tstruct rerere_cache cache;\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\ndiff --git a/rerere.h b/rerere.h\nindex a19d2407b59..362b348af25 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -9,12 +9,6 @@\n struct pathspec;\n struct repository;\n \n-#define RERERE_AUTOUPDATE   01\n-#define RERERE_NOAUTOUPDATE 02\n-#define RERERE_READONLY     04\n-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n-#define RERERE_NOWAIT       010\n-\n /*\n  * Marks paths that have been hand-resolved and added to the\n  * index. Set in the util field of such paths after calling\n@@ -39,13 +33,21 @@ struct rerere_id {\n \tint variant;\n };\n \n+enum rerere_flags {\n+\tRERERE_AUTOUPDATE = (1 << 0),\n+\tRERERE_NOAUTOUPDATE = (1 << 1),\n+\tRERERE_READONLY = (1 << 2),\n+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n+\tRERERE_NOWAIT = (1 << 3),\n+};\n+\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags);\n+\t\t       enum rerere_flags flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int rerere_record(struct repository *, int);\n+int rerere_record(struct repository *r, enum rerere_flags flags);\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\n@@ -58,7 +60,8 @@ const char *rerere_path(struct repository *,\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n void rerere_clear(struct repository *, struct string_list *);\n-void rerere_gc(struct repository *, struct string_list *, int);\n+void rerere_gc(struct repository *, struct string_list *,\n+\t       enum rerere_flags flags);\n \n /*\n  * Check whether garbage collection for rerere entries is needed, which is\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556465","messageId":"20261027-pks-rerere-subcommands-v1-3-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 03/12] builtin/rerere: drop `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:46Z","receivedAt":"2026-10-27T10:46:46Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in git-rerere(1).\nAs that command cannot run outside of a repository these references can\nbe trivially replaced by the repository that's passed in as parameter to\n`cmd_rerere()`. We don't have to worry about the repository being `NULL`\nwhen called with \"-h\", either, as there are no references to the repo\nbefore we call `parse_options()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 24 +++++++++++-------------\n 1 file changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 1717fb7a65d..556f267f37d 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint autoupdate = -1, skip_locked = 0, flags = 0;\n@@ -75,7 +73,7 @@ int cmd_rerere(int argc,\n \tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n \t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n \n-\trepo_config(the_repository, git_xmerge_config, NULL);\n+\trepo_config(repo, git_xmerge_config, NULL);\n \n \tif (autoupdate == 1)\n \t\tflags = RERERE_AUTOUPDATE;\n@@ -83,7 +81,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn rerere_record(the_repository, flags);\n+\t\treturn rerere_record(repo, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\n@@ -94,21 +92,21 @@ int cmd_rerere(int argc,\n \t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n \t\t\t       prefix, argv + 1);\n \n-\t\tret = rerere_forget(the_repository, &pathspec);\n+\t\tret = rerere_forget(repo, &pathspec);\n \n \t\tclear_pathspec(&pathspec);\n \t\treturn ret;\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(the_repository, &merge_rr);\n+\t\trerere_clear(repo, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(the_repository, &merge_rr,\n+\t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\")) {\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t       flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n@@ -116,7 +114,7 @@ int cmd_rerere(int argc,\n \n \t\trerere_cache_release(&cache);\n \t} else if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(the_repository, &merge_rr);\n+\t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n \t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -129,16 +127,16 @@ int cmd_rerere(int argc,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t      flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n \t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(the_repository, &buf, id, \"preimage\"),\n+\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n \t\t\t\t     path, path, path))\n \t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(the_repository, &buf, id, NULL));\n+\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n \t\t}\n \n \t\trerere_cache_release(&cache);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556466","messageId":"20261027-pks-rerere-subcommands-v1-4-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 04/12] builtin/rerere: stop passing flags to subcommands that ignore them","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:47Z","receivedAt":"2026-10-27T10:46:47Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has a \"--[no-]rerere-autoupdate\" flag. If\npassed, we explicitly enable or disable recording clean merge\nresolutions that are staged in the index. This flag only matters to\ngit-rerere(1) when not executed with any subcommand, but we also forward\nthe flag to `git rerere status` and `git rerere diff`.\n\nThis is mostly harmless as we would ignore those flags anyway, but it\nmakes subsequent refactorings harder to understand. Prepare for these\nrefactorings by not using the flag in those subcommands anymore.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 556f267f37d..d65870779f3 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -107,7 +107,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -128,7 +128,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t      flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556467","messageId":"20261027-pks-rerere-subcommands-v1-5-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 05/12] builtin/rerere: turn \"forget\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:48Z","receivedAt":"2026-10-27T10:46:48Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has its own, home-grown implementation of\nsubcommands. Of course this implementation is inconsistent with how\nsubcommands typically work:\n\n  - Options from other subcommands apply to each other.\n\n  - We don't have proper usage strings.\n\n  - Running `git rerere <subcmd> -h` doesn't print the options that are\n    supported by that subcommand, but instead it just prints the help of\n    git-rerere(1) itself.\n\nA subsequent commit will thus introduce proper subcommands as supported\nby our parse-options subsystem. Refactor the \"forget\" subcommand to use\nparse-options as a preparatory step. The other commands will follow in\nsubsequent commits until all of them have been converted, and then we\nswitch over to `OPT_SUBCOMMAND()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 38 ++++++++++++++++++++++++--------------\n 1 file changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex d65870779f3..0f55619bf62 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_forget(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct pathspec pathspec;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (!argc)\n+\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n+\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n+\n+\tret = rerere_forget(repo, &pathspec);\n+\n+\tclear_pathspec(&pathspec);\n+\treturn ret;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -83,20 +105,8 @@ int cmd_rerere(int argc,\n \tif (argc < 1)\n \t\treturn rerere_record(repo, flags);\n \n-\tif (!strcmp(argv[0], \"forget\")) {\n-\t\tstruct pathspec pathspec;\n-\t\tint ret;\n-\n-\t\tif (argc < 2)\n-\t\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n-\t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n-\t\t\t       prefix, argv + 1);\n-\n-\t\tret = rerere_forget(repo, &pathspec);\n-\n-\t\tclear_pathspec(&pathspec);\n-\t\treturn ret;\n-\t}\n+\tif (!strcmp(argv[0], \"forget\"))\n+\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n \n \tif (!strcmp(argv[0], \"clear\")) {\n \t\trerere_clear(repo, &merge_rr);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556468","messageId":"20261027-pks-rerere-subcommands-v1-6-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 06/12] builtin/rerere: turn \"clear\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:49Z","receivedAt":"2026-10-27T10:46:49Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"clear\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 25 ++++++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 0f55619bf62..96e98bc411c 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_clear(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_clear(repo, &merge_rr);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -107,9 +127,8 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\n-\tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(repo, &merge_rr);\n+\telse if (!strcmp(argv[0], \"clear\")) {\n+\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556469","messageId":"20261027-pks-rerere-subcommands-v1-7-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 07/12] builtin/rerere: turn \"status\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:50Z","receivedAt":"2026-10-27T10:46:50Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"status\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------\n 1 file changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 96e98bc411c..e2955fea20e 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_status(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\tfor (size_t i = 0; i < merge_rr.nr; i++)\n+\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\treturn 0;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -132,17 +158,9 @@ int cmd_rerere(int argc,\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n-\telse if (!strcmp(argv[0], \"status\")) {\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n-\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\n-\t\trerere_cache_release(&cache);\n-\t} else if (!strcmp(argv[0], \"remaining\")) {\n+\telse if (!strcmp(argv[0], \"status\"))\n+\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"remaining\")) {\n \t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556470","messageId":"20261027-pks-rerere-subcommands-v1-8-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 08/12] builtin/rerere: turn \"remaining\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:51Z","receivedAt":"2026-10-27T10:46:51Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"remaining\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------\n 1 file changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex e2955fea20e..31c1b37540e 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_remaining(int argc,\n+\t\t\t\tconst char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_remaining(repo, &merge_rr);\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n+\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\t\telse\n+\t\t\t/* prepare for later call to\n+\t\t\t * string_list_clear() */\n+\t\t\tmerge_rr.items[i].util = NULL;\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_status(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -160,17 +188,9 @@ int cmd_rerere(int argc,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(repo, &merge_rr);\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n-\t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\t\t\telse\n-\t\t\t\t/* prepare for later call to\n-\t\t\t\t * string_list_clear() */\n-\t\t\t\tmerge_rr.items[i].util = NULL;\n-\t\t}\n-\t} else if (!strcmp(argv[0], \"diff\")) {\n+\telse if (!strcmp(argv[0], \"remaining\"))\n+\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"diff\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556471","messageId":"20261027-pks-rerere-subcommands-v1-9-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 09/12] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:52Z","receivedAt":"2026-10-27T10:46:52Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"diff\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 31c1b37540e..87ee4eddd0a 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_diff(int argc,\n+\t\t\t   const char **argv,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tconst char *path = merge_rr.items[i].string;\n+\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n+\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"), path, path, path))\n+\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n+\t\t\t    rerere_path(repo, &buf, id, NULL));\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -190,25 +224,9 @@ int cmd_rerere(int argc,\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n \t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\")) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tconst char *path = merge_rr.items[i].string;\n-\t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n-\t\t\t\t     path, path, path))\n-\t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n-\t\t}\n-\n-\t\trerere_cache_release(&cache);\n-\t\tstrbuf_release(&buf);\n-\t} else\n+\telse if (!strcmp(argv[0], \"diff\"))\n+\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n+\telse\n \t\tusage_with_options(rerere_usage, options);\n \n \tstring_list_clear(&merge_rr, 1);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556472","messageId":"20261027-pks-rerere-subcommands-v1-10-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:53Z","receivedAt":"2026-10-27T10:46:53Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"gc\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n t/t4200-rerere.sh |  5 -----\n 2 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 87ee4eddd0a..67626e13845 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_gc(int argc,\n+\t\t\t const char **argv,\n+\t\t\t const char *prefix,\n+\t\t\t struct repository *repo)\n+{\n+\tint skip_locked = 0;\n+\tstruct option options[] = {\n+\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n+\t\t\t\tN_(\"skip gc while another process holds the lock\")),\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_gc(repo, &merge_rr,\n+\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -187,21 +211,16 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\tint autoupdate = -1, skip_locked = 0, flags = 0;\n+\tint autoupdate = -1, flags = 0;\n \n \tstruct option options[] = {\n \t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n-\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n-\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n-\n-\tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n-\t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage,\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_config(repo, git_xmerge_config, NULL);\n \n@@ -215,11 +234,10 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\")) {\n+\telse if (!strcmp(argv[0], \"clear\"))\n \t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(repo, &merge_rr,\n-\t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\telse if (!strcmp(argv[0], \"gc\"))\n+\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n@@ -229,6 +247,5 @@ int cmd_rerere(int argc,\n \telse\n \t\tusage_with_options(rerere_usage, options);\n \n-\tstring_list_clear(&merge_rr, 1);\n \treturn 0;\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex ab412ecc6e8..0d4cbf5114a 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n \ttest_path_is_missing $rr2/preimage\n '\n \n-test_expect_success '--skip-locked is only accepted by gc' '\n-\ttest_must_fail git rerere --skip-locked clear 2>err &&\n-\ttest_grep \"option .--skip-locked. requires .gc.\" err\n-'\n-\n test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n \tgit reset --hard &&\n \trm -rf $rr &&\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556473","messageId":"20261027-pks-rerere-subcommands-v1-11-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:54Z","receivedAt":"2026-10-27T10:46:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In git-rerere(1) we have our own custom logic to parse subcommands. In\npreceding commits we have refactored all of those subcommands so that\nthey are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\nthese so that we get rid of our custom subcommand parsing.\n\nUnfortunately this means that we have a backwards-incompatible change\nbecause we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\nsubcommands. But this was arguably broken and misleading as we ignore\nthis flag for any other subcommand aynway. So we cheat a bit and simply\ncall it a bug that those flags were accepted in the first place.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 56 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 67626e13845..80ecca1fe0d 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -5,6 +5,7 @@\n #include \"rerere.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_record(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tint autoupdate = -1;\n+\tstruct option options[] = {\n+\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n+\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_END(),\n+\t};\n+\tenum rerere_flags flags = 0;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (autoupdate == 1)\n+\t\tflags = RERERE_AUTOUPDATE;\n+\tif (autoupdate == 0)\n+\t\tflags = RERERE_NOAUTOUPDATE;\n+\n+\treturn rerere_record(repo, flags);\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tint autoupdate = -1, flags = 0;\n-\n+\tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n-\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n-\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n+\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n+\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n+\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n+\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n+\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n-\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \trepo_config(repo, git_xmerge_config, NULL);\n \n-\tif (autoupdate == 1)\n-\t\tflags = RERERE_AUTOUPDATE;\n-\tif (autoupdate == 0)\n-\t\tflags = RERERE_NOAUTOUPDATE;\n+\tif (!fn) {\n+\t\tstruct strvec args = STRVEC_INIT;\n+\t\tconst char **args_copy;\n+\t\tint ret;\n \n-\tif (argc < 1)\n-\t\treturn rerere_record(repo, flags);\n-\n-\tif (!strcmp(argv[0], \"forget\"))\n-\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\"))\n-\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"gc\"))\n-\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"status\"))\n-\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\"))\n-\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\"))\n-\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n-\telse\n-\t\tusage_with_options(rerere_usage, options);\n+\t\tstrvec_push(&args, \"record\");\n+\t\tstrvec_pushv(&args, argv);\n \n-\treturn 0;\n+\t\t/*\n+\t\t * We need to copy the array as it will be modified by\n+\t\t * `parse_options()`, and if so we leak the strings\n+\t\t * referenced by `args`.\n+\t\t */\n+\t\tCALLOC_ARRAY(args_copy, args.nr);\n+\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n+\n+\t\tret = cmd_rerere_record(args.nr, args_copy, prefix, repo);\n+\n+\t\tstrvec_clear(&args);\n+\t\tfree(args_copy);\n+\t\treturn ret;\n+\t}\n+\n+\treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556474","messageId":"20261027-pks-rerere-subcommands-v1-12-d836c36ce0c5@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-27T10:46:55Z","receivedAt":"2026-10-27T10:46:55Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Adapt git-rerere(1) to have proper usage strings for each of the\nsubcommands.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc |  8 +++++-\n builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex 4e6ab9a27c9..e04e9ef3ef8 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n SYNOPSIS\n --------\n [verse]\n-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n+'git rerere' [--[no-]rerere-autoupdate]\n+'git rerere' clear\n+'git rerere' diff\n+'git rerere' forget <pathspec>...\n+'git rerere' gc\n+'git rerere' remaining\n+'git rerere' status\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 80ecca1fe0d..97a08ecd6e7 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -10,10 +10,13 @@\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n \n-static const char * const rerere_usage[] = {\n-\tN_(\"git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\"),\n-\tNULL,\n-};\n+#define RERERE_USAGE N_(\"git rerere [--[no-]rerere-autoupdate]\")\n+#define RERERE_CLEAR_USAGE N_(\"git rerere clear\")\n+#define RERERE_DIFF_USAGE N_(\"git rerere diff\")\n+#define RERERE_FORGET_USAGE N_(\"git rerere forget <pathspec>...\")\n+#define RERERE_GC_USAGE N_(\"git rerere gc\")\n+#define RERERE_REMAINING_USAGE N_(\"git rerere remaining\")\n+#define RERERE_STATUS_USAGE N_(\"git rerere status\")\n \n static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)\n {\n@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_clear_usage[] = {\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_diff_usage[] = {\n+\t\tRERERE_DIFF_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_forget_usage[] = {\n+\t\tRERERE_FORGET_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct pathspec pathspec;\n \tint ret;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);\n \tif (!argc)\n \t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n \tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,\n \t\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_gc_usage[] = {\n+\t\tRERERE_GC_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -164,6 +183,10 @@ static int cmd_rerere_record(int argc,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tNULL,\n+\t};\n \tenum rerere_flags flags = 0;\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_remaining_usage[] = {\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_status_usage[] = {\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -247,6 +278,16 @@ int cmd_rerere(int argc,\n \t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tRERERE_DIFF_USAGE,\n+\t\tRERERE_FORGET_USAGE,\n+\t\tRERERE_GC_USAGE,\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556513","messageId":"c23c4593fa3add2b40613febb2911cfb@fastmail.com","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-2-d836c36ce0c5@pks.im","subject":"Re: [PATCH 02/12] rerere: convert flags into an enum","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-27T14:47:17Z","receivedAt":"2026-10-27T14:47:17Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\nOn Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> Our modern coding guidelines say that flags should typically be passed\n> around as enums so that it becomes trivial to see what kind of flags are\n> expected. Adapt the rerere flags accordingly.\n> \n>   <snip>\n> +enum rerere_flags {\n> +\tRERERE_AUTOUPDATE = (1 << 0),\n> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> +\tRERERE_READONLY = (1 << 2),\n> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n> +\tRERERE_NOWAIT = (1 << 3),\n> +};\n\nIf we're moving to using enum flags, then wouldn't it be better to\nexplicitly add a \"RERE_MERGE_LOCK_TOKEN\" to the enum for that case, \nrather than have this value only documented by a comment?\n\n  -Mark\n\n"},{"id":"556569","messageId":"xmqqzevzhqyq.fsf@gitster.g","threadId":"66677","inReplyTo":"c23c4593fa3add2b40613febb2911cfb@fastmail.com","subject":"Re: [PATCH 02/12] rerere: convert flags into an enum","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-27T19:40:45Z","receivedAt":"2026-10-27T19:40:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n\n> On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n>> Our modern coding guidelines say that flags should typically be passed\n>> around as enums so that it becomes trivial to see what kind of flags are\n>> expected. Adapt the rerere flags accordingly.\n>> \n>>   <snip>\n>> +enum rerere_flags {\n>> +\tRERERE_AUTOUPDATE = (1 << 0),\n>> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n>> +\tRERERE_READONLY = (1 << 2),\n>> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n>> +\tRERERE_NOWAIT = (1 << 3),\n>> +};\n>\n> If we're moving to using enum flags, then wouldn't it be better to\n> explicitly add a \"RERE_MERGE_LOCK_TOKEN\" to the enum for that case, \n> rather than have this value only documented by a comment?\n\nPerhaps you misunderstand what the comment says.  It is an\nexplanation for the next line, i.e., it tells the API users \"If you\nwant the 'immediate failure when locked' behaviour, pass the _NOWAIT\nbit\".\n\n"},{"id":"556571","messageId":"xmqqv76mj563.fsf@gitster.g","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-1-d836c36ce0c5@pks.im","subject":"Re: [PATCH 01/12] rerere: rename `repo_rerere()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-27T19:48:36Z","receivedAt":"2026-10-27T19:48:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> The `repo_rerere()` function is the only function in \"rerere.h\" that\n> does not have a `rerere_` prefix. And while it does indeed receive a\n> repository as first parameter, that's not a good-enough reason to give\n> it a `repo_` prefix.\n>\n> Rename the function to `rerere_record()` to be consistent with all the\n> other functions.\n\nI do not think the convention to give \"repo_\" prefix to variants of\nfunctions that worked only on the_repository should stay with us\nforever, and losing repo prefix from this function would be an\nexcellent first move towards that future.\n\nI howevr take isseus with the verb \"record\" in its new name.  What\nthe function does is not just record.  It autonomously finds out\nwhat situation it is in and does the logical next thing, which\nvaries.  It resolves when a recorded resolution exist.  it records\nwhen seeing a particular conflict for the first time.  There was no\nsingle good verb to express that.  Perhaps \"to rerere\" or \"to\nperform rerere\" can be invented as a verb to describe such an\nintelligent operation?\n\n\n\n"},{"id":"556572","messageId":"xmqqqzhaj4zv.fsf@gitster.g","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"Re: [PATCH 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-27T19:52:20Z","receivedAt":"2026-10-27T19:52:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> while reviewing some patch series around git-rerere(1) recently I was a\n> bit appalled by our custom subcommand parsing that we do here. This\n> patch series here thus cleans up and modernizes that part a bit so that\n> git-rerere(1) behaves like every other Git command that happens to have\n> subcommands.\n>\n> This series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\n> ps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\n> rerere cache state, 2026-10-23) merged into it.\n\nAs the inventor of the mechanism, I took special interest in the\ntopic, and overall found them well done.  I wasn't even aware that\nwe were so close to get rid of USE_THE_REPOSITORY_VARIABLE in\nbuiltin/rerere.c with such a small change (even though as I've said\nI do not think it is high priority to make cmd_foo() not rely on\nthe_repository).  Very nicely done.\n\nThanks.  \n\n"},{"id":"556618","messageId":"auGzRmkt6Mk6peSp@pks.im","threadId":"66677","inReplyTo":"xmqqv76mj563.fsf@gitster.g","subject":"Re: [PATCH 01/12] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T08:33:19Z","receivedAt":"2026-10-28T08:33:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Oct 27, 2026 at 12:48:36PM -0700, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > The `repo_rerere()` function is the only function in \"rerere.h\" that\n> > does not have a `rerere_` prefix. And while it does indeed receive a\n> > repository as first parameter, that's not a good-enough reason to give\n> > it a `repo_` prefix.\n> >\n> > Rename the function to `rerere_record()` to be consistent with all the\n> > other functions.\n> \n> I do not think the convention to give \"repo_\" prefix to variants of\n> functions that worked only on the_repository should stay with us\n> forever, and losing repo prefix from this function would be an\n> excellent first move towards that future.\n> \n> I howevr take isseus with the verb \"record\" in its new name.  What\n> the function does is not just record.  It autonomously finds out\n> what situation it is in and does the logical next thing, which\n> varies.  It resolves when a recorded resolution exist.  it records\n> when seeing a particular conflict for the first time.  There was no\n> single good verb to express that.  Perhaps \"to rerere\" or \"to\n> perform rerere\" can be invented as a verb to describe such an\n> intelligent operation?\n\nI was picking \"record\" because that's also what git-rerere(1) says:\n\n  This command assists the developer in this process by recording\n  conflicted automerge results and corresponding hand resolve results on\n  the initial manual merge, and applying previously recorded hand\n  resolutions to their corresponding automerge results.\n\nBut I guess your point is valid, as we don't only do that, but also\nupdate merge conflicts locally. I'd pick your \"perform\" proposal in that\ncase and rename it to `rerere_perform()` instead. That name is somewhat\nvague, but I guess that cannot be helped because it actually does a\nbunch of things at once.\n\nI guess that can be helped with documentation though.\n\nPatrick\n\n"},{"id":"556619","messageId":"auGzVZj5vbVm3-xf@pks.im","threadId":"66677","inReplyTo":"xmqqzevzhqyq.fsf@gitster.g","subject":"Re: [PATCH 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T08:33:25Z","receivedAt":"2026-10-28T08:33:25Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:\n> \"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n> \n> > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> >> Our modern coding guidelines say that flags should typically be passed\n> >> around as enums so that it becomes trivial to see what kind of flags are\n> >> expected. Adapt the rerere flags accordingly.\n> >> \n> >>   <snip>\n> >> +enum rerere_flags {\n> >> +\tRERERE_AUTOUPDATE = (1 << 0),\n> >> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> >> +\tRERERE_READONLY = (1 << 2),\n> >> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n> >> +\tRERERE_NOWAIT = (1 << 3),\n> >> +};\n> >\n> > If we're moving to using enum flags, then wouldn't it be better to\n> > explicitly add a \"RERE_MERGE_LOCK_TOKEN\" to the enum for that case, \n> > rather than have this value only documented by a comment?\n> \n> Perhaps you misunderstand what the comment says.  It is an\n> explanation for the next line, i.e., it tells the API users \"If you\n> want the 'immediate failure when locked' behaviour, pass the _NOWAIT\n> bit\".\n\nYeah, this. I guess we can help that though by documenting all of the\nflags while at it.\n\nPatrick\n\n"},{"id":"556663","messageId":"541b09ff60a5acd851aff471cf6fba75@fastmail.com","threadId":"66677","inReplyTo":"auGzVZj5vbVm3-xf@pks.im","subject":"Re: [PATCH 02/12] rerere: convert flags into an enum","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-28T14:11:36Z","receivedAt":"2026-10-28T14:11:36Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\nOn Wed, 28 Oct 2026 09:33:25 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:\n> > \"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n> > \n> > > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> > >> Our modern coding guidelines say that flags should typically be passed\n> > >> around as enums so that it becomes trivial to see what kind of flags are\n> > >> expected. Adapt the rerere flags accordingly.\n> > >> \n> > >>   <snip>\n> > >> +enum rerere_flags {\n> > >> +\tRERERE_AUTOUPDATE = (1 << 0),\n> > >> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> > >> +\tRERERE_READONLY = (1 << 2),\n> > >> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n> > >> +\tRERERE_NOWAIT = (1 << 3),\n> > >> +};\n> > >\n> > > If we're moving to using enum flags, then wouldn't it be better to\n> > > explicitly add a \"RERE_MERGE_LOCK_TOKEN\" to the enum for that case, \n> > > rather than have this value only documented by a comment?\n> > \n> > Perhaps you misunderstand what the comment says.  It is an\n> > explanation for the next line, i.e., it tells the API users \"If you\n> > want the 'immediate failure when locked' behaviour, pass the _NOWAIT\n> > bit\".\n> \n> Yeah, this. I guess we can help that though by documenting all of the\n> flags while at it.\n\nAh, yeah. I misunderstood that. Obvious in retrospect, but I was\npuzzling over that for a while. \n\n    -Mark\n\n\n\n"},{"id":"556680","messageId":"xmqqwlr1bxnn.fsf@gitster.g","threadId":"66677","inReplyTo":"auGzRmkt6Mk6peSp@pks.im","subject":"Re: [PATCH 01/12] rerere: rename `repo_rerere()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T16:25:00Z","receivedAt":"2026-10-28T16:25:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> I was picking \"record\" because that's also what git-rerere(1) says:\n>\n>   This command assists the developer in this process by recording\n>   conflicted automerge results and corresponding hand resolve results on\n>   the initial manual merge, and applying previously recorded hand\n>   resolutions to their corresponding automerge results.\n>\n> But I guess your point is valid, as we don't only do that, but also\n> update merge conflicts locally. I'd pick your \"perform\" proposal in that\n\nYup, the description above says \"recording\" and \"applying\".\n\n> case and rename it to `rerere_perform()` instead. That name is somewhat\n> vague, but I guess that cannot be helped because it actually does a\n> bunch of things at once.\n\nLet's just call it rerere(), then.\n\nIt was the original name for the operation before it was renamed in\n35843b1123 (rerere.c: remove implicit dependency on the_index,\n2018-09-21), which taught it to take an instance of a repository\nstructure.\n\nGoing back to that original name is in line with what I said\nearlier.  The \"repo_\" prefix is a mistaken trend, and once\neverything becomes free from the_repository, it would become\nredundant and unnecessary.\n\nThanks.\n\n"},{"id":"556681","messageId":"xmqqse1pbxmv.fsf@gitster.g","threadId":"66677","inReplyTo":"auGzVZj5vbVm3-xf@pks.im","subject":"Re: [PATCH 02/12] rerere: convert flags into an enum","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T16:25:28Z","receivedAt":"2026-10-28T16:25:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:\n>> \"Mark C. Chu-Carroll\" <markchucarroll@fastmail.com> writes:\n>> \n>> > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:\n>> >> Our modern coding guidelines say that flags should typically be passed\n>> >> around as enums so that it becomes trivial to see what kind of flags are\n>> >> expected. Adapt the rerere flags accordingly.\n>> >> \n>> >>   <snip>\n>> >> +enum rerere_flags {\n>> >> +\tRERERE_AUTOUPDATE = (1 << 0),\n>> >> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n>> >> +\tRERERE_READONLY = (1 << 2),\n>> >> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n>> >> +\tRERERE_NOWAIT = (1 << 3),\n>> >> +};\n>> >\n>> > If we're moving to using enum flags, then wouldn't it be better to\n>> > explicitly add a \"RERE_MERGE_LOCK_TOKEN\" to the enum for that case, \n>> > rather than have this value only documented by a comment?\n>> \n>> Perhaps you misunderstand what the comment says.  It is an\n>> explanation for the next line, i.e., it tells the API users \"If you\n>> want the 'immediate failure when locked' behaviour, pass the _NOWAIT\n>> bit\".\n>\n> Yeah, this. I guess we can help that though by documenting all of the\n> flags while at it.\n\nGreat.\n\n"},{"id":"556746","messageId":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH v2 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:09Z","receivedAt":"2026-10-29T09:57:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nwhile reviewing some patch series around git-rerere(1) recently I was a\nbit appalled by our custom subcommand parsing that we do here. This\npatch series here thus cleans up and modernizes that part a bit so that\ngit-rerere(1) behaves like every other Git command that happens to have\nsubcommands.\n\nThis series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\nps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\nrerere cache state, 2026-10-23) merged into it.\n\nChanges in v2:\n  - Document rerere flags.\n  - Rename `rerere_record()` to just `rerere()`.\n  - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (12):\n      rerere: rename `repo_rerere()`\n      rerere: convert flags into an enum\n      builtin/rerere: drop `the_repository`\n      builtin/rerere: stop passing flags to subcommands that ignore them\n      builtin/rerere: turn \"forget\" into a proper subcommand\n      builtin/rerere: turn \"clear\" into a proper subcommand\n      builtin/rerere: turn \"status\" into a proper subcommand\n      builtin/rerere: turn \"remaining\" into a proper subcommand\n      builtin/rerere: turn \"diff\" into a proper subcommand\n      builtin/rerere: turn \"gc\" into a proper subcommand\n      builtin/rerere: use `OPT_SUBCOMMAND()`\n      builtin/rerere: introduce proper usage strings for subcommands\n\n Documentation/git-rerere.adoc |   8 +-\n apply.c                       |   2 +-\n builtin/am.c                  |   4 +-\n builtin/commit.c              |   2 +-\n builtin/merge.c               |   2 +-\n builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------\n builtin/stash.c               |   2 +-\n rerere.c                      |  12 +-\n rerere.h                      |  37 +++--\n sequencer.c                   |   4 +-\n t/t4200-rerere.sh             |   5 -\n 11 files changed, 291 insertions(+), 106 deletions(-)\n\nRange-diff versus v1:\n\n 1:  ce75cde848d !  1:  1f3fbbad575 rerere: rename `repo_rerere()`\n    @@ Commit message\n         repository as first parameter, that's not a good-enough reason to give\n         it a `repo_` prefix.\n     \n    -    Rename the function to `rerere_record()` to be consistent with all the\n    -    other functions.\n    +    Rename the function to just `rerere()`. Move around and extend\n    +    documentation of this function to better explain what it does.\n     \n         Signed-off-by: Patrick Steinhardt <ps@pks.im>\n     \n    @@ apply.c: static int write_out_results(struct apply_state *state, struct patch *l\n      \t\t */\n      \t\tif (!state->cached)\n     -\t\t\trepo_rerere(state->repo, 0);\n    -+\t\t\trerere_record(state->repo, 0);\n    ++\t\t\trerere(state->repo, 0);\n      \t}\n      \n      \treturn errs;\n    @@ builtin/am.c: static int fall_back_threeway(const struct am_state *state, const\n      \n      \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n     -\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n    -+\t\trerere_record(the_repository, state->allow_rerere_autoupdate);\n    ++\t\trerere(the_repository, state->allow_rerere_autoupdate);\n      \t\tfree(their_tree_name);\n      \t\treturn error(_(\"Failed to merge in the changes.\"));\n      \t}\n    @@ builtin/am.c: static void am_resolve(struct am_state *state, int allow_empty)\n      \t}\n      \n     -\trepo_rerere(the_repository, 0);\n    -+\trerere_record(the_repository, 0);\n    ++\trerere(the_repository, 0);\n      \n      \tdo_commit(state);\n      \n    @@ builtin/commit.c: int cmd_commit(int argc,\n      \tgit_test_write_commit_graph_or_die(the_repository);\n      \n     -\trepo_rerere(the_repository, 0);\n    -+\trerere_record(the_repository, 0);\n    ++\trerere(the_repository, 0);\n      \trun_auto_maintenance(the_repository, quiet);\n      \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n      \t\t\tNULL, \"post-commit\", NULL);\n    @@ builtin/merge.c: static int suggest_conflicts(void)\n      \tstrbuf_release(&msgbuf);\n      \tfclose(fp);\n     -\trepo_rerere(the_repository, allow_rerere_auto);\n    -+\trerere_record(the_repository, allow_rerere_auto);\n    ++\trerere(the_repository, allow_rerere_auto);\n      \tprintf(_(\"Automatic merge failed; \"\n      \t\t\t\"fix conflicts and then commit the result.\\n\"));\n      \treturn 1;\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n      \n      \tif (argc < 1)\n     -\t\treturn repo_rerere(the_repository, flags);\n    -+\t\treturn rerere_record(the_repository, flags);\n    ++\t\treturn rerere(the_repository, flags);\n      \n      \tif (!strcmp(argv[0], \"forget\")) {\n      \t\tstruct pathspec pathspec;\n    @@ builtin/stash.c: static enum stash_apply_result do_apply_stash(const char *prefi\n      \n      \tif (ret) {\n     -\t\trepo_rerere(the_repository, 0);\n    -+\t\trerere_record(the_repository, 0);\n    ++\t\trerere(the_repository, 0);\n      \n      \t\tif (index)\n      \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\n     \n      ## rerere.c ##\n     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n    -  * perform mergy operations, possibly leaving conflicted index entries\n    -  * and working tree files.\n    -  */\n    + \treturn fd;\n    + }\n    + \n    +-/*\n    +- * The main entry point that is called internally from codepaths that\n    +- * perform mergy operations, possibly leaving conflicted index entries\n    +- * and working tree files.\n    +- */\n     -int repo_rerere(struct repository *r, int flags)\n    -+int rerere_record(struct repository *r, int flags)\n    ++int rerere(struct repository *r, int flags)\n      {\n      \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n      \tstruct rerere_cache cache;\n    @@ rerere.h: int rerere_cache_setup(struct rerere_cache *cache,\n      void rerere_cache_release(struct rerere_cache *cache);\n      \n     -int repo_rerere(struct repository *, int);\n    -+int rerere_record(struct repository *, int);\n    ++/*\n    ++ * The main entry point that is called internally from codepaths that\n    ++ * perform mergy operations, possibly leaving conflicted index entries\n    ++ * and working tree files. It records (and optionally updates) resolved\n    ++ * conflicts and reuses recorded resolutions for unresolved conflicts.\n    ++ */\n    ++int rerere(struct repository *r, int flags);\n    ++\n      /*\n       * Given the conflict ID and the name of a \"file\" used for replaying\n       * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\n    @@ sequencer.c: static enum pick_result do_pick_commit(struct repository *r,\n      \t\t      short_commit_name(r, commit), msg.subject);\n      \t\tprint_advice(r, res == 1, opts);\n     -\t\trepo_rerere(r, opts->allow_rerere_auto);\n    -+\t\trerere_record(r, opts->allow_rerere_auto);\n    ++\t\trerere(r, opts->allow_rerere_auto);\n      \t\tgoto leave;\n      \t}\n      \n    @@ sequencer.c: static int do_merge(struct repository *r,\n      \trollback_lock_file(&lock);\n      \tif (ret)\n     -\t\trepo_rerere(r, opts->allow_rerere_auto);\n    -+\t\trerere_record(r, opts->allow_rerere_auto);\n    ++\t\trerere(r, opts->allow_rerere_auto);\n      \telse\n      \t\t/*\n      \t\t * In case of problems, we now want to return a positive\n 2:  18259e1556a !  2:  e910458a47c rerere: convert flags into an enum\n    @@ Commit message\n     \n         Our modern coding guidelines say that flags should typically be passed\n         around as enums so that it becomes trivial to see what kind of flags are\n    -    expected. Adapt the rerere flags accordingly.\n    +    expected. Adapt the rerere flags accordingly and document them.\n     \n         Signed-off-by: Patrick Steinhardt <ps@pks.im>\n     \n    @@ rerere.c: static int is_rerere_enabled(struct repository *r)\n      \tint lock_timeout_ms = 1000;\n      \tint fd;\n     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n    -  * perform mergy operations, possibly leaving conflicted index entries\n    -  * and working tree files.\n    -  */\n    --int rerere_record(struct repository *r, int flags)\n    -+int rerere_record(struct repository *r, enum rerere_flags flags)\n    + \treturn fd;\n    + }\n    + \n    +-int rerere(struct repository *r, int flags)\n    ++int rerere(struct repository *r, enum rerere_flags flags)\n      {\n      \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n      \tstruct rerere_cache cache;\n    @@ rerere.h: struct rerere_id {\n      };\n      \n     +enum rerere_flags {\n    ++\t/*\n    ++\t * Auto-update the index with previously recorded resolutions. This can\n    ++\t * be used to explicitly override \"rerere.autoUpdate\".\n    ++\t */\n     +\tRERERE_AUTOUPDATE = (1 << 0),\n    ++\n    ++\t/* Reverse of RERERE_AUTOUPDATE. */\n     +\tRERERE_NOAUTOUPDATE = (1 << 1),\n    ++\n    ++\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n     +\tRERERE_READONLY = (1 << 2),\n    -+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n    ++\n    ++\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n     +\tRERERE_NOWAIT = (1 << 3),\n     +};\n     +\n    @@ rerere.h: struct rerere_id {\n     +\t\t       enum rerere_flags flags);\n      void rerere_cache_release(struct rerere_cache *cache);\n      \n    --int rerere_record(struct repository *, int);\n    -+int rerere_record(struct repository *r, enum rerere_flags flags);\n    + /*\n    +@@ rerere.h: void rerere_cache_release(struct rerere_cache *cache);\n    +  * and working tree files. It records (and optionally updates) resolved\n    +  * conflicts and reuses recorded resolutions for unresolved conflicts.\n    +  */\n    +-int rerere(struct repository *r, int flags);\n    ++int rerere(struct repository *r, enum rerere_flags flags);\n    + \n      /*\n       * Given the conflict ID and the name of a \"file\" used for replaying\n    -  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\n     @@ rerere.h: const char *rerere_path(struct repository *,\n      int rerere_forget(struct repository *, struct pathspec *);\n      int rerere_remaining(struct repository *, struct string_list *);\n 3:  89ae664d90d !  3:  5254d1ac3ba builtin/rerere: drop `the_repository`\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n      \t\tflags = RERERE_NOAUTOUPDATE;\n      \n      \tif (argc < 1)\n    --\t\treturn rerere_record(the_repository, flags);\n    -+\t\treturn rerere_record(repo, flags);\n    +-\t\treturn rerere(the_repository, flags);\n    ++\t\treturn rerere(repo, flags);\n      \n      \tif (!strcmp(argv[0], \"forget\")) {\n      \t\tstruct pathspec pathspec;\n 4:  5eff73de7bc =  4:  8b24e253e6b builtin/rerere: stop passing flags to subcommands that ignore them\n 5:  621c5f6ab1b !  5:  43dde532e63 builtin/rerere: turn \"forget\" into a proper subcommand\n    @@ builtin/rerere.c: static int diff_two(const char *file1, const char *label1,\n      \t       const char *prefix,\n     @@ builtin/rerere.c: int cmd_rerere(int argc,\n      \tif (argc < 1)\n    - \t\treturn rerere_record(repo, flags);\n    + \t\treturn rerere(repo, flags);\n      \n     -\tif (!strcmp(argv[0], \"forget\")) {\n     -\t\tstruct pathspec pathspec;\n 6:  d01fa02064c =  6:  13fd07a2f53 builtin/rerere: turn \"clear\" into a proper subcommand\n 7:  2bebea6449e =  7:  c5d48081cc9 builtin/rerere: turn \"status\" into a proper subcommand\n 8:  5594019f31f =  8:  5c6891f6a48 builtin/rerere: turn \"remaining\" into a proper subcommand\n 9:  e8a2f8ce209 =  9:  b7ed9ef810b builtin/rerere: turn \"diff\" into a proper subcommand\n10:  deebcee0379 = 10:  0ceff6d241b builtin/rerere: turn \"gc\" into a proper subcommand\n11:  56037e9a761 ! 11:  3b8b4b65a53 builtin/rerere: use `OPT_SUBCOMMAND()`\n    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,\n      \treturn 0;\n      }\n      \n    -+static int cmd_rerere_record(int argc,\n    -+\t\t\t     const char **argv,\n    -+\t\t\t     const char *prefix,\n    -+\t\t\t     struct repository *repo)\n    ++static int cmd_rerere_perform(int argc,\n    ++\t\t\t      const char **argv,\n    ++\t\t\t      const char *prefix,\n    ++\t\t\t      struct repository *repo)\n     +{\n     +\tint autoupdate = -1;\n     +\tstruct option options[] = {\n    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,\n     +\tif (autoupdate == 0)\n     +\t\tflags = RERERE_NOAUTOUPDATE;\n     +\n    -+\treturn rerere_record(repo, flags);\n    ++\treturn rerere(repo, flags);\n     +}\n     +\n      static int cmd_rerere_remaining(int argc,\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     +\t\tint ret;\n      \n     -\tif (argc < 1)\n    --\t\treturn rerere_record(repo, flags);\n    +-\t\treturn rerere(repo, flags);\n     -\n     -\tif (!strcmp(argv[0], \"forget\"))\n     -\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     -\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n     -\telse\n     -\t\tusage_with_options(rerere_usage, options);\n    -+\t\tstrvec_push(&args, \"record\");\n    ++\t\tstrvec_push(&args, \"perform\");\n     +\t\tstrvec_pushv(&args, argv);\n      \n     -\treturn 0;\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     +\t\tCALLOC_ARRAY(args_copy, args.nr);\n     +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n     +\n    -+\t\tret = cmd_rerere_record(args.nr, args_copy, prefix, repo);\n    ++\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n     +\n     +\t\tstrvec_clear(&args);\n     +\t\tfree(args_copy);\n12:  102223da27b ! 12:  05adadc9dd8 builtin/rerere: introduce proper usage strings for subcommands\n    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,\n      \tif (argc)\n      \t\tusage(_(\"too many arguments\"));\n      \n    -@@ builtin/rerere.c: static int cmd_rerere_record(int argc,\n    +@@ builtin/rerere.c: static int cmd_rerere_perform(int argc,\n      \t\t\tN_(\"register clean resolutions in index\"), 1),\n      \t\tOPT_END(),\n      \t};\n\n---\nbase-commit: 710910c03a22ac663885049213b9fef5853ea8e0\nchange-id: 20261027-pks-rerere-subcommands-318d41553438\n\n\n"},{"id":"556747","messageId":"20261029-pks-rerere-subcommands-v2-1-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 01/12] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:10Z","receivedAt":"2026-10-29T09:57:10Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `repo_rerere()` function is the only function in \"rerere.h\" that\ndoes not have a `rerere_` prefix. And while it does indeed receive a\nrepository as first parameter, that's not a good-enough reason to give\nit a `repo_` prefix.\n\nRename the function to just `rerere()`. Move around and extend\ndocumentation of this function to better explain what it does.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n apply.c          | 2 +-\n builtin/am.c     | 4 ++--\n builtin/commit.c | 2 +-\n builtin/merge.c  | 2 +-\n builtin/rerere.c | 2 +-\n builtin/stash.c  | 2 +-\n rerere.c         | 7 +------\n rerere.h         | 9 ++++++++-\n sequencer.c      | 4 ++--\n 9 files changed, 18 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex a0b7119c639..646fabeafa3 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t * tree with conflict markers, but that isn't written with --cached.\n \t\t */\n \t\tif (!state->cached)\n-\t\t\trepo_rerere(state->repo, 0);\n+\t\t\trerere(state->repo, 0);\n \t}\n \n \treturn errs;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e9623b83077..4a5b37bee00 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\to.verbosity = 0;\n \n \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n-\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n+\t\trerere(the_repository, state->allow_rerere_autoupdate);\n \t\tfree(their_tree_name);\n \t\treturn error(_(\"Failed to merge in the changes.\"));\n \t}\n@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t\tgoto next;\n \t}\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \n \tdo_commit(state);\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8ffd42681bb..3a4b94ad623 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,\n \n \tgit_test_write_commit_graph_or_die(the_repository);\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \trun_auto_maintenance(the_repository, quiet);\n \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n \t\t\tNULL, \"post-commit\", NULL);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d7bf209114f..089e36e8575 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\n-\trepo_rerere(the_repository, allow_rerere_auto);\n+\trerere(the_repository, allow_rerere_auto);\n \tprintf(_(\"Automatic merge failed; \"\n \t\t\t\"fix conflicts and then commit the result.\\n\"));\n \treturn 1;\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2c17f02f56d..a499e7b9151 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -83,7 +83,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn repo_rerere(the_repository, flags);\n+\t\treturn rerere(the_repository, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex e1a3a76bd04..91870a255fd 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,\n \t\tret = error(_(\"could not write index\"));\n \n \tif (ret) {\n-\t\trepo_rerere(the_repository, 0);\n+\t\trerere(the_repository, 0);\n \n \t\tif (index)\n \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\ndiff --git a/rerere.c b/rerere.c\nindex e0897612085..47a4a325bf5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-/*\n- * The main entry point that is called internally from codepaths that\n- * perform mergy operations, possibly leaving conflicted index entries\n- * and working tree files.\n- */\n-int repo_rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, int flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\ndiff --git a/rerere.h b/rerere.h\nindex d3cbd10e13f..dd9da03d6db 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       int flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int repo_rerere(struct repository *, int);\n+/*\n+ * The main entry point that is called internally from codepaths that\n+ * perform mergy operations, possibly leaving conflicted index entries\n+ * and working tree files. It records (and optionally updates) resolved\n+ * conflicts and reuses recorded resolutions for unresolved conflicts.\n+ */\n+int rerere(struct repository *r, int flags);\n+\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\ndiff --git a/sequencer.c b/sequencer.c\nindex 508ec717920..ace1cfac1cb 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(r, commit), msg.subject);\n \t\tprint_advice(r, res == 1, opts);\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556748","messageId":"20261029-pks-rerere-subcommands-v2-2-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:11Z","receivedAt":"2026-10-29T09:57:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Our modern coding guidelines say that flags should typically be passed\naround as enums so that it becomes trivial to see what kind of flags are\nexpected. Adapt the rerere flags accordingly and document them.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n rerere.c |  7 ++++---\n rerere.h | 30 +++++++++++++++++++++---------\n 2 files changed, 25 insertions(+), 12 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 47a4a325bf5..3652b7ac2d5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags)\n+\t\t       enum rerere_flags flags)\n {\n \tint lock_timeout_ms = 1000;\n \tint fd;\n@@ -951,7 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-int rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, enum rerere_flags flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n@@ -1336,7 +1336,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)\n \treturn needed;\n }\n \n-void rerere_gc(struct repository *r, struct string_list *rr, int flags)\n+void rerere_gc(struct repository *r, struct string_list *rr,\n+\t       enum rerere_flags flags)\n {\n \tstruct rerere_cache cache;\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\ndiff --git a/rerere.h b/rerere.h\nindex dd9da03d6db..f13790c5dcd 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -9,12 +9,6 @@\n struct pathspec;\n struct repository;\n \n-#define RERERE_AUTOUPDATE   01\n-#define RERERE_NOAUTOUPDATE 02\n-#define RERERE_READONLY     04\n-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n-#define RERERE_NOWAIT       010\n-\n /*\n  * Marks paths that have been hand-resolved and added to the\n  * index. Set in the util field of such paths after calling\n@@ -39,10 +33,27 @@ struct rerere_id {\n \tint variant;\n };\n \n+enum rerere_flags {\n+\t/*\n+\t * Auto-update the index with previously recorded resolutions. This can\n+\t * be used to explicitly override \"rerere.autoUpdate\".\n+\t */\n+\tRERERE_AUTOUPDATE = (1 << 0),\n+\n+\t/* Reverse of RERERE_AUTOUPDATE. */\n+\tRERERE_NOAUTOUPDATE = (1 << 1),\n+\n+\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n+\tRERERE_READONLY = (1 << 2),\n+\n+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n+\tRERERE_NOWAIT = (1 << 3),\n+};\n+\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags);\n+\t\t       enum rerere_flags flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n /*\n@@ -51,7 +62,7 @@ void rerere_cache_release(struct rerere_cache *cache);\n  * and working tree files. It records (and optionally updates) resolved\n  * conflicts and reuses recorded resolutions for unresolved conflicts.\n  */\n-int rerere(struct repository *r, int flags);\n+int rerere(struct repository *r, enum rerere_flags flags);\n \n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n@@ -65,7 +76,8 @@ const char *rerere_path(struct repository *,\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n void rerere_clear(struct repository *, struct string_list *);\n-void rerere_gc(struct repository *, struct string_list *, int);\n+void rerere_gc(struct repository *, struct string_list *,\n+\t       enum rerere_flags flags);\n \n /*\n  * Check whether garbage collection for rerere entries is needed, which is\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556749","messageId":"20261029-pks-rerere-subcommands-v2-3-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 03/12] builtin/rerere: drop `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:12Z","receivedAt":"2026-10-29T09:57:12Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in git-rerere(1).\nAs that command cannot run outside of a repository these references can\nbe trivially replaced by the repository that's passed in as parameter to\n`cmd_rerere()`. We don't have to worry about the repository being `NULL`\nwhen called with \"-h\", either, as there are no references to the repo\nbefore we call `parse_options()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 24 +++++++++++-------------\n 1 file changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex a499e7b9151..83fb3783c61 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint autoupdate = -1, skip_locked = 0, flags = 0;\n@@ -75,7 +73,7 @@ int cmd_rerere(int argc,\n \tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n \t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n \n-\trepo_config(the_repository, git_xmerge_config, NULL);\n+\trepo_config(repo, git_xmerge_config, NULL);\n \n \tif (autoupdate == 1)\n \t\tflags = RERERE_AUTOUPDATE;\n@@ -83,7 +81,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn rerere(the_repository, flags);\n+\t\treturn rerere(repo, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\n@@ -94,21 +92,21 @@ int cmd_rerere(int argc,\n \t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n \t\t\t       prefix, argv + 1);\n \n-\t\tret = rerere_forget(the_repository, &pathspec);\n+\t\tret = rerere_forget(repo, &pathspec);\n \n \t\tclear_pathspec(&pathspec);\n \t\treturn ret;\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(the_repository, &merge_rr);\n+\t\trerere_clear(repo, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(the_repository, &merge_rr,\n+\t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\")) {\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t       flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n@@ -116,7 +114,7 @@ int cmd_rerere(int argc,\n \n \t\trerere_cache_release(&cache);\n \t} else if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(the_repository, &merge_rr);\n+\t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n \t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -129,16 +127,16 @@ int cmd_rerere(int argc,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t      flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n \t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(the_repository, &buf, id, \"preimage\"),\n+\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n \t\t\t\t     path, path, path))\n \t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(the_repository, &buf, id, NULL));\n+\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n \t\t}\n \n \t\trerere_cache_release(&cache);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556750","messageId":"20261029-pks-rerere-subcommands-v2-4-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 04/12] builtin/rerere: stop passing flags to subcommands that ignore them","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:13Z","receivedAt":"2026-10-29T09:57:13Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has a \"--[no-]rerere-autoupdate\" flag. If\npassed, we explicitly enable or disable recording clean merge\nresolutions that are staged in the index. This flag only matters to\ngit-rerere(1) when not executed with any subcommand, but we also forward\nthe flag to `git rerere status` and `git rerere diff`.\n\nThis is mostly harmless as we would ignore those flags anyway, but it\nmakes subsequent refactorings harder to understand. Prepare for these\nrefactorings by not using the flag in those subcommands anymore.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 83fb3783c61..405276cc94b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -107,7 +107,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -128,7 +128,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t      flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556751","messageId":"20261029-pks-rerere-subcommands-v2-5-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 05/12] builtin/rerere: turn \"forget\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:14Z","receivedAt":"2026-10-29T09:57:14Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has its own, home-grown implementation of\nsubcommands. Of course this implementation is inconsistent with how\nsubcommands typically work:\n\n  - Options from other subcommands apply to each other.\n\n  - We don't have proper usage strings.\n\n  - Running `git rerere <subcmd> -h` doesn't print the options that are\n    supported by that subcommand, but instead it just prints the help of\n    git-rerere(1) itself.\n\nA subsequent commit will thus introduce proper subcommands as supported\nby our parse-options subsystem. Refactor the \"forget\" subcommand to use\nparse-options as a preparatory step. The other commands will follow in\nsubsequent commits until all of them have been converted, and then we\nswitch over to `OPT_SUBCOMMAND()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 38 ++++++++++++++++++++++++--------------\n 1 file changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 405276cc94b..5d2ae154ff8 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_forget(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct pathspec pathspec;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (!argc)\n+\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n+\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n+\n+\tret = rerere_forget(repo, &pathspec);\n+\n+\tclear_pathspec(&pathspec);\n+\treturn ret;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -83,20 +105,8 @@ int cmd_rerere(int argc,\n \tif (argc < 1)\n \t\treturn rerere(repo, flags);\n \n-\tif (!strcmp(argv[0], \"forget\")) {\n-\t\tstruct pathspec pathspec;\n-\t\tint ret;\n-\n-\t\tif (argc < 2)\n-\t\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n-\t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n-\t\t\t       prefix, argv + 1);\n-\n-\t\tret = rerere_forget(repo, &pathspec);\n-\n-\t\tclear_pathspec(&pathspec);\n-\t\treturn ret;\n-\t}\n+\tif (!strcmp(argv[0], \"forget\"))\n+\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n \n \tif (!strcmp(argv[0], \"clear\")) {\n \t\trerere_clear(repo, &merge_rr);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556752","messageId":"20261029-pks-rerere-subcommands-v2-6-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 06/12] builtin/rerere: turn \"clear\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:15Z","receivedAt":"2026-10-29T09:57:15Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"clear\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 25 ++++++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 5d2ae154ff8..62f69b488b0 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_clear(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_clear(repo, &merge_rr);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -107,9 +127,8 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\n-\tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(repo, &merge_rr);\n+\telse if (!strcmp(argv[0], \"clear\")) {\n+\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556753","messageId":"20261029-pks-rerere-subcommands-v2-7-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 07/12] builtin/rerere: turn \"status\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:16Z","receivedAt":"2026-10-29T09:57:16Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"status\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------\n 1 file changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 62f69b488b0..2bcd270a1f1 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_status(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\tfor (size_t i = 0; i < merge_rr.nr; i++)\n+\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\treturn 0;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -132,17 +158,9 @@ int cmd_rerere(int argc,\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n-\telse if (!strcmp(argv[0], \"status\")) {\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n-\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\n-\t\trerere_cache_release(&cache);\n-\t} else if (!strcmp(argv[0], \"remaining\")) {\n+\telse if (!strcmp(argv[0], \"status\"))\n+\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"remaining\")) {\n \t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556754","messageId":"20261029-pks-rerere-subcommands-v2-8-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 08/12] builtin/rerere: turn \"remaining\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:17Z","receivedAt":"2026-10-29T09:57:17Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"remaining\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------\n 1 file changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2bcd270a1f1..3f82bcbeb10 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_remaining(int argc,\n+\t\t\t\tconst char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_remaining(repo, &merge_rr);\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n+\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\t\telse\n+\t\t\t/* prepare for later call to\n+\t\t\t * string_list_clear() */\n+\t\t\tmerge_rr.items[i].util = NULL;\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_status(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -160,17 +188,9 @@ int cmd_rerere(int argc,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(repo, &merge_rr);\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n-\t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\t\t\telse\n-\t\t\t\t/* prepare for later call to\n-\t\t\t\t * string_list_clear() */\n-\t\t\t\tmerge_rr.items[i].util = NULL;\n-\t\t}\n-\t} else if (!strcmp(argv[0], \"diff\")) {\n+\telse if (!strcmp(argv[0], \"remaining\"))\n+\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"diff\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556755","messageId":"20261029-pks-rerere-subcommands-v2-9-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 09/12] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:18Z","receivedAt":"2026-10-29T09:57:18Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"diff\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3f82bcbeb10..40bae5cb9cc 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_diff(int argc,\n+\t\t\t   const char **argv,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tconst char *path = merge_rr.items[i].string;\n+\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n+\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"), path, path, path))\n+\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n+\t\t\t    rerere_path(repo, &buf, id, NULL));\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -190,25 +224,9 @@ int cmd_rerere(int argc,\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n \t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\")) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tconst char *path = merge_rr.items[i].string;\n-\t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n-\t\t\t\t     path, path, path))\n-\t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n-\t\t}\n-\n-\t\trerere_cache_release(&cache);\n-\t\tstrbuf_release(&buf);\n-\t} else\n+\telse if (!strcmp(argv[0], \"diff\"))\n+\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n+\telse\n \t\tusage_with_options(rerere_usage, options);\n \n \tstring_list_clear(&merge_rr, 1);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556756","messageId":"20261029-pks-rerere-subcommands-v2-10-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:19Z","receivedAt":"2026-10-29T09:57:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"gc\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n t/t4200-rerere.sh |  5 -----\n 2 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 40bae5cb9cc..3162b074ec6 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_gc(int argc,\n+\t\t\t const char **argv,\n+\t\t\t const char *prefix,\n+\t\t\t struct repository *repo)\n+{\n+\tint skip_locked = 0;\n+\tstruct option options[] = {\n+\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n+\t\t\t\tN_(\"skip gc while another process holds the lock\")),\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_gc(repo, &merge_rr,\n+\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -187,21 +211,16 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\tint autoupdate = -1, skip_locked = 0, flags = 0;\n+\tint autoupdate = -1, flags = 0;\n \n \tstruct option options[] = {\n \t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n-\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n-\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n-\n-\tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n-\t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage,\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_config(repo, git_xmerge_config, NULL);\n \n@@ -215,11 +234,10 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\")) {\n+\telse if (!strcmp(argv[0], \"clear\"))\n \t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(repo, &merge_rr,\n-\t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\telse if (!strcmp(argv[0], \"gc\"))\n+\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n@@ -229,6 +247,5 @@ int cmd_rerere(int argc,\n \telse\n \t\tusage_with_options(rerere_usage, options);\n \n-\tstring_list_clear(&merge_rr, 1);\n \treturn 0;\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex ab412ecc6e8..0d4cbf5114a 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n \ttest_path_is_missing $rr2/preimage\n '\n \n-test_expect_success '--skip-locked is only accepted by gc' '\n-\ttest_must_fail git rerere --skip-locked clear 2>err &&\n-\ttest_grep \"option .--skip-locked. requires .gc.\" err\n-'\n-\n test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n \tgit reset --hard &&\n \trm -rf $rr &&\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556757","messageId":"20261029-pks-rerere-subcommands-v2-11-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:20Z","receivedAt":"2026-10-29T09:57:20Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In git-rerere(1) we have our own custom logic to parse subcommands. In\npreceding commits we have refactored all of those subcommands so that\nthey are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\nthese so that we get rid of our custom subcommand parsing.\n\nUnfortunately this means that we have a backwards-incompatible change\nbecause we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\nsubcommands. But this was arguably broken and misleading as we ignore\nthis flag for any other subcommand aynway. So we cheat a bit and simply\ncall it a bug that those flags were accepted in the first place.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 56 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3162b074ec6..97c791e420b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -5,6 +5,7 @@\n #include \"rerere.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_perform(int argc,\n+\t\t\t      const char **argv,\n+\t\t\t      const char *prefix,\n+\t\t\t      struct repository *repo)\n+{\n+\tint autoupdate = -1;\n+\tstruct option options[] = {\n+\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n+\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_END(),\n+\t};\n+\tenum rerere_flags flags = 0;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (autoupdate == 1)\n+\t\tflags = RERERE_AUTOUPDATE;\n+\tif (autoupdate == 0)\n+\t\tflags = RERERE_NOAUTOUPDATE;\n+\n+\treturn rerere(repo, flags);\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tint autoupdate = -1, flags = 0;\n-\n+\tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n-\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n-\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n+\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n+\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n+\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n+\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n+\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n-\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \trepo_config(repo, git_xmerge_config, NULL);\n \n-\tif (autoupdate == 1)\n-\t\tflags = RERERE_AUTOUPDATE;\n-\tif (autoupdate == 0)\n-\t\tflags = RERERE_NOAUTOUPDATE;\n+\tif (!fn) {\n+\t\tstruct strvec args = STRVEC_INIT;\n+\t\tconst char **args_copy;\n+\t\tint ret;\n \n-\tif (argc < 1)\n-\t\treturn rerere(repo, flags);\n-\n-\tif (!strcmp(argv[0], \"forget\"))\n-\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\"))\n-\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"gc\"))\n-\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"status\"))\n-\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\"))\n-\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\"))\n-\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n-\telse\n-\t\tusage_with_options(rerere_usage, options);\n+\t\tstrvec_push(&args, \"perform\");\n+\t\tstrvec_pushv(&args, argv);\n \n-\treturn 0;\n+\t\t/*\n+\t\t * We need to copy the array as it will be modified by\n+\t\t * `parse_options()`, and if so we leak the strings\n+\t\t * referenced by `args`.\n+\t\t */\n+\t\tCALLOC_ARRAY(args_copy, args.nr);\n+\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n+\n+\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n+\n+\t\tstrvec_clear(&args);\n+\t\tfree(args_copy);\n+\t\treturn ret;\n+\t}\n+\n+\treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556758","messageId":"20261029-pks-rerere-subcommands-v2-12-07d5ba18e882@pks.im","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"[PATCH v2 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T09:57:21Z","receivedAt":"2026-10-29T09:57:21Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Adapt git-rerere(1) to have proper usage strings for each of the\nsubcommands.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc |  8 +++++-\n builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex 4e6ab9a27c9..e04e9ef3ef8 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n SYNOPSIS\n --------\n [verse]\n-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n+'git rerere' [--[no-]rerere-autoupdate]\n+'git rerere' clear\n+'git rerere' diff\n+'git rerere' forget <pathspec>...\n+'git rerere' gc\n+'git rerere' remaining\n+'git rerere' status\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 97c791e420b..051e50838ce 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -10,10 +10,13 @@\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n \n-static const char * const rerere_usage[] = {\n-\tN_(\"git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\"),\n-\tNULL,\n-};\n+#define RERERE_USAGE N_(\"git rerere [--[no-]rerere-autoupdate]\")\n+#define RERERE_CLEAR_USAGE N_(\"git rerere clear\")\n+#define RERERE_DIFF_USAGE N_(\"git rerere diff\")\n+#define RERERE_FORGET_USAGE N_(\"git rerere forget <pathspec>...\")\n+#define RERERE_GC_USAGE N_(\"git rerere gc\")\n+#define RERERE_REMAINING_USAGE N_(\"git rerere remaining\")\n+#define RERERE_STATUS_USAGE N_(\"git rerere status\")\n \n static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)\n {\n@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_clear_usage[] = {\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_diff_usage[] = {\n+\t\tRERERE_DIFF_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_forget_usage[] = {\n+\t\tRERERE_FORGET_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct pathspec pathspec;\n \tint ret;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);\n \tif (!argc)\n \t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n \tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,\n \t\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_gc_usage[] = {\n+\t\tRERERE_GC_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tNULL,\n+\t};\n \tenum rerere_flags flags = 0;\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_remaining_usage[] = {\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_status_usage[] = {\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -247,6 +278,16 @@ int cmd_rerere(int argc,\n \t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tRERERE_DIFF_USAGE,\n+\t\tRERERE_FORGET_USAGE,\n+\t\tRERERE_GC_USAGE,\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"557659","messageId":"CAOLa=ZT6XJK_duCu5E+i-PxXzaCt-JUOsHAsTdysc7EYY3pBdg@mail.gmail.com","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-2-07d5ba18e882@pks.im","subject":"Re: [PATCH v2 02/12] rerere: convert flags into an enum","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-06T10:51:13Z","receivedAt":"2026-11-06T10:51:13Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> diff --git a/rerere.h b/rerere.h\n> index dd9da03d6db..f13790c5dcd 100644\n> --- a/rerere.h\n> +++ b/rerere.h\n> @@ -39,10 +33,27 @@ struct rerere_id {\n>  \tint variant;\n>  };\n>\n> +enum rerere_flags {\n> +\t/*\n> +\t * Auto-update the index with previously recorded resolutions. This can\n> +\t * be used to explicitly override \"rerere.autoUpdate\".\n> +\t */\n> +\tRERERE_AUTOUPDATE = (1 << 0),\n> +\n> +\t/* Reverse of RERERE_AUTOUPDATE. */\n> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> +\n\nNit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict\nresolution information to the stderr instead of updating the index.\nPerhaps that's something to document?\n\n> +\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n> +\tRERERE_READONLY = (1 << 2),\n> +\n> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n> +\tRERERE_NOWAIT = (1 << 3),\n> +};\n> +\n>  int rerere_cache_setup(struct rerere_cache *cache,\n>  \t\t       struct repository *r,\n>  \t\t       struct string_list *merge_rr,\n> -\t\t       int flags);\n> +\t\t       enum rerere_flags flags);\n>  void rerere_cache_release(struct rerere_cache *cache);\n>\n>  /*\n"},{"id":"557660","messageId":"CAOLa=ZTSxrEA5bq1_7WdjLOxGoZ5WXma0kb24hDAhfteVpXj6Q@mail.gmail.com","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-10-07d5ba18e882@pks.im","subject":"Re: [PATCH v2 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-06T10:56:58Z","receivedAt":"2026-11-06T10:56:58Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> As explained in a preceding commit, a subsequent commit will introduce\n> proper subcommands as supported by our parse-options subsystem. Refactor\n> the \"gc\" subcommand to use parse-options as a preparatory step.\n>\n\nOkay so the commits till here are mostly straightforward extraction to\nprepare for the subcommand introduction. Reading on....\n"},{"id":"557665","messageId":"au28e2L4LEMziCfI@pks.im","threadId":"66677","inReplyTo":"CAOLa=ZT6XJK_duCu5E+i-PxXzaCt-JUOsHAsTdysc7EYY3pBdg@mail.gmail.com","subject":"Re: [PATCH v2 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T11:39:49Z","receivedAt":"2026-11-06T11:39:49Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 05:51:13AM -0500, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > diff --git a/rerere.h b/rerere.h\n> > index dd9da03d6db..f13790c5dcd 100644\n> > --- a/rerere.h\n> > +++ b/rerere.h\n> > @@ -39,10 +33,27 @@ struct rerere_id {\n> >  \tint variant;\n> >  };\n> >\n> > +enum rerere_flags {\n> > +\t/*\n> > +\t * Auto-update the index with previously recorded resolutions. This can\n> > +\t * be used to explicitly override \"rerere.autoUpdate\".\n> > +\t */\n> > +\tRERERE_AUTOUPDATE = (1 << 0),\n> > +\n> > +\t/* Reverse of RERERE_AUTOUPDATE. */\n> > +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> > +\n> \n> Nit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict\n> resolution information to the stderr instead of updating the index.\n> Perhaps that's something to document?\n\nWell, the fact that it prints to stderr is not specific to NOAUTOUPDATE.\nWe print messages in both cases, just at different times:\n\n  - When `RERERE_AUTOUPDATE` is set we print the messages in\n    `update_paths()`.\n\n  - When `RERERE_NOAUTOUPDATE` is set (or `RERERE_AUTOUPDATE` is simply\n    unset) then we print the message in `do_rerere_one_path()`.\n\nThe messages are different of course, but I don't really think that this\nmatters for the flag here. What we might want to say though is that we\ndon't update the index, but the working tree does get updated.\n\nWill adapt, thanks.\n\nPatrick\n\n"},{"id":"557666","messageId":"CAOLa=ZQrOyA2k+5EDmh+VJD=gC=68m3D17uKvNUTmaxH2FuNZg@mail.gmail.com","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-11-07d5ba18e882@pks.im","subject":"Re: [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-06T11:44:38Z","receivedAt":"2026-11-06T11:44:38Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In git-rerere(1) we have our own custom logic to parse subcommands. In\n> preceding commits we have refactored all of those subcommands so that\n> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\n> these so that we get rid of our custom subcommand parsing.\n>\n> Unfortunately this means that we have a backwards-incompatible change\n> because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n> subcommands. But this was arguably broken and misleading as we ignore\n> this flag for any other subcommand aynway. So we cheat a bit and simply\n> call it a bug that those flags were accepted in the first place.\n>\n\nOkay.\n\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n>  1 file changed, 56 insertions(+), 28 deletions(-)\n>\n> diff --git a/builtin/rerere.c b/builtin/rerere.c\n> index 3162b074ec6..97c791e420b 100644\n> --- a/builtin/rerere.c\n> +++ b/builtin/rerere.c\n> @@ -5,6 +5,7 @@\n>  #include \"rerere.h\"\n>  #include \"strbuf.h\"\n>  #include \"string-list.h\"\n> +#include \"strvec.h\"\n>  #include \"xdiff/xdiff.h\"\n>  #include \"xdiff-interface.h\"\n>  #include \"pathspec.h\"\n> @@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n>  \treturn 0;\n>  }\n>\n> +static int cmd_rerere_perform(int argc,\n> +\t\t\t      const char **argv,\n> +\t\t\t      const char *prefix,\n> +\t\t\t      struct repository *repo)\n> +{\n> +\tint autoupdate = -1;\n> +\tstruct option options[] = {\n> +\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n> +\t\t\tN_(\"register clean resolutions in index\"), 1),\n> +\t\tOPT_END(),\n> +\t};\n> +\tenum rerere_flags flags = 0;\n> +\n> +\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n> +\tif (argc)\n> +\t\tusage(_(\"too many arguments\"));\n> +\n> +\tif (autoupdate == 1)\n> +\t\tflags = RERERE_AUTOUPDATE;\n> +\tif (autoupdate == 0)\n> +\t\tflags = RERERE_NOAUTOUPDATE;\n> +\n> +\treturn rerere(repo, flags);\n> +}\n> +\n\nSo I guess this would be the default case if no subcommand is used,\nmeaning the subcommands should be optional.\n\n\n>  static int cmd_rerere_remaining(int argc,\n>  \t\t\t\tconst char **argv,\n>  \t\t\t\tconst char *prefix,\n> @@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n>  \t       const char *prefix,\n>  \t       struct repository *repo)\n>  {\n> -\tint autoupdate = -1, flags = 0;\n> -\n> +\tparse_opt_subcommand_fn *fn = NULL;\n>  \tstruct option options[] = {\n> -\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n> -\t\t\tN_(\"register clean resolutions in index\"), 1),\n> +\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n> +\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n> +\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n> +\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n> +\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n> +\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n>  \t\tOPT_END(),\n>  \t};\n>\n>  \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n> -\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n> -\n> +\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\nSo this matches what I thought.\n\n>  \trepo_config(repo, git_xmerge_config, NULL);\n>\n> -\tif (autoupdate == 1)\n> -\t\tflags = RERERE_AUTOUPDATE;\n> -\tif (autoupdate == 0)\n> -\t\tflags = RERERE_NOAUTOUPDATE;\n> +\tif (!fn) {\n\nOkay if there's no function we call the default case. I wonder if we\ncould've done the inverse to reduce code block. if (fn) reutrn fn(...).\nDoesn't matter much anyway.\n\n> +\t\tstruct strvec args = STRVEC_INIT;\n> +\t\tconst char **args_copy;\n> +\t\tint ret;\n>\n> -\tif (argc < 1)\n> -\t\treturn rerere(repo, flags);\n> -\n> -\tif (!strcmp(argv[0], \"forget\"))\n> -\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n> -\telse if (!strcmp(argv[0], \"clear\"))\n> -\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n> -\telse if (!strcmp(argv[0], \"gc\"))\n> -\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n> -\telse if (!strcmp(argv[0], \"status\"))\n> -\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n> -\telse if (!strcmp(argv[0], \"remaining\"))\n> -\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n> -\telse if (!strcmp(argv[0], \"diff\"))\n> -\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n> -\telse\n> -\t\tusage_with_options(rerere_usage, options);\n> +\t\tstrvec_push(&args, \"perform\");\n\nWorthwhile adding a comment that this is a dummy placeholder subcommand?\n\n> +\t\tstrvec_pushv(&args, argv);\n>\n> -\treturn 0;\n> +\t\t/*\n> +\t\t * We need to copy the array as it will be modified by\n> +\t\t * `parse_options()`, and if so we leak the strings\n> +\t\t * referenced by `args`.\n> +\t\t */\n> +\t\tCALLOC_ARRAY(args_copy, args.nr);\n> +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n> +\n\nSince we need to add the dummy 'perform' and don't want to clear the\nactual argv, we copy it over. makes sense.\n\n> +\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n> +\n> +\t\tstrvec_clear(&args);\n> +\t\tfree(args_copy);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn fn(argc, argv, prefix, repo);\n>  }\n>\n> --\n> 2.56.0.341.g393f52fd96.dirty\n"},{"id":"557667","messageId":"CAOLa=ZSiuNPmegF726Sw_7ieCnx-vPVNLp89War_Wvc9Tq4S4w@mail.gmail.com","threadId":"66677","inReplyTo":"20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im","subject":"Re: [PATCH v2 00/12] builtin/rerere: convert to use subcommands","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-06T11:45:21Z","receivedAt":"2026-11-06T11:45:21Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Hi,\n>\n> while reviewing some patch series around git-rerere(1) recently I was a\n> bit appalled by our custom subcommand parsing that we do here. This\n> patch series here thus cleans up and modernizes that part a bit so that\n> git-rerere(1) behaves like every other Git command that happens to have\n> subcommands.\n>\n> This series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\n> ps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\n> rerere cache state, 2026-10-23) merged into it.\n>\n\nLooks to be in good shape!\n\nThanks\n"},{"id":"557678","messageId":"CAOLa=ZS+sJcPh1Q2Zz4Dz_hkbJCEd_sQzhSTbaZwEWL0nqDJnw@mail.gmail.com","threadId":"66677","inReplyTo":"au28e2L4LEMziCfI@pks.im","subject":"Re: [PATCH v2 02/12] rerere: convert flags into an enum","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-06T13:50:01Z","receivedAt":"2026-11-06T13:50:01Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Fri, Nov 06, 2026 at 05:51:13AM -0500, Karthik Nayak wrote:\n>> Patrick Steinhardt <ps@pks.im> writes:\n>>\n>> > diff --git a/rerere.h b/rerere.h\n>> > index dd9da03d6db..f13790c5dcd 100644\n>> > --- a/rerere.h\n>> > +++ b/rerere.h\n>> > @@ -39,10 +33,27 @@ struct rerere_id {\n>> >  \tint variant;\n>> >  };\n>> >\n>> > +enum rerere_flags {\n>> > +\t/*\n>> > +\t * Auto-update the index with previously recorded resolutions. This can\n>> > +\t * be used to explicitly override \"rerere.autoUpdate\".\n>> > +\t */\n>> > +\tRERERE_AUTOUPDATE = (1 << 0),\n>> > +\n>> > +\t/* Reverse of RERERE_AUTOUPDATE. */\n>> > +\tRERERE_NOAUTOUPDATE = (1 << 1),\n>> > +\n>>\n>> Nit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict\n>> resolution information to the stderr instead of updating the index.\n>> Perhaps that's something to document?\n>\n> Well, the fact that it prints to stderr is not specific to NOAUTOUPDATE.\n> We print messages in both cases, just at different times:\n>\n>   - When `RERERE_AUTOUPDATE` is set we print the messages in\n>     `update_paths()`.\n>\n>   - When `RERERE_NOAUTOUPDATE` is set (or `RERERE_AUTOUPDATE` is simply\n>     unset) then we print the message in `do_rerere_one_path()`.\n>\n\nI didn't dig enough to find the former.\n\n> The messages are different of course, but I don't really think that this\n> matters for the flag here. What we might want to say though is that we\n> don't update the index, but the working tree does get updated.\n>\n> Will adapt, thanks.\n>\n> Patrick\n\nSounds good.\n"},{"id":"557686","messageId":"au3jWCIwBKLV8DXT@pks.im","threadId":"66677","inReplyTo":"CAOLa=ZQrOyA2k+5EDmh+VJD=gC=68m3D17uKvNUTmaxH2FuNZg@mail.gmail.com","subject":"Re: [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T14:25:28Z","receivedAt":"2026-11-06T14:25:28Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 03:44:38AM -0800, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> > diff --git a/builtin/rerere.c b/builtin/rerere.c\n> > index 3162b074ec6..97c791e420b 100644\n> > --- a/builtin/rerere.c\n> > +++ b/builtin/rerere.c\n> > @@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n> >  \t       const char *prefix,\n> >  \t       struct repository *repo)\n> >  {\n> > -\tint autoupdate = -1, flags = 0;\n> > -\n> > +\tparse_opt_subcommand_fn *fn = NULL;\n> >  \tstruct option options[] = {\n> > -\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n> > -\t\t\tN_(\"register clean resolutions in index\"), 1),\n> > +\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n> > +\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n> > +\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n> > +\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n> > +\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n> > +\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n> >  \t\tOPT_END(),\n> >  \t};\n> >\n> >  \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n> > -\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n> > -\n> > +\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n> \n> So this matches what I thought.\n> \n> >  \trepo_config(repo, git_xmerge_config, NULL);\n> >\n> > -\tif (autoupdate == 1)\n> > -\t\tflags = RERERE_AUTOUPDATE;\n> > -\tif (autoupdate == 0)\n> > -\t\tflags = RERERE_NOAUTOUPDATE;\n> > +\tif (!fn) {\n> \n> Okay if there's no function we call the default case. I wonder if we\n> could've done the inverse to reduce code block. if (fn) reutrn fn(...).\n> Doesn't matter much anyway.\n\nI think that the result is actually harder to read in that case, even\nthough that might just be my personal opinion. But having a return in\nthe middle of the function is awkward, and I like that the variables\nthat are specific to the default subcommand are nicely scoped to the\nblock so that they obviously cannot be used by any other subcommand.\n\nSo I prefer to keep this as-is.\n\n> > +\t\tstruct strvec args = STRVEC_INIT;\n> > +\t\tconst char **args_copy;\n> > +\t\tint ret;\n> >\n> > -\tif (argc < 1)\n> > -\t\treturn rerere(repo, flags);\n> > -\n> > -\tif (!strcmp(argv[0], \"forget\"))\n> > -\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n> > -\telse if (!strcmp(argv[0], \"clear\"))\n> > -\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n> > -\telse if (!strcmp(argv[0], \"gc\"))\n> > -\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n> > -\telse if (!strcmp(argv[0], \"status\"))\n> > -\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n> > -\telse if (!strcmp(argv[0], \"remaining\"))\n> > -\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n> > -\telse if (!strcmp(argv[0], \"diff\"))\n> > -\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n> > -\telse\n> > -\t\tusage_with_options(rerere_usage, options);\n> > +\t\tstrvec_push(&args, \"perform\");\n> \n> Worthwhile adding a comment that this is a dummy placeholder subcommand?\n\nHmm. I could add something like this:\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 97c791e420b..f88bc43e363 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -257,6 +257,7 @@ int cmd_rerere(int argc,\n \t\tconst char **args_copy;\n \t\tint ret;\n \n+\t\t/* This is a dummy subcommand name. */\n \t\tstrvec_push(&args, \"perform\");\n \t\tstrvec_pushv(&args, argv);\n\nBut does that really add much value? I myself don't think so, but if you\nfeel that it does I'm happy to add it in.\n\nThanks!\n\nPatrick\n\n"},{"id":"557694","messageId":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH v3 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:54Z","receivedAt":"2026-11-06T15:13:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nwhile reviewing some patch series around git-rerere(1) recently I was a\nbit appalled by our custom subcommand parsing that we do here. This\npatch series here thus cleans up and modernizes that part a bit so that\ngit-rerere(1) behaves like every other Git command that happens to have\nsubcommands.\n\nThis series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\nps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\nrerere cache state, 2026-10-23) merged into it.\n\nChanges in v3:\n  - Clarify what `RERERE_NOAUTOUPDATE` does.\n  - Link to v2: https://patch.msgid.link/20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im\n\nChanges in v2:\n  - Document rerere flags.\n  - Rename `rerere_record()` to just `rerere()`.\n  - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (12):\n      rerere: rename `repo_rerere()`\n      rerere: convert flags into an enum\n      builtin/rerere: drop `the_repository`\n      builtin/rerere: stop passing flags to subcommands that ignore them\n      builtin/rerere: turn \"forget\" into a proper subcommand\n      builtin/rerere: turn \"clear\" into a proper subcommand\n      builtin/rerere: turn \"status\" into a proper subcommand\n      builtin/rerere: turn \"remaining\" into a proper subcommand\n      builtin/rerere: turn \"diff\" into a proper subcommand\n      builtin/rerere: turn \"gc\" into a proper subcommand\n      builtin/rerere: use `OPT_SUBCOMMAND()`\n      builtin/rerere: introduce proper usage strings for subcommands\n\n Documentation/git-rerere.adoc |   8 +-\n apply.c                       |   2 +-\n builtin/am.c                  |   4 +-\n builtin/commit.c              |   2 +-\n builtin/merge.c               |   2 +-\n builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------\n builtin/stash.c               |   2 +-\n rerere.c                      |  12 +-\n rerere.h                      |  40 ++++--\n sequencer.c                   |   4 +-\n t/t4200-rerere.sh             |   5 -\n 11 files changed, 294 insertions(+), 106 deletions(-)\n\nRange-diff versus v2:\n\n 1:  8d6b21c1ea2 =  1:  022fe75450a rerere: rename `repo_rerere()`\n 2:  3dd2a9cc7e0 !  2:  1cb50bf5937 rerere: convert flags into an enum\n    @@ rerere.h: struct rerere_id {\n     +\t */\n     +\tRERERE_AUTOUPDATE = (1 << 0),\n     +\n    -+\t/* Reverse of RERERE_AUTOUPDATE. */\n    ++\t/*\n    ++\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n    ++\t * working tree but don't touch the index.\n    ++\t */\n     +\tRERERE_NOAUTOUPDATE = (1 << 1),\n     +\n     +\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n 3:  a69e7f43d2b =  3:  d18adf008c9 builtin/rerere: drop `the_repository`\n 4:  86654ba3606 =  4:  bc2eea0ba84 builtin/rerere: stop passing flags to subcommands that ignore them\n 5:  f532910d986 =  5:  2b45e209b08 builtin/rerere: turn \"forget\" into a proper subcommand\n 6:  6340e1db614 =  6:  8e1a5cf4239 builtin/rerere: turn \"clear\" into a proper subcommand\n 7:  1c623efc48e =  7:  aede0d76e54 builtin/rerere: turn \"status\" into a proper subcommand\n 8:  debe0999ecb =  8:  114e40d5a51 builtin/rerere: turn \"remaining\" into a proper subcommand\n 9:  00bcc60a186 =  9:  7c523f60339 builtin/rerere: turn \"diff\" into a proper subcommand\n10:  9cc14c726eb = 10:  6962d3ae764 builtin/rerere: turn \"gc\" into a proper subcommand\n11:  8c90e572751 = 11:  d9021a91b8e builtin/rerere: use `OPT_SUBCOMMAND()`\n12:  11baa9ee058 = 12:  3b59da3d583 builtin/rerere: introduce proper usage strings for subcommands\n\n---\nbase-commit: 710910c03a22ac663885049213b9fef5853ea8e0\nchange-id: 20261027-pks-rerere-subcommands-318d41553438\n\n\n"},{"id":"557695","messageId":"20261106-pks-rerere-subcommands-v3-1-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 01/12] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:55Z","receivedAt":"2026-11-06T15:13:55Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `repo_rerere()` function is the only function in \"rerere.h\" that\ndoes not have a `rerere_` prefix. And while it does indeed receive a\nrepository as first parameter, that's not a good-enough reason to give\nit a `repo_` prefix.\n\nRename the function to just `rerere()`. Move around and extend\ndocumentation of this function to better explain what it does.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n apply.c          | 2 +-\n builtin/am.c     | 4 ++--\n builtin/commit.c | 2 +-\n builtin/merge.c  | 2 +-\n builtin/rerere.c | 2 +-\n builtin/stash.c  | 2 +-\n rerere.c         | 7 +------\n rerere.h         | 9 ++++++++-\n sequencer.c      | 4 ++--\n 9 files changed, 18 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex a0b7119c639..646fabeafa3 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t * tree with conflict markers, but that isn't written with --cached.\n \t\t */\n \t\tif (!state->cached)\n-\t\t\trepo_rerere(state->repo, 0);\n+\t\t\trerere(state->repo, 0);\n \t}\n \n \treturn errs;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e9623b83077..4a5b37bee00 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\to.verbosity = 0;\n \n \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n-\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n+\t\trerere(the_repository, state->allow_rerere_autoupdate);\n \t\tfree(their_tree_name);\n \t\treturn error(_(\"Failed to merge in the changes.\"));\n \t}\n@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t\tgoto next;\n \t}\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \n \tdo_commit(state);\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8ffd42681bb..3a4b94ad623 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,\n \n \tgit_test_write_commit_graph_or_die(the_repository);\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \trun_auto_maintenance(the_repository, quiet);\n \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n \t\t\tNULL, \"post-commit\", NULL);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d7bf209114f..089e36e8575 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\n-\trepo_rerere(the_repository, allow_rerere_auto);\n+\trerere(the_repository, allow_rerere_auto);\n \tprintf(_(\"Automatic merge failed; \"\n \t\t\t\"fix conflicts and then commit the result.\\n\"));\n \treturn 1;\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2c17f02f56d..a499e7b9151 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -83,7 +83,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn repo_rerere(the_repository, flags);\n+\t\treturn rerere(the_repository, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex e1a3a76bd04..91870a255fd 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,\n \t\tret = error(_(\"could not write index\"));\n \n \tif (ret) {\n-\t\trepo_rerere(the_repository, 0);\n+\t\trerere(the_repository, 0);\n \n \t\tif (index)\n \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\ndiff --git a/rerere.c b/rerere.c\nindex e0897612085..47a4a325bf5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-/*\n- * The main entry point that is called internally from codepaths that\n- * perform mergy operations, possibly leaving conflicted index entries\n- * and working tree files.\n- */\n-int repo_rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, int flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\ndiff --git a/rerere.h b/rerere.h\nindex d3cbd10e13f..dd9da03d6db 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       int flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int repo_rerere(struct repository *, int);\n+/*\n+ * The main entry point that is called internally from codepaths that\n+ * perform mergy operations, possibly leaving conflicted index entries\n+ * and working tree files. It records (and optionally updates) resolved\n+ * conflicts and reuses recorded resolutions for unresolved conflicts.\n+ */\n+int rerere(struct repository *r, int flags);\n+\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\ndiff --git a/sequencer.c b/sequencer.c\nindex 508ec717920..ace1cfac1cb 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(r, commit), msg.subject);\n \t\tprint_advice(r, res == 1, opts);\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557696","messageId":"20261106-pks-rerere-subcommands-v3-2-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:56Z","receivedAt":"2026-11-06T15:13:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Our modern coding guidelines say that flags should typically be passed\naround as enums so that it becomes trivial to see what kind of flags are\nexpected. Adapt the rerere flags accordingly and document them.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n rerere.c |  7 ++++---\n rerere.h | 33 ++++++++++++++++++++++++---------\n 2 files changed, 28 insertions(+), 12 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 47a4a325bf5..3652b7ac2d5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags)\n+\t\t       enum rerere_flags flags)\n {\n \tint lock_timeout_ms = 1000;\n \tint fd;\n@@ -951,7 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-int rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, enum rerere_flags flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n@@ -1336,7 +1336,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)\n \treturn needed;\n }\n \n-void rerere_gc(struct repository *r, struct string_list *rr, int flags)\n+void rerere_gc(struct repository *r, struct string_list *rr,\n+\t       enum rerere_flags flags)\n {\n \tstruct rerere_cache cache;\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\ndiff --git a/rerere.h b/rerere.h\nindex dd9da03d6db..21ff867d824 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -9,12 +9,6 @@\n struct pathspec;\n struct repository;\n \n-#define RERERE_AUTOUPDATE   01\n-#define RERERE_NOAUTOUPDATE 02\n-#define RERERE_READONLY     04\n-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n-#define RERERE_NOWAIT       010\n-\n /*\n  * Marks paths that have been hand-resolved and added to the\n  * index. Set in the util field of such paths after calling\n@@ -39,10 +33,30 @@ struct rerere_id {\n \tint variant;\n };\n \n+enum rerere_flags {\n+\t/*\n+\t * Auto-update the index with previously recorded resolutions. This can\n+\t * be used to explicitly override \"rerere.autoUpdate\".\n+\t */\n+\tRERERE_AUTOUPDATE = (1 << 0),\n+\n+\t/*\n+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n+\t * working tree but don't touch the index.\n+\t */\n+\tRERERE_NOAUTOUPDATE = (1 << 1),\n+\n+\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n+\tRERERE_READONLY = (1 << 2),\n+\n+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n+\tRERERE_NOWAIT = (1 << 3),\n+};\n+\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags);\n+\t\t       enum rerere_flags flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n /*\n@@ -51,7 +65,7 @@ void rerere_cache_release(struct rerere_cache *cache);\n  * and working tree files. It records (and optionally updates) resolved\n  * conflicts and reuses recorded resolutions for unresolved conflicts.\n  */\n-int rerere(struct repository *r, int flags);\n+int rerere(struct repository *r, enum rerere_flags flags);\n \n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n@@ -65,7 +79,8 @@ const char *rerere_path(struct repository *,\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n void rerere_clear(struct repository *, struct string_list *);\n-void rerere_gc(struct repository *, struct string_list *, int);\n+void rerere_gc(struct repository *, struct string_list *,\n+\t       enum rerere_flags flags);\n \n /*\n  * Check whether garbage collection for rerere entries is needed, which is\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557697","messageId":"20261106-pks-rerere-subcommands-v3-3-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 03/12] builtin/rerere: drop `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:57Z","receivedAt":"2026-11-06T15:13:57Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in git-rerere(1).\nAs that command cannot run outside of a repository these references can\nbe trivially replaced by the repository that's passed in as parameter to\n`cmd_rerere()`. We don't have to worry about the repository being `NULL`\nwhen called with \"-h\", either, as there are no references to the repo\nbefore we call `parse_options()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 24 +++++++++++-------------\n 1 file changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex a499e7b9151..83fb3783c61 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint autoupdate = -1, skip_locked = 0, flags = 0;\n@@ -75,7 +73,7 @@ int cmd_rerere(int argc,\n \tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n \t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n \n-\trepo_config(the_repository, git_xmerge_config, NULL);\n+\trepo_config(repo, git_xmerge_config, NULL);\n \n \tif (autoupdate == 1)\n \t\tflags = RERERE_AUTOUPDATE;\n@@ -83,7 +81,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn rerere(the_repository, flags);\n+\t\treturn rerere(repo, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\n@@ -94,21 +92,21 @@ int cmd_rerere(int argc,\n \t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n \t\t\t       prefix, argv + 1);\n \n-\t\tret = rerere_forget(the_repository, &pathspec);\n+\t\tret = rerere_forget(repo, &pathspec);\n \n \t\tclear_pathspec(&pathspec);\n \t\treturn ret;\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(the_repository, &merge_rr);\n+\t\trerere_clear(repo, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(the_repository, &merge_rr,\n+\t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\")) {\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t       flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n@@ -116,7 +114,7 @@ int cmd_rerere(int argc,\n \n \t\trerere_cache_release(&cache);\n \t} else if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(the_repository, &merge_rr);\n+\t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n \t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -129,16 +127,16 @@ int cmd_rerere(int argc,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t      flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n \t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(the_repository, &buf, id, \"preimage\"),\n+\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n \t\t\t\t     path, path, path))\n \t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(the_repository, &buf, id, NULL));\n+\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n \t\t}\n \n \t\trerere_cache_release(&cache);\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557698","messageId":"20261106-pks-rerere-subcommands-v3-4-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 04/12] builtin/rerere: stop passing flags to subcommands that ignore them","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:58Z","receivedAt":"2026-11-06T15:13:58Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has a \"--[no-]rerere-autoupdate\" flag. If\npassed, we explicitly enable or disable recording clean merge\nresolutions that are staged in the index. This flag only matters to\ngit-rerere(1) when not executed with any subcommand, but we also forward\nthe flag to `git rerere status` and `git rerere diff`.\n\nThis is mostly harmless as we would ignore those flags anyway, but it\nmakes subsequent refactorings harder to understand. Prepare for these\nrefactorings by not using the flag in those subcommands anymore.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 83fb3783c61..405276cc94b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -107,7 +107,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -128,7 +128,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t      flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557699","messageId":"20261106-pks-rerere-subcommands-v3-5-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 05/12] builtin/rerere: turn \"forget\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:13:59Z","receivedAt":"2026-11-06T15:13:59Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has its own, home-grown implementation of\nsubcommands. Of course this implementation is inconsistent with how\nsubcommands typically work:\n\n  - Options from other subcommands apply to each other.\n\n  - We don't have proper usage strings.\n\n  - Running `git rerere <subcmd> -h` doesn't print the options that are\n    supported by that subcommand, but instead it just prints the help of\n    git-rerere(1) itself.\n\nA subsequent commit will thus introduce proper subcommands as supported\nby our parse-options subsystem. Refactor the \"forget\" subcommand to use\nparse-options as a preparatory step. The other commands will follow in\nsubsequent commits until all of them have been converted, and then we\nswitch over to `OPT_SUBCOMMAND()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 38 ++++++++++++++++++++++++--------------\n 1 file changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 405276cc94b..5d2ae154ff8 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_forget(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct pathspec pathspec;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (!argc)\n+\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n+\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n+\n+\tret = rerere_forget(repo, &pathspec);\n+\n+\tclear_pathspec(&pathspec);\n+\treturn ret;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -83,20 +105,8 @@ int cmd_rerere(int argc,\n \tif (argc < 1)\n \t\treturn rerere(repo, flags);\n \n-\tif (!strcmp(argv[0], \"forget\")) {\n-\t\tstruct pathspec pathspec;\n-\t\tint ret;\n-\n-\t\tif (argc < 2)\n-\t\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n-\t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n-\t\t\t       prefix, argv + 1);\n-\n-\t\tret = rerere_forget(repo, &pathspec);\n-\n-\t\tclear_pathspec(&pathspec);\n-\t\treturn ret;\n-\t}\n+\tif (!strcmp(argv[0], \"forget\"))\n+\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n \n \tif (!strcmp(argv[0], \"clear\")) {\n \t\trerere_clear(repo, &merge_rr);\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557700","messageId":"20261106-pks-rerere-subcommands-v3-6-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 06/12] builtin/rerere: turn \"clear\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:00Z","receivedAt":"2026-11-06T15:14:00Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"clear\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 25 ++++++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 5d2ae154ff8..62f69b488b0 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_clear(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_clear(repo, &merge_rr);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -107,9 +127,8 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\n-\tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(repo, &merge_rr);\n+\telse if (!strcmp(argv[0], \"clear\")) {\n+\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557701","messageId":"20261106-pks-rerere-subcommands-v3-7-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 07/12] builtin/rerere: turn \"status\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:01Z","receivedAt":"2026-11-06T15:14:01Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"status\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------\n 1 file changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 62f69b488b0..2bcd270a1f1 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_status(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\tfor (size_t i = 0; i < merge_rr.nr; i++)\n+\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\treturn 0;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -132,17 +158,9 @@ int cmd_rerere(int argc,\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n-\telse if (!strcmp(argv[0], \"status\")) {\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n-\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\n-\t\trerere_cache_release(&cache);\n-\t} else if (!strcmp(argv[0], \"remaining\")) {\n+\telse if (!strcmp(argv[0], \"status\"))\n+\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"remaining\")) {\n \t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557702","messageId":"20261106-pks-rerere-subcommands-v3-8-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 08/12] builtin/rerere: turn \"remaining\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:02Z","receivedAt":"2026-11-06T15:14:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"remaining\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------\n 1 file changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2bcd270a1f1..3f82bcbeb10 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_remaining(int argc,\n+\t\t\t\tconst char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_remaining(repo, &merge_rr);\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n+\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\t\telse\n+\t\t\t/* prepare for later call to\n+\t\t\t * string_list_clear() */\n+\t\t\tmerge_rr.items[i].util = NULL;\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_status(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -160,17 +188,9 @@ int cmd_rerere(int argc,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(repo, &merge_rr);\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n-\t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\t\t\telse\n-\t\t\t\t/* prepare for later call to\n-\t\t\t\t * string_list_clear() */\n-\t\t\t\tmerge_rr.items[i].util = NULL;\n-\t\t}\n-\t} else if (!strcmp(argv[0], \"diff\")) {\n+\telse if (!strcmp(argv[0], \"remaining\"))\n+\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"diff\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557703","messageId":"20261106-pks-rerere-subcommands-v3-9-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 09/12] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:03Z","receivedAt":"2026-11-06T15:14:03Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"diff\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3f82bcbeb10..40bae5cb9cc 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_diff(int argc,\n+\t\t\t   const char **argv,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tconst char *path = merge_rr.items[i].string;\n+\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n+\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"), path, path, path))\n+\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n+\t\t\t    rerere_path(repo, &buf, id, NULL));\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -190,25 +224,9 @@ int cmd_rerere(int argc,\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n \t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\")) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tconst char *path = merge_rr.items[i].string;\n-\t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n-\t\t\t\t     path, path, path))\n-\t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n-\t\t}\n-\n-\t\trerere_cache_release(&cache);\n-\t\tstrbuf_release(&buf);\n-\t} else\n+\telse if (!strcmp(argv[0], \"diff\"))\n+\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n+\telse\n \t\tusage_with_options(rerere_usage, options);\n \n \tstring_list_clear(&merge_rr, 1);\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557704","messageId":"20261106-pks-rerere-subcommands-v3-10-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:04Z","receivedAt":"2026-11-06T15:14:04Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"gc\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n t/t4200-rerere.sh |  5 -----\n 2 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 40bae5cb9cc..3162b074ec6 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_gc(int argc,\n+\t\t\t const char **argv,\n+\t\t\t const char *prefix,\n+\t\t\t struct repository *repo)\n+{\n+\tint skip_locked = 0;\n+\tstruct option options[] = {\n+\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n+\t\t\t\tN_(\"skip gc while another process holds the lock\")),\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_gc(repo, &merge_rr,\n+\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -187,21 +211,16 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\tint autoupdate = -1, skip_locked = 0, flags = 0;\n+\tint autoupdate = -1, flags = 0;\n \n \tstruct option options[] = {\n \t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n-\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n-\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n-\n-\tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n-\t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage,\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_config(repo, git_xmerge_config, NULL);\n \n@@ -215,11 +234,10 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\")) {\n+\telse if (!strcmp(argv[0], \"clear\"))\n \t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(repo, &merge_rr,\n-\t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\telse if (!strcmp(argv[0], \"gc\"))\n+\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n@@ -229,6 +247,5 @@ int cmd_rerere(int argc,\n \telse\n \t\tusage_with_options(rerere_usage, options);\n \n-\tstring_list_clear(&merge_rr, 1);\n \treturn 0;\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex ab412ecc6e8..0d4cbf5114a 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n \ttest_path_is_missing $rr2/preimage\n '\n \n-test_expect_success '--skip-locked is only accepted by gc' '\n-\ttest_must_fail git rerere --skip-locked clear 2>err &&\n-\ttest_grep \"option .--skip-locked. requires .gc.\" err\n-'\n-\n test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n \tgit reset --hard &&\n \trm -rf $rr &&\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557705","messageId":"20261106-pks-rerere-subcommands-v3-11-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:05Z","receivedAt":"2026-11-06T15:14:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In git-rerere(1) we have our own custom logic to parse subcommands. In\npreceding commits we have refactored all of those subcommands so that\nthey are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\nthese so that we get rid of our custom subcommand parsing.\n\nUnfortunately this means that we have a backwards-incompatible change\nbecause we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\nsubcommands. But this was arguably broken and misleading as we ignore\nthis flag for any other subcommand aynway. So we cheat a bit and simply\ncall it a bug that those flags were accepted in the first place.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 56 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3162b074ec6..97c791e420b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -5,6 +5,7 @@\n #include \"rerere.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_perform(int argc,\n+\t\t\t      const char **argv,\n+\t\t\t      const char *prefix,\n+\t\t\t      struct repository *repo)\n+{\n+\tint autoupdate = -1;\n+\tstruct option options[] = {\n+\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n+\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_END(),\n+\t};\n+\tenum rerere_flags flags = 0;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (autoupdate == 1)\n+\t\tflags = RERERE_AUTOUPDATE;\n+\tif (autoupdate == 0)\n+\t\tflags = RERERE_NOAUTOUPDATE;\n+\n+\treturn rerere(repo, flags);\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tint autoupdate = -1, flags = 0;\n-\n+\tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n-\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n-\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n+\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n+\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n+\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n+\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n+\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n-\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \trepo_config(repo, git_xmerge_config, NULL);\n \n-\tif (autoupdate == 1)\n-\t\tflags = RERERE_AUTOUPDATE;\n-\tif (autoupdate == 0)\n-\t\tflags = RERERE_NOAUTOUPDATE;\n+\tif (!fn) {\n+\t\tstruct strvec args = STRVEC_INIT;\n+\t\tconst char **args_copy;\n+\t\tint ret;\n \n-\tif (argc < 1)\n-\t\treturn rerere(repo, flags);\n-\n-\tif (!strcmp(argv[0], \"forget\"))\n-\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\"))\n-\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"gc\"))\n-\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"status\"))\n-\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\"))\n-\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\"))\n-\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n-\telse\n-\t\tusage_with_options(rerere_usage, options);\n+\t\tstrvec_push(&args, \"perform\");\n+\t\tstrvec_pushv(&args, argv);\n \n-\treturn 0;\n+\t\t/*\n+\t\t * We need to copy the array as it will be modified by\n+\t\t * `parse_options()`, and if so we leak the strings\n+\t\t * referenced by `args`.\n+\t\t */\n+\t\tCALLOC_ARRAY(args_copy, args.nr);\n+\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n+\n+\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n+\n+\t\tstrvec_clear(&args);\n+\t\tfree(args_copy);\n+\t\treturn ret;\n+\t}\n+\n+\treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557706","messageId":"20261106-pks-rerere-subcommands-v3-12-4ff164d8fb81@pks.im","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im","subject":"[PATCH v3 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T15:14:06Z","receivedAt":"2026-11-06T15:14:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Adapt git-rerere(1) to have proper usage strings for each of the\nsubcommands.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc |  8 +++++-\n builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex 4e6ab9a27c9..e04e9ef3ef8 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n SYNOPSIS\n --------\n [verse]\n-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n+'git rerere' [--[no-]rerere-autoupdate]\n+'git rerere' clear\n+'git rerere' diff\n+'git rerere' forget <pathspec>...\n+'git rerere' gc\n+'git rerere' remaining\n+'git rerere' status\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 97c791e420b..051e50838ce 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -10,10 +10,13 @@\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n \n-static const char * const rerere_usage[] = {\n-\tN_(\"git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\"),\n-\tNULL,\n-};\n+#define RERERE_USAGE N_(\"git rerere [--[no-]rerere-autoupdate]\")\n+#define RERERE_CLEAR_USAGE N_(\"git rerere clear\")\n+#define RERERE_DIFF_USAGE N_(\"git rerere diff\")\n+#define RERERE_FORGET_USAGE N_(\"git rerere forget <pathspec>...\")\n+#define RERERE_GC_USAGE N_(\"git rerere gc\")\n+#define RERERE_REMAINING_USAGE N_(\"git rerere remaining\")\n+#define RERERE_STATUS_USAGE N_(\"git rerere status\")\n \n static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)\n {\n@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_clear_usage[] = {\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_diff_usage[] = {\n+\t\tRERERE_DIFF_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_forget_usage[] = {\n+\t\tRERERE_FORGET_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct pathspec pathspec;\n \tint ret;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);\n \tif (!argc)\n \t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n \tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,\n \t\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_gc_usage[] = {\n+\t\tRERERE_GC_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tNULL,\n+\t};\n \tenum rerere_flags flags = 0;\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_remaining_usage[] = {\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_status_usage[] = {\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -247,6 +278,16 @@ int cmd_rerere(int argc,\n \t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tRERERE_DIFF_USAGE,\n+\t\tRERERE_FORGET_USAGE,\n+\t\tRERERE_GC_USAGE,\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\n-- \n2.56.0.500.g5d06dc02cd.dirty\n\n\n"},{"id":"557711","messageId":"xmqqqzgxlxrq.fsf@gitster.g","threadId":"66677","inReplyTo":"20261106-pks-rerere-subcommands-v3-2-4ff164d8fb81@pks.im","subject":"Re: [PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T16:39:37Z","receivedAt":"2026-11-06T16:39:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> +enum rerere_flags {\n> +\t/*\n> +\t * Auto-update the index with previously recorded resolutions. This can\n> +\t * be used to explicitly override \"rerere.autoUpdate\".\n> +\t */\n> +\tRERERE_AUTOUPDATE = (1 << 0),\n> +\n> +\t/*\n> +\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n> +\t * working tree but don't touch the index.\n> +\t */\n> +\tRERERE_NOAUTOUPDATE = (1 << 1),\n\nAs you have updated the comment in this iteration, I'll throw a bit\nof review in.  The new comment is not wrong per-se, but the one from\nthe previous iteration was sufficient to convey the same thing.  In\nother words, I see no improvement in v3 over what you had in v2 for\nthis bit.\n\nWhat BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is\nneeded in the first place.  In other words, \"How is it different\nfrom the lack of RERERE_AUTOUPDATE bit?\" is not answered here.  And\nI think that is a lot more important thing to clarify.\n\n> +\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n> +\tRERERE_READONLY = (1 << 2),\n> +\n> +\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n> +\tRERERE_NOWAIT = (1 << 3),\n> +};\n\n"},{"id":"557878","messageId":"avFxCywngxJgwylf@pks.im","threadId":"66677","inReplyTo":"xmqqqzgxlxrq.fsf@gitster.g","subject":"Re: [PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-09T07:06:51Z","receivedAt":"2026-11-09T07:06:51Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 08:39:37AM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > +enum rerere_flags {\n> > +\t/*\n> > +\t * Auto-update the index with previously recorded resolutions. This can\n> > +\t * be used to explicitly override \"rerere.autoUpdate\".\n> > +\t */\n> > +\tRERERE_AUTOUPDATE = (1 << 0),\n> > +\n> > +\t/*\n> > +\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n> > +\t * working tree but don't touch the index.\n> > +\t */\n> > +\tRERERE_NOAUTOUPDATE = (1 << 1),\n> \n> As you have updated the comment in this iteration, I'll throw a bit\n> of review in.  The new comment is not wrong per-se, but the one from\n> the previous iteration was sufficient to convey the same thing.  In\n> other words, I see no improvement in v3 over what you had in v2 for\n> this bit.\n\nI wouldn't necessarily say so, as an unknowing reader might not know\nthat we still update the working tree. I myself certainly didn't, and I\nhad to dig a bit to figure out what happens with this flag, mostly\nbecause I am not familiar with the rerere subsystem.\n\n> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is\n> needed in the first place.  In other words, \"How is it different\n> from the lack of RERERE_AUTOUPDATE bit?\" is not answered here.  And\n> I think that is a lot more important thing to clarify.\n\nHeh, in this case _I_ thought that it's implicitly clear from the\ncomment of `RERERE_AUTOUPDATE`: it overrides \"rerere.autoUpdate\". I\nfigured that updating these comments would cause some discussions, and\nthat's exactly why I didn't dare to update them at all in v1 :)\n\nHow about this instead:\n\n    Only update the file in the working tree, but don't touch the index.\n    This can be passed to explicitly override \"rerere.autoUpdate\".\n\nPatrick\n\n"},{"id":"557955","messageId":"xmqqld7210a2.fsf@gitster.g","threadId":"66677","inReplyTo":"avFxCywngxJgwylf@pks.im","subject":"Re: [PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T15:40:05Z","receivedAt":"2026-11-09T15:40:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is\n>> needed in the first place.  In other words, \"How is it different\n>> from the lack of RERERE_AUTOUPDATE bit?\" is not answered here.  And\n>> I think that is a lot more important thing to clarify.\n>\n> Heh, in this case _I_ thought that it's implicitly clear from the\n> comment of `RERERE_AUTOUPDATE`: it overrides \"rerere.autoUpdate\". I\n> figured that updating these comments would cause some discussions, and\n> that's exactly why I didn't dare to update them at all in v1 :)\n\n;-)\n\n"},{"id":"557978","messageId":"xmqqik25zuku.fsf@gitster.g","threadId":"66677","inReplyTo":"xmqqld7210a2.fsf@gitster.g","subject":"Re: [PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T19:13:53Z","receivedAt":"2026-11-09T19:13:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n>>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is\n>>> needed in the first place.  In other words, \"How is it different\n>>> from the lack of RERERE_AUTOUPDATE bit?\" is not answered here.  And\n>>> I think that is a lot more important thing to clarify.\n>>\n>> Heh, in this case _I_ thought that it's implicitly clear from the\n>> comment of `RERERE_AUTOUPDATE`: it overrides \"rerere.autoUpdate\". I\n>> figured that updating these comments would cause some discussions, and\n>> that's exactly why I didn't dare to update them at all in v1 :)\n>\n> ;-)\n\nThe command line can give us not two (which could be represented\nwith a single bit) but three choices, (0) the command line has no\npreference on --[no-]autoupdate and follow the configured default,\n(1) --autoupdate, or (2) --no-autoupdate, and that is exactly why we\nhave these two independent-looking bits.\n\nBut two bits can express another combination (i.e., both bits on),\nwhich probably is invalid.  The underlying OPT_UYN() calls\nparse_opt_tertiary() which only chooses between 1 and 2 so we should\nbe safe on the setting side, but I offhand do not remember if we\ndetect when both bits are on and BUG() out where we consume the\nvalue.\n\nThanks.\n\n\n"},{"id":"558180","messageId":"avRLM38NKe81u9fg@pks.im","threadId":"66677","inReplyTo":"xmqqik25zuku.fsf@gitster.g","subject":"Re: [PATCH v3 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T11:02:11Z","receivedAt":"2026-11-11T11:02:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 11:13:53AM -0800, Junio C Hamano wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > Patrick Steinhardt <ps@pks.im> writes:\n> >\n> >>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is\n> >>> needed in the first place.  In other words, \"How is it different\n> >>> from the lack of RERERE_AUTOUPDATE bit?\" is not answered here.  And\n> >>> I think that is a lot more important thing to clarify.\n> >>\n> >> Heh, in this case _I_ thought that it's implicitly clear from the\n> >> comment of `RERERE_AUTOUPDATE`: it overrides \"rerere.autoUpdate\". I\n> >> figured that updating these comments would cause some discussions, and\n> >> that's exactly why I didn't dare to update them at all in v1 :)\n> >\n> > ;-)\n> \n> The command line can give us not two (which could be represented\n> with a single bit) but three choices, (0) the command line has no\n> preference on --[no-]autoupdate and follow the configured default,\n> (1) --autoupdate, or (2) --no-autoupdate, and that is exactly why we\n> have these two independent-looking bits.\n> \n> But two bits can express another combination (i.e., both bits on),\n> which probably is invalid.  The underlying OPT_UYN() calls\n> parse_opt_tertiary() which only chooses between 1 and 2 so we should\n> be safe on the setting side, but I offhand do not remember if we\n> detect when both bits are on and BUG() out where we consume the\n> value.\n\nWe have this bit in `rerere_cache_setup()`:\n\n\tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n\t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n\nSo `RERERE_AUTOUPDATE` takes precedence over `RERERE_NOAUTOUPDATE`, but\nall callers know to only pass one of these flags. I agree though that we\nshould detect this misuse and complain about it, it's certainly not\nobvious at all.\n\nPatrick\n\n"},{"id":"558184","messageId":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:36Z","receivedAt":"2026-11-11T12:18:36Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nwhile reviewing some patch series around git-rerere(1) recently I was a\nbit appalled by our custom subcommand parsing that we do here. This\npatch series here thus cleans up and modernizes that part a bit so that\ngit-rerere(1) behaves like every other Git command that happens to have\nsubcommands.\n\nThis series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\nps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\nrerere cache state, 2026-10-23) merged into it.\n\nChanges in v4:\n  - Some more polishing for `RERERE_{NO,}AUTOUPDATE` documentation.\n  - Die in case both of these flags are passed.\n  - Link to v3: https://patch.msgid.link/20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im\n\nChanges in v3:\n  - Clarify what `RERERE_NOAUTOUPDATE` does.\n  - Link to v2: https://patch.msgid.link/20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im\n\nChanges in v2:\n  - Document rerere flags.\n  - Rename `rerere_record()` to just `rerere()`.\n  - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (12):\n      rerere: rename `repo_rerere()`\n      rerere: convert flags into an enum\n      builtin/rerere: drop `the_repository`\n      builtin/rerere: stop passing flags to subcommands that ignore them\n      builtin/rerere: turn \"forget\" into a proper subcommand\n      builtin/rerere: turn \"clear\" into a proper subcommand\n      builtin/rerere: turn \"status\" into a proper subcommand\n      builtin/rerere: turn \"remaining\" into a proper subcommand\n      builtin/rerere: turn \"diff\" into a proper subcommand\n      builtin/rerere: turn \"gc\" into a proper subcommand\n      builtin/rerere: use `OPT_SUBCOMMAND()`\n      builtin/rerere: introduce proper usage strings for subcommands\n\n Documentation/git-rerere.adoc |   8 +-\n apply.c                       |   2 +-\n builtin/am.c                  |   4 +-\n builtin/commit.c              |   2 +-\n builtin/merge.c               |   2 +-\n builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------\n builtin/stash.c               |   2 +-\n rerere.c                      |  14 +-\n rerere.h                      |  43 ++++--\n sequencer.c                   |   4 +-\n t/t4200-rerere.sh             |   5 -\n 11 files changed, 299 insertions(+), 106 deletions(-)\n\nRange-diff versus v3:\n\n 1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`\n 2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum\n    @@ Commit message\n         around as enums so that it becomes trivial to see what kind of flags are\n         expected. Adapt the rerere flags accordingly and document them.\n     \n    +    While at it, detect the case where both `RERERE_AUTOUPDATE` and\n    +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot\n    +    of sense, and it's not obvious which of those flags takes precedence\n    +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of\n    +    those flags, but let's be safe rather than sorry and `BUG()` in case\n    +    both are passed.\n    +\n         Signed-off-by: Patrick Steinhardt <ps@pks.im>\n     \n      ## rerere.c ##\n    @@ rerere.c: static int is_rerere_enabled(struct repository *r)\n      {\n      \tint lock_timeout_ms = 1000;\n      \tint fd;\n    +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n    + \trepo_config_get_bool(r, \"rerere.autoupdate\", &cache->autoupdate);\n    + \trepo_config_get_int(r, \"rerere.locktimeout\", &lock_timeout_ms);\n    + \n    ++\tif ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))\n    ++\t\tBUG(\"RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE\");\n    + \tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n    + \t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n    + \tif ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))\n     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n      \treturn fd;\n      }\n    @@ rerere.h: struct rerere_id {\n     +\tRERERE_AUTOUPDATE = (1 << 0),\n     +\n     +\t/*\n    -+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n    -+\t * working tree but don't touch the index.\n    ++\t * update the file in the working tree but don't touch the index. This\n    ++\t * can be used to explicitly override \"rerere.autoUpdate\".\n    ++\t *\n    ++\t * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is\n    ++\t * invalid to pass both flags at the same time.\n     +\t */\n     +\tRERERE_NOAUTOUPDATE = (1 << 1),\n     +\n 3:  99faad47068 =  3:  48692c2c88d builtin/rerere: drop `the_repository`\n 4:  f164c482227 =  4:  e76991dd39d builtin/rerere: stop passing flags to subcommands that ignore them\n 5:  0573d2323e8 =  5:  2474dca4713 builtin/rerere: turn \"forget\" into a proper subcommand\n 6:  2098dedf4fd =  6:  cecdbb1c63b builtin/rerere: turn \"clear\" into a proper subcommand\n 7:  e8eaa2b4092 =  7:  54fc766f9d2 builtin/rerere: turn \"status\" into a proper subcommand\n 8:  a5781284b8b =  8:  fa2c839b2cb builtin/rerere: turn \"remaining\" into a proper subcommand\n 9:  9a4278df0ea =  9:  416b8311ca9 builtin/rerere: turn \"diff\" into a proper subcommand\n10:  e63b9be0d74 = 10:  adb2b68f833 builtin/rerere: turn \"gc\" into a proper subcommand\n11:  47889896ecb = 11:  a12e19cb2e8 builtin/rerere: use `OPT_SUBCOMMAND()`\n12:  5e16a247b49 = 12:  4b1b6170ba3 builtin/rerere: introduce proper usage strings for subcommands\n\n---\nbase-commit: 710910c03a22ac663885049213b9fef5853ea8e0\nchange-id: 20261027-pks-rerere-subcommands-318d41553438\n\n\n"},{"id":"558185","messageId":"20261111-pks-rerere-subcommands-v4-1-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 01/12] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:37Z","receivedAt":"2026-11-11T12:18:37Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `repo_rerere()` function is the only function in \"rerere.h\" that\ndoes not have a `rerere_` prefix. And while it does indeed receive a\nrepository as first parameter, that's not a good-enough reason to give\nit a `repo_` prefix.\n\nRename the function to just `rerere()`. Move around and extend\ndocumentation of this function to better explain what it does.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n apply.c          | 2 +-\n builtin/am.c     | 4 ++--\n builtin/commit.c | 2 +-\n builtin/merge.c  | 2 +-\n builtin/rerere.c | 2 +-\n builtin/stash.c  | 2 +-\n rerere.c         | 7 +------\n rerere.h         | 9 ++++++++-\n sequencer.c      | 4 ++--\n 9 files changed, 18 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex a0b7119c639..646fabeafa3 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t * tree with conflict markers, but that isn't written with --cached.\n \t\t */\n \t\tif (!state->cached)\n-\t\t\trepo_rerere(state->repo, 0);\n+\t\t\trerere(state->repo, 0);\n \t}\n \n \treturn errs;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e9623b83077..4a5b37bee00 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\to.verbosity = 0;\n \n \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n-\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n+\t\trerere(the_repository, state->allow_rerere_autoupdate);\n \t\tfree(their_tree_name);\n \t\treturn error(_(\"Failed to merge in the changes.\"));\n \t}\n@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t\tgoto next;\n \t}\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \n \tdo_commit(state);\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8ffd42681bb..3a4b94ad623 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,\n \n \tgit_test_write_commit_graph_or_die(the_repository);\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \trun_auto_maintenance(the_repository, quiet);\n \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n \t\t\tNULL, \"post-commit\", NULL);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d7bf209114f..089e36e8575 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\n-\trepo_rerere(the_repository, allow_rerere_auto);\n+\trerere(the_repository, allow_rerere_auto);\n \tprintf(_(\"Automatic merge failed; \"\n \t\t\t\"fix conflicts and then commit the result.\\n\"));\n \treturn 1;\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2c17f02f56d..a499e7b9151 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -83,7 +83,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn repo_rerere(the_repository, flags);\n+\t\treturn rerere(the_repository, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex e1a3a76bd04..91870a255fd 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,\n \t\tret = error(_(\"could not write index\"));\n \n \tif (ret) {\n-\t\trepo_rerere(the_repository, 0);\n+\t\trerere(the_repository, 0);\n \n \t\tif (index)\n \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\ndiff --git a/rerere.c b/rerere.c\nindex e0897612085..47a4a325bf5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-/*\n- * The main entry point that is called internally from codepaths that\n- * perform mergy operations, possibly leaving conflicted index entries\n- * and working tree files.\n- */\n-int repo_rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, int flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\ndiff --git a/rerere.h b/rerere.h\nindex d3cbd10e13f..dd9da03d6db 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       int flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int repo_rerere(struct repository *, int);\n+/*\n+ * The main entry point that is called internally from codepaths that\n+ * perform mergy operations, possibly leaving conflicted index entries\n+ * and working tree files. It records (and optionally updates) resolved\n+ * conflicts and reuses recorded resolutions for unresolved conflicts.\n+ */\n+int rerere(struct repository *r, int flags);\n+\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\ndiff --git a/sequencer.c b/sequencer.c\nindex 508ec717920..ace1cfac1cb 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(r, commit), msg.subject);\n \t\tprint_advice(r, res == 1, opts);\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558186","messageId":"20261111-pks-rerere-subcommands-v4-2-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 02/12] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:38Z","receivedAt":"2026-11-11T12:18:38Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Our modern coding guidelines say that flags should typically be passed\naround as enums so that it becomes trivial to see what kind of flags are\nexpected. Adapt the rerere flags accordingly and document them.\n\nWhile at it, detect the case where both `RERERE_AUTOUPDATE` and\n`RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot\nof sense, and it's not obvious which of those flags takes precedence\n(it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of\nthose flags, but let's be safe rather than sorry and `BUG()` in case\nboth are passed.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n rerere.c |  9 ++++++---\n rerere.h | 36 +++++++++++++++++++++++++++---------\n 2 files changed, 33 insertions(+), 12 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 47a4a325bf5..47d9077eeca 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags)\n+\t\t       enum rerere_flags flags)\n {\n \tint lock_timeout_ms = 1000;\n \tint fd;\n@@ -922,6 +922,8 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \trepo_config_get_bool(r, \"rerere.autoupdate\", &cache->autoupdate);\n \trepo_config_get_int(r, \"rerere.locktimeout\", &lock_timeout_ms);\n \n+\tif ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))\n+\t\tBUG(\"RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE\");\n \tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n \t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n \tif ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))\n@@ -951,7 +953,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-int rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, enum rerere_flags flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n@@ -1336,7 +1338,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)\n \treturn needed;\n }\n \n-void rerere_gc(struct repository *r, struct string_list *rr, int flags)\n+void rerere_gc(struct repository *r, struct string_list *rr,\n+\t       enum rerere_flags flags)\n {\n \tstruct rerere_cache cache;\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\ndiff --git a/rerere.h b/rerere.h\nindex dd9da03d6db..10b25018c0e 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -9,12 +9,6 @@\n struct pathspec;\n struct repository;\n \n-#define RERERE_AUTOUPDATE   01\n-#define RERERE_NOAUTOUPDATE 02\n-#define RERERE_READONLY     04\n-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n-#define RERERE_NOWAIT       010\n-\n /*\n  * Marks paths that have been hand-resolved and added to the\n  * index. Set in the util field of such paths after calling\n@@ -39,10 +33,33 @@ struct rerere_id {\n \tint variant;\n };\n \n+enum rerere_flags {\n+\t/*\n+\t * Auto-update the index with previously recorded resolutions. This can\n+\t * be used to explicitly override \"rerere.autoUpdate\".\n+\t */\n+\tRERERE_AUTOUPDATE = (1 << 0),\n+\n+\t/*\n+\t * update the file in the working tree but don't touch the index. This\n+\t * can be used to explicitly override \"rerere.autoUpdate\".\n+\t *\n+\t * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is\n+\t * invalid to pass both flags at the same time.\n+\t */\n+\tRERERE_NOAUTOUPDATE = (1 << 1),\n+\n+\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n+\tRERERE_READONLY = (1 << 2),\n+\n+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n+\tRERERE_NOWAIT = (1 << 3),\n+};\n+\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags);\n+\t\t       enum rerere_flags flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n /*\n@@ -51,7 +68,7 @@ void rerere_cache_release(struct rerere_cache *cache);\n  * and working tree files. It records (and optionally updates) resolved\n  * conflicts and reuses recorded resolutions for unresolved conflicts.\n  */\n-int rerere(struct repository *r, int flags);\n+int rerere(struct repository *r, enum rerere_flags flags);\n \n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n@@ -65,7 +82,8 @@ const char *rerere_path(struct repository *,\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n void rerere_clear(struct repository *, struct string_list *);\n-void rerere_gc(struct repository *, struct string_list *, int);\n+void rerere_gc(struct repository *, struct string_list *,\n+\t       enum rerere_flags flags);\n \n /*\n  * Check whether garbage collection for rerere entries is needed, which is\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558187","messageId":"20261111-pks-rerere-subcommands-v4-3-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 03/12] builtin/rerere: drop `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:39Z","receivedAt":"2026-11-11T12:18:39Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in git-rerere(1).\nAs that command cannot run outside of a repository these references can\nbe trivially replaced by the repository that's passed in as parameter to\n`cmd_rerere()`. We don't have to worry about the repository being `NULL`\nwhen called with \"-h\", either, as there are no references to the repo\nbefore we call `parse_options()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 24 +++++++++++-------------\n 1 file changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex a499e7b9151..83fb3783c61 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint autoupdate = -1, skip_locked = 0, flags = 0;\n@@ -75,7 +73,7 @@ int cmd_rerere(int argc,\n \tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n \t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n \n-\trepo_config(the_repository, git_xmerge_config, NULL);\n+\trepo_config(repo, git_xmerge_config, NULL);\n \n \tif (autoupdate == 1)\n \t\tflags = RERERE_AUTOUPDATE;\n@@ -83,7 +81,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn rerere(the_repository, flags);\n+\t\treturn rerere(repo, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\n@@ -94,21 +92,21 @@ int cmd_rerere(int argc,\n \t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n \t\t\t       prefix, argv + 1);\n \n-\t\tret = rerere_forget(the_repository, &pathspec);\n+\t\tret = rerere_forget(repo, &pathspec);\n \n \t\tclear_pathspec(&pathspec);\n \t\treturn ret;\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(the_repository, &merge_rr);\n+\t\trerere_clear(repo, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(the_repository, &merge_rr,\n+\t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\")) {\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t       flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n@@ -116,7 +114,7 @@ int cmd_rerere(int argc,\n \n \t\trerere_cache_release(&cache);\n \t} else if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(the_repository, &merge_rr);\n+\t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n \t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -129,16 +127,16 @@ int cmd_rerere(int argc,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t      flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n \t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(the_repository, &buf, id, \"preimage\"),\n+\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n \t\t\t\t     path, path, path))\n \t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(the_repository, &buf, id, NULL));\n+\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n \t\t}\n \n \t\trerere_cache_release(&cache);\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558188","messageId":"20261111-pks-rerere-subcommands-v4-4-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 04/12] builtin/rerere: stop passing flags to subcommands that ignore them","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:40Z","receivedAt":"2026-11-11T12:18:40Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has a \"--[no-]rerere-autoupdate\" flag. If\npassed, we explicitly enable or disable recording clean merge\nresolutions that are staged in the index. This flag only matters to\ngit-rerere(1) when not executed with any subcommand, but we also forward\nthe flag to `git rerere status` and `git rerere diff`.\n\nThis is mostly harmless as we would ignore those flags anyway, but it\nmakes subsequent refactorings harder to understand. Prepare for these\nrefactorings by not using the flag in those subcommands anymore.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 83fb3783c61..405276cc94b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -107,7 +107,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -128,7 +128,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t      flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558189","messageId":"20261111-pks-rerere-subcommands-v4-5-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 05/12] builtin/rerere: turn \"forget\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:41Z","receivedAt":"2026-11-11T12:18:41Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has its own, home-grown implementation of\nsubcommands. Of course this implementation is inconsistent with how\nsubcommands typically work:\n\n  - Options from other subcommands apply to each other.\n\n  - We don't have proper usage strings.\n\n  - Running `git rerere <subcmd> -h` doesn't print the options that are\n    supported by that subcommand, but instead it just prints the help of\n    git-rerere(1) itself.\n\nA subsequent commit will thus introduce proper subcommands as supported\nby our parse-options subsystem. Refactor the \"forget\" subcommand to use\nparse-options as a preparatory step. The other commands will follow in\nsubsequent commits until all of them have been converted, and then we\nswitch over to `OPT_SUBCOMMAND()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 38 ++++++++++++++++++++++++--------------\n 1 file changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 405276cc94b..5d2ae154ff8 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_forget(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct pathspec pathspec;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (!argc)\n+\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n+\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n+\n+\tret = rerere_forget(repo, &pathspec);\n+\n+\tclear_pathspec(&pathspec);\n+\treturn ret;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -83,20 +105,8 @@ int cmd_rerere(int argc,\n \tif (argc < 1)\n \t\treturn rerere(repo, flags);\n \n-\tif (!strcmp(argv[0], \"forget\")) {\n-\t\tstruct pathspec pathspec;\n-\t\tint ret;\n-\n-\t\tif (argc < 2)\n-\t\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n-\t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n-\t\t\t       prefix, argv + 1);\n-\n-\t\tret = rerere_forget(repo, &pathspec);\n-\n-\t\tclear_pathspec(&pathspec);\n-\t\treturn ret;\n-\t}\n+\tif (!strcmp(argv[0], \"forget\"))\n+\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n \n \tif (!strcmp(argv[0], \"clear\")) {\n \t\trerere_clear(repo, &merge_rr);\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558190","messageId":"20261111-pks-rerere-subcommands-v4-6-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 06/12] builtin/rerere: turn \"clear\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:42Z","receivedAt":"2026-11-11T12:18:42Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"clear\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 25 ++++++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 5d2ae154ff8..62f69b488b0 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_clear(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_clear(repo, &merge_rr);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -107,9 +127,8 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\n-\tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(repo, &merge_rr);\n+\telse if (!strcmp(argv[0], \"clear\")) {\n+\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558191","messageId":"20261111-pks-rerere-subcommands-v4-7-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 07/12] builtin/rerere: turn \"status\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:43Z","receivedAt":"2026-11-11T12:18:43Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"status\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------\n 1 file changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 62f69b488b0..2bcd270a1f1 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_status(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\tfor (size_t i = 0; i < merge_rr.nr; i++)\n+\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\treturn 0;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -132,17 +158,9 @@ int cmd_rerere(int argc,\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n-\telse if (!strcmp(argv[0], \"status\")) {\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n-\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\n-\t\trerere_cache_release(&cache);\n-\t} else if (!strcmp(argv[0], \"remaining\")) {\n+\telse if (!strcmp(argv[0], \"status\"))\n+\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"remaining\")) {\n \t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558192","messageId":"20261111-pks-rerere-subcommands-v4-8-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 08/12] builtin/rerere: turn \"remaining\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:44Z","receivedAt":"2026-11-11T12:18:44Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"remaining\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------\n 1 file changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2bcd270a1f1..3f82bcbeb10 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_remaining(int argc,\n+\t\t\t\tconst char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_remaining(repo, &merge_rr);\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n+\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\t\telse\n+\t\t\t/* prepare for later call to\n+\t\t\t * string_list_clear() */\n+\t\t\tmerge_rr.items[i].util = NULL;\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_status(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -160,17 +188,9 @@ int cmd_rerere(int argc,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(repo, &merge_rr);\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n-\t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\t\t\telse\n-\t\t\t\t/* prepare for later call to\n-\t\t\t\t * string_list_clear() */\n-\t\t\t\tmerge_rr.items[i].util = NULL;\n-\t\t}\n-\t} else if (!strcmp(argv[0], \"diff\")) {\n+\telse if (!strcmp(argv[0], \"remaining\"))\n+\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"diff\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558193","messageId":"20261111-pks-rerere-subcommands-v4-9-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 09/12] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:45Z","receivedAt":"2026-11-11T12:18:45Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"diff\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3f82bcbeb10..40bae5cb9cc 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_diff(int argc,\n+\t\t\t   const char **argv,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tconst char *path = merge_rr.items[i].string;\n+\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n+\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"), path, path, path))\n+\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n+\t\t\t    rerere_path(repo, &buf, id, NULL));\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -190,25 +224,9 @@ int cmd_rerere(int argc,\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n \t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\")) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tconst char *path = merge_rr.items[i].string;\n-\t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n-\t\t\t\t     path, path, path))\n-\t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n-\t\t}\n-\n-\t\trerere_cache_release(&cache);\n-\t\tstrbuf_release(&buf);\n-\t} else\n+\telse if (!strcmp(argv[0], \"diff\"))\n+\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n+\telse\n \t\tusage_with_options(rerere_usage, options);\n \n \tstring_list_clear(&merge_rr, 1);\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558194","messageId":"20261111-pks-rerere-subcommands-v4-10-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:46Z","receivedAt":"2026-11-11T12:18:46Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"gc\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n t/t4200-rerere.sh |  5 -----\n 2 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 40bae5cb9cc..3162b074ec6 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_gc(int argc,\n+\t\t\t const char **argv,\n+\t\t\t const char *prefix,\n+\t\t\t struct repository *repo)\n+{\n+\tint skip_locked = 0;\n+\tstruct option options[] = {\n+\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n+\t\t\t\tN_(\"skip gc while another process holds the lock\")),\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_gc(repo, &merge_rr,\n+\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -187,21 +211,16 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\tint autoupdate = -1, skip_locked = 0, flags = 0;\n+\tint autoupdate = -1, flags = 0;\n \n \tstruct option options[] = {\n \t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n-\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n-\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n-\n-\tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n-\t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage,\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_config(repo, git_xmerge_config, NULL);\n \n@@ -215,11 +234,10 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\")) {\n+\telse if (!strcmp(argv[0], \"clear\"))\n \t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(repo, &merge_rr,\n-\t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\telse if (!strcmp(argv[0], \"gc\"))\n+\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n@@ -229,6 +247,5 @@ int cmd_rerere(int argc,\n \telse\n \t\tusage_with_options(rerere_usage, options);\n \n-\tstring_list_clear(&merge_rr, 1);\n \treturn 0;\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex ab412ecc6e8..0d4cbf5114a 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n \ttest_path_is_missing $rr2/preimage\n '\n \n-test_expect_success '--skip-locked is only accepted by gc' '\n-\ttest_must_fail git rerere --skip-locked clear 2>err &&\n-\ttest_grep \"option .--skip-locked. requires .gc.\" err\n-'\n-\n test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n \tgit reset --hard &&\n \trm -rf $rr &&\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558195","messageId":"20261111-pks-rerere-subcommands-v4-11-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:47Z","receivedAt":"2026-11-11T12:18:47Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In git-rerere(1) we have our own custom logic to parse subcommands. In\npreceding commits we have refactored all of those subcommands so that\nthey are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\nthese so that we get rid of our custom subcommand parsing.\n\nUnfortunately this means that we have a backwards-incompatible change\nbecause we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\nsubcommands. But this was arguably broken and misleading as we ignore\nthis flag for any other subcommand aynway. So we cheat a bit and simply\ncall it a bug that those flags were accepted in the first place.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 56 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3162b074ec6..97c791e420b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -5,6 +5,7 @@\n #include \"rerere.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_perform(int argc,\n+\t\t\t      const char **argv,\n+\t\t\t      const char *prefix,\n+\t\t\t      struct repository *repo)\n+{\n+\tint autoupdate = -1;\n+\tstruct option options[] = {\n+\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n+\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_END(),\n+\t};\n+\tenum rerere_flags flags = 0;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (autoupdate == 1)\n+\t\tflags = RERERE_AUTOUPDATE;\n+\tif (autoupdate == 0)\n+\t\tflags = RERERE_NOAUTOUPDATE;\n+\n+\treturn rerere(repo, flags);\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tint autoupdate = -1, flags = 0;\n-\n+\tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n-\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n-\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n+\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n+\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n+\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n+\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n+\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n-\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \trepo_config(repo, git_xmerge_config, NULL);\n \n-\tif (autoupdate == 1)\n-\t\tflags = RERERE_AUTOUPDATE;\n-\tif (autoupdate == 0)\n-\t\tflags = RERERE_NOAUTOUPDATE;\n+\tif (!fn) {\n+\t\tstruct strvec args = STRVEC_INIT;\n+\t\tconst char **args_copy;\n+\t\tint ret;\n \n-\tif (argc < 1)\n-\t\treturn rerere(repo, flags);\n-\n-\tif (!strcmp(argv[0], \"forget\"))\n-\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\"))\n-\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"gc\"))\n-\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"status\"))\n-\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\"))\n-\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\"))\n-\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n-\telse\n-\t\tusage_with_options(rerere_usage, options);\n+\t\tstrvec_push(&args, \"perform\");\n+\t\tstrvec_pushv(&args, argv);\n \n-\treturn 0;\n+\t\t/*\n+\t\t * We need to copy the array as it will be modified by\n+\t\t * `parse_options()`, and if so we leak the strings\n+\t\t * referenced by `args`.\n+\t\t */\n+\t\tCALLOC_ARRAY(args_copy, args.nr);\n+\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n+\n+\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n+\n+\t\tstrvec_clear(&args);\n+\t\tfree(args_copy);\n+\t\treturn ret;\n+\t}\n+\n+\treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558196","messageId":"20261111-pks-rerere-subcommands-v4-12-df0c8bf79e16@pks.im","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"[PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T12:18:48Z","receivedAt":"2026-11-11T12:18:48Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Adapt git-rerere(1) to have proper usage strings for each of the\nsubcommands.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc |  8 +++++-\n builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex 4e6ab9a27c9..e04e9ef3ef8 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n SYNOPSIS\n --------\n [verse]\n-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n+'git rerere' [--[no-]rerere-autoupdate]\n+'git rerere' clear\n+'git rerere' diff\n+'git rerere' forget <pathspec>...\n+'git rerere' gc\n+'git rerere' remaining\n+'git rerere' status\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 97c791e420b..051e50838ce 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -10,10 +10,13 @@\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n \n-static const char * const rerere_usage[] = {\n-\tN_(\"git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\"),\n-\tNULL,\n-};\n+#define RERERE_USAGE N_(\"git rerere [--[no-]rerere-autoupdate]\")\n+#define RERERE_CLEAR_USAGE N_(\"git rerere clear\")\n+#define RERERE_DIFF_USAGE N_(\"git rerere diff\")\n+#define RERERE_FORGET_USAGE N_(\"git rerere forget <pathspec>...\")\n+#define RERERE_GC_USAGE N_(\"git rerere gc\")\n+#define RERERE_REMAINING_USAGE N_(\"git rerere remaining\")\n+#define RERERE_STATUS_USAGE N_(\"git rerere status\")\n \n static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)\n {\n@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_clear_usage[] = {\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_diff_usage[] = {\n+\t\tRERERE_DIFF_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_forget_usage[] = {\n+\t\tRERERE_FORGET_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct pathspec pathspec;\n \tint ret;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);\n \tif (!argc)\n \t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n \tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,\n \t\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_gc_usage[] = {\n+\t\tRERERE_GC_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tNULL,\n+\t};\n \tenum rerere_flags flags = 0;\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_remaining_usage[] = {\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_status_usage[] = {\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -247,6 +278,16 @@ int cmd_rerere(int argc,\n \t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tRERERE_DIFF_USAGE,\n+\t\tRERERE_FORGET_USAGE,\n+\t\tRERERE_GC_USAGE,\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\n-- \n2.56.0.611.g1030f0b940.dirty\n\n\n"},{"id":"558293","messageId":"CAOLa=ZTAYtq0K4YfcSBocf-fxadTiaJp+AV5-_6_pbNMBwYQXA@mail.gmail.com","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-12T13:41:29Z","receivedAt":"2026-11-12T13:41:29Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Hi,\n>\n> while reviewing some patch series around git-rerere(1) recently I was a\n> bit appalled by our custom subcommand parsing that we do here. This\n> patch series here thus cleans up and modernizes that part a bit so that\n> git-rerere(1) behaves like every other Git command that happens to have\n> subcommands.\n>\n> This series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\n> ps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\n> rerere cache state, 2026-10-23) merged into it.\n>\n> Changes in v4:\n>   - Some more polishing for `RERERE_{NO,}AUTOUPDATE` documentation.\n>   - Die in case both of these flags are passed.\n\nDefinitely a welcome improvement!\n\n>   - Link to v3: https://patch.msgid.link/20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im\n>\n> Changes in v3:\n>   - Clarify what `RERERE_NOAUTOUPDATE` does.\n>   - Link to v2: https://patch.msgid.link/20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im\n>\n> Changes in v2:\n>   - Document rerere flags.\n>   - Rename `rerere_record()` to just `rerere()`.\n>   - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im\n>\n> Thanks!\n>\n> Patrick\n\n[snip]\n\n> Range-diff versus v3:\n>\n>  1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`\n>  2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum\n>     @@ Commit message\n>          around as enums so that it becomes trivial to see what kind of flags are\n>          expected. Adapt the rerere flags accordingly and document them.\n>\n>     +    While at it, detect the case where both `RERERE_AUTOUPDATE` and\n>     +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot\n>     +    of sense, and it's not obvious which of those flags takes precedence\n>     +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of\n>     +    those flags, but let's be safe rather than sorry and `BUG()` in case\n>     +    both are passed.\n>     +\n>          Signed-off-by: Patrick Steinhardt <ps@pks.im>\n>\n>       ## rerere.c ##\n>     @@ rerere.c: static int is_rerere_enabled(struct repository *r)\n>       {\n>       \tint lock_timeout_ms = 1000;\n>       \tint fd;\n>     +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n>     + \trepo_config_get_bool(r, \"rerere.autoupdate\", &cache->autoupdate);\n>     + \trepo_config_get_int(r, \"rerere.locktimeout\", &lock_timeout_ms);\n>     +\n>     ++\tif ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))\n>     ++\t\tBUG(\"RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE\");\n>     + \tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n>     + \t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n>     + \tif ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))\n>      @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n>       \treturn fd;\n>       }\n>     @@ rerere.h: struct rerere_id {\n>      +\tRERERE_AUTOUPDATE = (1 << 0),\n>      +\n>      +\t/*\n>     -+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n>     -+\t * working tree but don't touch the index.\n>     ++\t * update the file in the working tree but don't touch the index. This\n\nNit: s/update/Update\n\n>     ++\t * can be used to explicitly override \"rerere.autoUpdate\".\n>     ++\t *\n>     ++\t * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is\n>     ++\t * invalid to pass both flags at the same time.\n>      +\t */\n>      +\tRERERE_NOAUTOUPDATE = (1 << 1),\n>      +\n>  3:  99faad47068 =  3:  48692c2c88d builtin/rerere: drop `the_repository`\n>  4:  f164c482227 =  4:  e76991dd39d builtin/rerere: stop passing flags to subcommands that ignore them\n>  5:  0573d2323e8 =  5:  2474dca4713 builtin/rerere: turn \"forget\" into a proper subcommand\n>  6:  2098dedf4fd =  6:  cecdbb1c63b builtin/rerere: turn \"clear\" into a proper subcommand\n>  7:  e8eaa2b4092 =  7:  54fc766f9d2 builtin/rerere: turn \"status\" into a proper subcommand\n>  8:  a5781284b8b =  8:  fa2c839b2cb builtin/rerere: turn \"remaining\" into a proper subcommand\n>  9:  9a4278df0ea =  9:  416b8311ca9 builtin/rerere: turn \"diff\" into a proper subcommand\n> 10:  e63b9be0d74 = 10:  adb2b68f833 builtin/rerere: turn \"gc\" into a proper subcommand\n> 11:  47889896ecb = 11:  a12e19cb2e8 builtin/rerere: use `OPT_SUBCOMMAND()`\n> 12:  5e16a247b49 = 12:  4b1b6170ba3 builtin/rerere: introduce proper usage strings for subcommands\n>\n> ---\n> base-commit: 710910c03a22ac663885049213b9fef5853ea8e0\n> change-id: 20261027-pks-rerere-subcommands-318d41553438\n\nLooks good. Thanks!\n"},{"id":"558371","messageId":"ava6Q1u65ASVeth5@pks.im","threadId":"66677","inReplyTo":"CAOLa=ZTAYtq0K4YfcSBocf-fxadTiaJp+AV5-_6_pbNMBwYQXA@mail.gmail.com","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-13T07:20:35Z","receivedAt":"2026-11-13T07:20:35Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 05:41:29AM -0800, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> > Range-diff versus v3:\n> >\n> >  1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`\n> >  2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum\n> >     @@ Commit message\n> >          around as enums so that it becomes trivial to see what kind of flags are\n> >          expected. Adapt the rerere flags accordingly and document them.\n> >\n> >     +    While at it, detect the case where both `RERERE_AUTOUPDATE` and\n> >     +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot\n> >     +    of sense, and it's not obvious which of those flags takes precedence\n> >     +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of\n> >     +    those flags, but let's be safe rather than sorry and `BUG()` in case\n> >     +    both are passed.\n> >     +\n> >          Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> >\n> >       ## rerere.c ##\n> >     @@ rerere.c: static int is_rerere_enabled(struct repository *r)\n> >       {\n> >       \tint lock_timeout_ms = 1000;\n> >       \tint fd;\n> >     +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n> >     + \trepo_config_get_bool(r, \"rerere.autoupdate\", &cache->autoupdate);\n> >     + \trepo_config_get_int(r, \"rerere.locktimeout\", &lock_timeout_ms);\n> >     +\n> >     ++\tif ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))\n> >     ++\t\tBUG(\"RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE\");\n> >     + \tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n> >     + \t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n> >     + \tif ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))\n> >      @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,\n> >       \treturn fd;\n> >       }\n> >     @@ rerere.h: struct rerere_id {\n> >      +\tRERERE_AUTOUPDATE = (1 << 0),\n> >      +\n> >      +\t/*\n> >     -+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n> >     -+\t * working tree but don't touch the index.\n> >     ++\t * update the file in the working tree but don't touch the index. This\n> \n> Nit: s/update/Update\n\nOops, good catch. I'll refrain from sending out another version just to\nfix this one fix though. Junio, I'd appreciate it if you could fix this\nup in your tree. Thanks!\n\nPatrick\n\n"},{"id":"558412","messageId":"xmqq33t4eh84.fsf@gitster.g","threadId":"66677","inReplyTo":"ava6Q1u65ASVeth5@pks.im","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-13T18:09:15Z","receivedAt":"2026-11-13T18:09:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> >     @@ rerere.h: struct rerere_id {\n>> >      +\tRERERE_AUTOUPDATE = (1 << 0),\n>> >      +\n>> >      +\t/*\n>> >     -+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n>> >     -+\t * working tree but don't touch the index.\n>> >     ++\t * update the file in the working tree but don't touch the index. This\n>> \n>> Nit: s/update/Update\n>\n> Oops, good catch. I'll refrain from sending out another version just to\n> fix this one fix though. Junio, I'd appreciate it if you could fix this\n> up in your tree. Thanks!\n\n    $ git checkout ps/rerere-subcommands\n    $ edit rerere.h\n    $ git log --oneline --first-parent master..\n    $ git commit -a --fixup HEAD~10\n    $ git rebase --autosquash HEAD~11\n\nBy the way, I wonder if we can simplify the last three steps in any\nway?\n\n * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n\n * The last \"rebase\" does not have to be on HEAD~11; as long as it\n   covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n   interested in taking any new development from there, and I do not\n   want to worry about what the command would do on the merges the\n   topic has as synthetic base.\n\nPerhaps with newer experimental commands it becomes easier to\nmanage?\n\n\n"},{"id":"558420","messageId":"20261113193811.cjM3D%taahol@utu.fi","threadId":"66677","inReplyTo":"xmqq33t4eh84.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Tuomas Ahola","fromEmail":"taahol@utu.fi","sentAt":"2026-11-13T19:38:11Z","receivedAt":"2026-11-13T19:38:11Z","isPatch":true,"sender":{"key":"taahol@utu.fi","avatar":"https://avatars.githubusercontent.com/u/114303477?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> >> >     @@ rerere.h: struct rerere_id {\n> >> >      +\tRERERE_AUTOUPDATE = (1 << 0),\n> >> >      +\n> >> >      +\t/*\n> >> >     -+\t * Reverse of RERERE_AUTOUPDATE. That is, update the file in the\n> >> >     -+\t * working tree but don't touch the index.\n> >> >     ++\t * update the file in the working tree but don't touch the index. This\n> >> \n> >> Nit: s/update/Update\n> >\n> > Oops, good catch. I'll refrain from sending out another version just to\n> > fix this one fix though. Junio, I'd appreciate it if you could fix this\n> > up in your tree. Thanks!\n> \n>     $ git checkout ps/rerere-subcommands\n>     $ edit rerere.h\n>     $ git log --oneline --first-parent master..\n>     $ git commit -a --fixup HEAD~10\n>     $ git rebase --autosquash HEAD~11\n> \n> By the way, I wonder if we can simplify the last three steps in any\n> way?\n> \n>  * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n> \n>  * The last \"rebase\" does not have to be on HEAD~11; as long as it\n>    covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n>    interested in taking any new development from there, and I do not\n>    want to worry about what the command would do on the merges the\n>    topic has as synthetic base.\n> \n\nJust for hack's sake :-)\n\n\t$ git rebase --autosquash $(git rev-list --min-parents=2 --max-count=1 HEAD)\n\n> Perhaps with newer experimental commands it becomes easier to\n> manage?\n> \n\n"},{"id":"558422","messageId":"1ebac86a-6674-4c6c-bcff-a71c05b26d3f@gmail.com","threadId":"66677","inReplyTo":"xmqq33t4eh84.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-11-13T19:44:31Z","receivedAt":"2026-11-13T19:44:31Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 13/11/2026 18:09, Junio C Hamano wrote:\n> >      $ git checkout ps/rerere-subcommands\n>      $ edit rerere.h\n>      $ git log --oneline --first-parent master..\n>      $ git commit -a --fixup HEAD~10\n>      $ git rebase --autosquash HEAD~11\n> > By the way, I wonder if we can simplify the last three steps in any\n> way?\n> >   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n> >   * The last \"rebase\" does not have to be on HEAD~11; as long as it\n>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n>     interested in taking any new development from there, and I do not\n>     want to worry about what the command would do on the merges the\n>     topic has as synthetic base.\n\nSo long as you've set an upstream branch, you can use \"--keep-base\" and omit the upstream commit.\n\nThanks\n\nPhillip\n\n\n"},{"id":"558426","messageId":"xmqqtslk9zk2.fsf@gitster.g","threadId":"66677","inReplyTo":"1ebac86a-6674-4c6c-bcff-a71c05b26d3f@gmail.com","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-13T21:44:29Z","receivedAt":"2026-11-13T21:44:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> On 13/11/2026 18:09, Junio C Hamano wrote:\n>> \n>>      $ git checkout ps/rerere-subcommands\n>>      $ edit rerere.h\n>>      $ git log --oneline --first-parent master..\n>>      $ git commit -a --fixup HEAD~10\n>>      $ git rebase --autosquash HEAD~11\n>> \n>> By the way, I wonder if we can simplify the last three steps in any\n>> way?\n>> \n>>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n>> \n>>   * The last \"rebase\" does not have to be on HEAD~11; as long as it\n>>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n>>     interested in taking any new development from there, and I do not\n>>     want to worry about what the command would do on the merges the\n>>     topic has as synthetic base.\n>\n> So long as you've set an upstream branch, you can use \"--keep-base\" and \n> omit the upstream commit.\n\nI do not think I want to set upstream for ~600 topic branches (among\n~100 are still in flight) I keep around.  I was hoping that after\nmaking fixup changes in my editor and adding them to the index\n\n    $ edit rerere.h\n    $ git add -u\n\nA single command that names the target of the added change\n\n    $ git fixup HEAD~10\n\nwould automatically do the two \"commit && rebase\" commands.\n\n\n\n\n"},{"id":"558446","messageId":"20261114072240.DBIRJ%taahol@utu.fi","threadId":"66677","inReplyTo":"xmqqtslk9zk2.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Tuomas Ahola","fromEmail":"taahol@utu.fi","sentAt":"2026-11-14T07:22:40Z","receivedAt":"2026-11-14T07:22:40Z","isPatch":true,"sender":{"key":"taahol@utu.fi","avatar":"https://avatars.githubusercontent.com/u/114303477?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n\n> Phillip Wood <phillip.wood123@gmail.com> writes:\n> \n> > On 13/11/2026 18:09, Junio C Hamano wrote:\n> >> \n> >>      $ git checkout ps/rerere-subcommands\n> >>      $ edit rerere.h\n> >>      $ git log --oneline --first-parent master..\n> >>      $ git commit -a --fixup HEAD~10\n> >>      $ git rebase --autosquash HEAD~11\n> >> \n> >> By the way, I wonder if we can simplify the last three steps in any\n> >> way?\n> >> \n> >>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n> >> \n> >>   * The last \"rebase\" does not have to be on HEAD~11; as long as it\n> >>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n> >>     interested in taking any new development from there, and I do not\n> >>     want to worry about what the command would do on the merges the\n> >>     topic has as synthetic base.\n> >\n> > So long as you've set an upstream branch, you can use \"--keep-base\" and \n> > omit the upstream commit.\n> \n> I do not think I want to set upstream for ~600 topic branches (among\n> ~100 are still in flight) I keep around.  I was hoping that after\n> making fixup changes in my editor and adding them to the index\n> \n>     $ edit rerere.h\n>     $ git add -u\n> \n> A single command that names the target of the added change\n> \n>     $ git fixup HEAD~10\n> \n> would automatically do the two \"commit && rebase\" commands.\n> \n\nWhich is exactly what 'git history fixup HEAD~10' strives to do, isn't it?\n\n"},{"id":"558450","messageId":"xmqq7bifponx.fsf@gitster.g","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-14T12:45:22Z","receivedAt":"2026-11-14T12:45:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Does the new syntax introduce a subtle UI regression that does not\nallow certain options before subcommands?  We used to take \"git\nrerere --skip-locked gc\", but now it has to be spelled as \"git\nrerere gc --skip-locked\", it seems.\n\nI do not particularly care about the '--skip-locked' option itself,\nand I personally prefer to see options after non-options as a\ngeneral CLI principle, but it seems that it is now required to give\nthe option after the \"gc\" subcommand.\n\nI do not know how often people run \"git rerere\" with these\nsubcommands themselves.  This subtle change in the CLI may go\nunnoticed in a smaller project, but because we probably have more\nthan a few thousand users, I am afraid that somebody will notice.\n\nIn the transcript below, \"rungit TRACK\" is my short-hand to run\nversion of \"git\" from that integration branch.\n\n$ rungit master rerere --skip-locked gc\n$ rungit next rerere --skip-locked gc\n$ rungit seen rerere --skip-locked gc\nerror: unknown option `skip-locked'\nusage: git rerere [--[no-]rerere-autoupdate]\n\n    --[no-]rerere-autoupdate\n                          register clean resolutions in index\n$ rungit seen rerere gc --skip-locked\n\n"},{"id":"558521","messageId":"avq08CLwtg0GQWnN@pks.im","threadId":"66677","inReplyTo":"20261114072240.DBIRJ%taahol@utu.fi","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T07:46:56Z","receivedAt":"2026-11-16T07:46:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Nov 14, 2026 at 09:22:40AM +0200, Tuomas Ahola wrote:\n> Junio C Hamano <gitster@pobox.com> wrote:\n> \n> > Phillip Wood <phillip.wood123@gmail.com> writes:\n> > \n> > > On 13/11/2026 18:09, Junio C Hamano wrote:\n> > >> \n> > >>      $ git checkout ps/rerere-subcommands\n> > >>      $ edit rerere.h\n> > >>      $ git log --oneline --first-parent master..\n> > >>      $ git commit -a --fixup HEAD~10\n> > >>      $ git rebase --autosquash HEAD~11\n> > >> \n> > >> By the way, I wonder if we can simplify the last three steps in any\n> > >> way?\n> > >> \n> > >>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.\n> > >> \n> > >>   * The last \"rebase\" does not have to be on HEAD~11; as long as it\n> > >>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*\n> > >>     interested in taking any new development from there, and I do not\n> > >>     want to worry about what the command would do on the merges the\n> > >>     topic has as synthetic base.\n> > >\n> > > So long as you've set an upstream branch, you can use \"--keep-base\" and \n> > > omit the upstream commit.\n> > \n> > I do not think I want to set upstream for ~600 topic branches (among\n> > ~100 are still in flight) I keep around.  I was hoping that after\n> > making fixup changes in my editor and adding them to the index\n> > \n> >     $ edit rerere.h\n> >     $ git add -u\n> > \n> > A single command that names the target of the added change\n> > \n> >     $ git fixup HEAD~10\n> > \n> > would automatically do the two \"commit && rebase\" commands.\n> > \n> \n> Which is exactly what 'git history fixup HEAD~10' strives to do, isn't it?\n\nYup. The only part still missing there to help Junio's case is to replay\nmerge commits. Once it supports that you can say `git history fixup\n\"HEAD^{/^rerere: convert flags}\"`.\n\nPatrick\n\n"},{"id":"558522","messageId":"avq3YHb_J8Ww6Kq7@pks.im","threadId":"66677","inReplyTo":"xmqq7bifponx.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T07:57:20Z","receivedAt":"2026-11-16T07:57:20Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Nov 14, 2026 at 04:45:22AM -0800, Junio C Hamano wrote:\n> Does the new syntax introduce a subtle UI regression that does not\n> allow certain options before subcommands?  We used to take \"git\n> rerere --skip-locked gc\", but now it has to be spelled as \"git\n> rerere gc --skip-locked\", it seems.\n> \n> I do not particularly care about the '--skip-locked' option itself,\n> and I personally prefer to see options after non-options as a\n> general CLI principle, but it seems that it is now required to give\n> the option after the \"gc\" subcommand.\n> \n> I do not know how often people run \"git rerere\" with these\n> subcommands themselves.  This subtle change in the CLI may go\n> unnoticed in a smaller project, but because we probably have more\n> than a few thousand users, I am afraid that somebody will notice.\n> \n> In the transcript below, \"rungit TRACK\" is my short-hand to run\n> version of \"git\" from that integration branch.\n> \n> $ rungit master rerere --skip-locked gc\n> $ rungit next rerere --skip-locked gc\n> $ rungit seen rerere --skip-locked gc\n> error: unknown option `skip-locked'\n> usage: git rerere [--[no-]rerere-autoupdate]\n> \n>     --[no-]rerere-autoupdate\n>                           register clean resolutions in index\n> $ rungit seen rerere gc --skip-locked\n\nYes, as documented in \"builtin/rerere: use `OPT_SUBCOMMAND()`.\n\n  Unfortunately this means that we have a backwards-incompatible change\n  because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n  subcommands. But this was arguably broken and misleading as we ignore\n  this flag for any other subcommand aynway. So we cheat a bit and simply\n  call it a bug that those flags were accepted in the first place.\n\nBut yes, the same is true for \"--skip-locked\". I was expecting more\nreview feedback on that specific part, and was a bit surprised to get\nnone.\n\nAs documented in the commit message, I would argue that the current\nstatus quo is just plain broken as we accept options in cases where they\naren't even being used at all. For \"--skip-locked\" that shouldn't be\nmuch of an issue, as the flag has only just been introduced, so it's\nvery unlikely that there's any users of it out there just yet. So now is\nthe right moment to fix that design wart.\n\nBUt that isn't true for the \"--rerere-autoupdate\" flag, which has\nexisted for a long time already. So if this backwards-incompatible\nchange is deemed to be too risky, then I'd adapt the code to only allow\nthat one flag in all locations.\n\nPatrick\n\n"},{"id":"558554","messageId":"xmqqik1wn5mu.fsf@gitster.g","threadId":"66677","inReplyTo":"avq3YHb_J8Ww6Kq7@pks.im","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-16T15:43:53Z","receivedAt":"2026-11-16T15:43:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> $ rungit seen rerere --skip-locked gc\n>> error: unknown option `skip-locked'\n>> usage: git rerere [--[no-]rerere-autoupdate]\n>> \n>>     --[no-]rerere-autoupdate\n>>                           register clean resolutions in index\n>> $ rungit seen rerere gc --skip-locked\n>\n> Yes, as documented in \"builtin/rerere: use `OPT_SUBCOMMAND()`.\n>\n>   Unfortunately this means that we have a backwards-incompatible change\n>   because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n>   subcommands. But this was arguably broken and misleading as we ignore\n>   this flag for any other subcommand aynway. So we cheat a bit and simply\n>   call it a bug that those flags were accepted in the first place.\n\nAh, I missed that part.\n\n> But yes, the same is true for \"--skip-locked\". I was expecting more\n> review feedback on that specific part, and was a bit surprised to get\n> none.\n\nOK.  Let's break it and have the users fix their scripts.\n\n"},{"id":"558589","messageId":"xmqqbj7oi7fn.fsf@gitster.g","threadId":"66677","inReplyTo":"xmqqik1wn5mu.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T01:16:12Z","receivedAt":"2026-11-17T01:16:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n>>> $ rungit seen rerere --skip-locked gc\n>>> error: unknown option `skip-locked'\n>>> usage: git rerere [--[no-]rerere-autoupdate]\n>>> \n>>>     --[no-]rerere-autoupdate\n>>>                           register clean resolutions in index\n>>> $ rungit seen rerere gc --skip-locked\n>>\n>> Yes, as documented in \"builtin/rerere: use `OPT_SUBCOMMAND()`.\n>>\n>>   Unfortunately this means that we have a backwards-incompatible change\n>>   because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n>>   subcommands. But this was arguably broken and misleading as we ignore\n>>   this flag for any other subcommand aynway. So we cheat a bit and simply\n>>   call it a bug that those flags were accepted in the first place.\n>\n> Ah, I missed that part.\n>\n>> But yes, the same is true for \"--skip-locked\". I was expecting more\n>> review feedback on that specific part, and was a bit surprised to get\n>> none.\n>\n> OK.  Let's break it and have the users fix their scripts.\n\nHaving said that\n\n    $ rungit seen rerere unknown\n    usage: too many arguments\n    $ rungit master rerere unknown\n    usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\n\nthe above might be a regression that is more easily spotted by\nfolks.\n\n"},{"id":"558590","messageId":"xmqq33t0i76r.fsf@gitster.g","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-10-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 10/12] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T01:21:32Z","receivedAt":"2026-11-17T01:21:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> As explained in a preceding commit, a subsequent commit will introduce\n> proper subcommands as supported by our parse-options subsystem. Refactor\n> the \"gc\" subcommand to use parse-options as a preparatory step.\n\nEven though the cover letter may have mentioned it, this should also\ndescribe the deliberate UI regression to help future readers of \"git\nlog\".  When they see a bug report on the mailing list and bisect\nleads to this commit, it makes a huge difference if you tell them\nthat the change in behavior was deliberate, with a clear reason\nexplained in the log message.  Otherwise they would say \"the UI\nregressed with this commit without explaining why it was thought to\nbe a good idea.  The commit unceremoniously drops a test that points\nout this exact regression\".\n\n\n\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n>  t/t4200-rerere.sh |  5 -----\n>  2 files changed, 30 insertions(+), 18 deletions(-)\n\n> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\n> index ab412ecc6e8..0d4cbf5114a 100755\n> --- a/t/t4200-rerere.sh\n> +++ b/t/t4200-rerere.sh\n> @@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n>  \ttest_path_is_missing $rr2/preimage\n>  '\n>  \n> -test_expect_success '--skip-locked is only accepted by gc' '\n> -\ttest_must_fail git rerere --skip-locked clear 2>err &&\n> -\ttest_grep \"option .--skip-locked. requires .gc.\" err\n> -'\n> -\n>  test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n>  \tgit reset --hard &&\n>  \trm -rf $rr &&\n\n"},{"id":"558591","messageId":"xmqqwlqcgsan.fsf@gitster.g","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-11-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T01:28:32Z","receivedAt":"2026-11-17T01:28:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In git-rerere(1) we have our own custom logic to parse subcommands. In\n> preceding commits we have refactored all of those subcommands so that\n> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\n> these so that we get rid of our custom subcommand parsing.\n>\n> Unfortunately this means that we have a backwards-incompatible change\n> because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n> subcommands. But this was arguably broken and misleading as we ignore\n> this flag for any other subcommand aynway. So we cheat a bit and simply\n> call it a bug that those flags were accepted in the first place.\n>\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n>  1 file changed, 56 insertions(+), 28 deletions(-)\n\nI already mentioned\n\n$ rungit master rerere unknown\nusage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\n\n    --[no-]rerere-autoupdate\n                          register clean resolutions in index\n\nvs\n\n$ rungit seen rerere unknown\nusage: too many arguments\n\nand it is this step that may be responsible for some of it.\n\n> @@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n>  \t       const char *prefix,\n>  \t       struct repository *repo)\n>  {\n> +\tparse_opt_subcommand_fn *fn = NULL;\n> +\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n> +\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n> +\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n> +\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n> +\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n> +\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n>  \t\tOPT_END(),\n>  \t};\n>  \n>  \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n> +\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n>  \trepo_config(repo, git_xmerge_config, NULL);\n>  \n> +\tif (!fn) {\n> +\t\tstruct strvec args = STRVEC_INIT;\n> +\t\tconst char **args_copy;\n> +\t\tint ret;\n>  \n> +\t\tstrvec_push(&args, \"perform\");\n> +\t\tstrvec_pushv(&args, argv);\n>  \n> +\t\t/*\n> +\t\t * We need to copy the array as it will be modified by\n> +\t\t * `parse_options()`, and if so we leak the strings\n> +\t\t * referenced by `args`.\n> +\t\t */\n> +\t\tCALLOC_ARRAY(args_copy, args.nr);\n> +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n\nDoes args.nr count the terminating NULL pointer?  We mimic the\nfamiliar (ac, av) convention of the C language; av[ac] being NULL is\nalso part of the convention, so if CALLOC_ARRAY() is not allocating\nan entry for the terminating NULL and COPY_ARRAY() is not copying\nargs together with the NULL, this may want to be corrected.\n\n> +\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n> +\n> +\t\tstrvec_clear(&args);\n> +\t\tfree(args_copy);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn fn(argc, argv, prefix, repo);\n>  }\n\n"},{"id":"558592","messageId":"xmqqo6bogrvc.fsf@gitster.g","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-12-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T01:37:43Z","receivedAt":"2026-11-17T01:37:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\n> index 4e6ab9a27c9..e04e9ef3ef8 100644\n> --- a/Documentation/git-rerere.adoc\n> +++ b/Documentation/git-rerere.adoc\n> @@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n> +'git rerere' [--[no-]rerere-autoupdate]\n> +'git rerere' clear\n> +'git rerere' diff\n> +'git rerere' forget <pathspec>...\n> +'git rerere' gc\n> +'git rerere' remaining\n> +'git rerere' status\n>  \n>  DESCRIPTION\n>  -----------\n\nThe above is consistent with [9/12] where we saw that the command\nbarfs if you say 'git rerere diff blurb'.\n\nYet, the documentation contradicts with the behaviour.\n\n    'diff'::\n\n    Display diffs for the current state of the resolution.  It is\n    useful for tracking what has changed while the user is resolving\n    conflicts.  Additional arguments are passed directly to the system\n    'diff' command installed in PATH.\n\nWe do not take additional arguments.  We do not pass anything to the\nsystem `diff` command installed in PATH.  It was a behaviour change\nleft undocumented ever since 658f365027 (Make git-rerere a builtin,\n2006-12-20) was done.\n\n\n\n"},{"id":"558593","messageId":"xmqqmrr8grv4.fsf@gitster.g","threadId":"66677","inReplyTo":"20261111-pks-rerere-subcommands-v4-9-df0c8bf79e16@pks.im","subject":"Re: [PATCH v4 09/12] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-17T01:37:51Z","receivedAt":"2026-11-17T01:37:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> +static int cmd_rerere_diff(int argc,\n> +\t\t\t   const char **argv,\n> +\t\t\t   const char *prefix,\n> +\t\t\t   struct repository *repo)\n> +{\n> +\tstruct option options[] = {\n> +\t\tOPT_END(),\n> +\t};\n> +\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n> +\tstruct strbuf buf = STRBUF_INIT;\n> +\tstruct rerere_cache cache;\n> +\n> +\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n> +\tif (argc)\n> +\t\tusage(_(\"too many arguments\"));\n\nWe will make a mental note that \"rerere diff\" does not take any\nextra arguments.\n\nThis matters when we look at the documentation patch later.\n\n"},{"id":"558710","messageId":"av2xijhHfFBANEHO@pks.im","threadId":"66677","inReplyTo":"xmqqo6bogrvc.fsf@gitster.g","subject":"Re: [PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-18T14:09:26Z","receivedAt":"2026-11-18T14:09:26Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 16, 2026 at 05:37:43PM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\n> > index 4e6ab9a27c9..e04e9ef3ef8 100644\n> > --- a/Documentation/git-rerere.adoc\n> > +++ b/Documentation/git-rerere.adoc\n> > @@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n> >  SYNOPSIS\n> >  --------\n> >  [verse]\n> > -'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n> > +'git rerere' [--[no-]rerere-autoupdate]\n> > +'git rerere' clear\n> > +'git rerere' diff\n> > +'git rerere' forget <pathspec>...\n> > +'git rerere' gc\n> > +'git rerere' remaining\n> > +'git rerere' status\n> >  \n> >  DESCRIPTION\n> >  -----------\n> \n> The above is consistent with [9/12] where we saw that the command\n> barfs if you say 'git rerere diff blurb'.\n> \n> Yet, the documentation contradicts with the behaviour.\n> \n>     'diff'::\n> \n>     Display diffs for the current state of the resolution.  It is\n>     useful for tracking what has changed while the user is resolving\n>     conflicts.  Additional arguments are passed directly to the system\n>     'diff' command installed in PATH.\n> \n> We do not take additional arguments.  We do not pass anything to the\n> system `diff` command installed in PATH.  It was a behaviour change\n> left undocumented ever since 658f365027 (Make git-rerere a builtin,\n> 2006-12-20) was done.\n\nHuh, interesting indeed. I'll include another patch to fix that while\nwe're here already.\n\nPatrick\n\n"},{"id":"558711","messageId":"av2xpF67qs6S0Hb7@pks.im","threadId":"66677","inReplyTo":"xmqqwlqcgsan.fsf@gitster.g","subject":"Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-18T14:09:40Z","receivedAt":"2026-11-18T14:09:40Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 16, 2026 at 05:28:32PM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > In git-rerere(1) we have our own custom logic to parse subcommands. In\n> > preceding commits we have refactored all of those subcommands so that\n> > they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\n> > these so that we get rid of our custom subcommand parsing.\n> >\n> > Unfortunately this means that we have a backwards-incompatible change\n> > because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n> > subcommands. But this was arguably broken and misleading as we ignore\n> > this flag for any other subcommand aynway. So we cheat a bit and simply\n> > call it a bug that those flags were accepted in the first place.\n> >\n> > Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> > ---\n> >  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------\n> >  1 file changed, 56 insertions(+), 28 deletions(-)\n> \n> I already mentioned\n> \n> $ rungit master rerere unknown\n> usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\n> \n>     --[no-]rerere-autoupdate\n>                           register clean resolutions in index\n> \n> vs\n> \n> $ rungit seen rerere unknown\n> usage: too many arguments\n> \n> and it is this step that may be responsible for some of it.\n\nRight, but isn't this actually an improvement? It's exactly the same way\nthat other commands with optional subcommands behave, e.g.:\n\n    $ git submodule\n    -855827c583bc30645ba427885caa40c5b81764d2 sha1collisiondetection\n    $ git submodule unknown\n    usage: git submodule [--quiet] [--cached]\n       or: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]\n\nOoh, no, it's the exact _other_ way round. We used to print the\nsynopsis, now we print \"too many arguments\". That's annoying and a\nregression indeed. Will fix.\n\n> > @@ -211,41 +237,43 @@ int cmd_rerere(int argc,\n> >  \t       const char *prefix,\n> >  \t       struct repository *repo)\n> >  {\n> > +\tparse_opt_subcommand_fn *fn = NULL;\n> > +\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n> > +\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n> > +\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n> > +\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n> > +\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n> > +\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n> >  \t\tOPT_END(),\n> >  \t};\n> >  \n> >  \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n> > +\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n> >  \trepo_config(repo, git_xmerge_config, NULL);\n> >  \n> > +\tif (!fn) {\n> > +\t\tstruct strvec args = STRVEC_INIT;\n> > +\t\tconst char **args_copy;\n> > +\t\tint ret;\n> >  \n> > +\t\tstrvec_push(&args, \"perform\");\n> > +\t\tstrvec_pushv(&args, argv);\n> >  \n> > +\t\t/*\n> > +\t\t * We need to copy the array as it will be modified by\n> > +\t\t * `parse_options()`, and if so we leak the strings\n> > +\t\t * referenced by `args`.\n> > +\t\t */\n> > +\t\tCALLOC_ARRAY(args_copy, args.nr);\n> > +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n> \n> Does args.nr count the terminating NULL pointer?  We mimic the\n> familiar (ac, av) convention of the C language; av[ac] being NULL is\n> also part of the convention, so if CALLOC_ARRAY() is not allocating\n> an entry for the terminating NULL and COPY_ARRAY() is not copying\n> args together with the NULL, this may want to be corrected.\n\nThat's a good point indeed. It likely doesn't matter, but better be safe\nthan sorry. Will adapt.\n\nPatrick\n\n"},{"id":"558712","messageId":"av2xrR48fdyIRwTL@pks.im","threadId":"66677","inReplyTo":"xmqqbj7oi7fn.fsf@gitster.g","subject":"Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-18T14:09:49Z","receivedAt":"2026-11-18T14:09:49Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 16, 2026 at 05:16:12PM -0800, Junio C Hamano wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > Patrick Steinhardt <ps@pks.im> writes:\n> >\n> >>> $ rungit seen rerere --skip-locked gc\n> >>> error: unknown option `skip-locked'\n> >>> usage: git rerere [--[no-]rerere-autoupdate]\n> >>> \n> >>>     --[no-]rerere-autoupdate\n> >>>                           register clean resolutions in index\n> >>> $ rungit seen rerere gc --skip-locked\n> >>\n> >> Yes, as documented in \"builtin/rerere: use `OPT_SUBCOMMAND()`.\n> >>\n> >>   Unfortunately this means that we have a backwards-incompatible change\n> >>   because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n> >>   subcommands. But this was arguably broken and misleading as we ignore\n> >>   this flag for any other subcommand aynway. So we cheat a bit and simply\n> >>   call it a bug that those flags were accepted in the first place.\n> >\n> > Ah, I missed that part.\n> >\n> >> But yes, the same is true for \"--skip-locked\". I was expecting more\n> >> review feedback on that specific part, and was a bit surprised to get\n> >> none.\n> >\n> > OK.  Let's break it and have the users fix their scripts.\n> \n> Having said that\n> \n>     $ rungit seen rerere unknown\n>     usage: too many arguments\n>     $ rungit master rerere unknown\n>     usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\n> \n> the above might be a regression that is more easily spotted by\n> folks.\n\nTrue, will fix.\n\nPatrick\n\n"},{"id":"558726","messageId":"xmqqse0y6pjf.fsf@gitster.g","threadId":"66677","inReplyTo":"av2xpF67qs6S0Hb7@pks.im","subject":"Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T17:02:44Z","receivedAt":"2026-11-18T17:02:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> > +\t\tCALLOC_ARRAY(args_copy, args.nr);\n>> > +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n>> \n>> Does args.nr count the terminating NULL pointer?  We mimic the\n>> familiar (ac, av) convention of the C language; av[ac] being NULL is\n>> also part of the convention, so if CALLOC_ARRAY() is not allocating\n>> an entry for the terminating NULL and COPY_ARRAY() is not copying\n>> args together with the NULL, this may want to be corrected.\n>\n> That's a good point indeed. It likely doesn't matter, but better be safe\n> than sorry. Will adapt.\n\nThe COPY_ARRAY() call can stay as-is.  CALLOC_ARRAY() needs to\nallocate one more element.\n\n\n\n\n"},{"id":"558821","messageId":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im","subject":"[PATCH v5 00/13] builtin/rerere: convert to use subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:01Z","receivedAt":"2026-11-19T11:47:01Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nwhile reviewing some patch series around git-rerere(1) recently I was a\nbit appalled by our custom subcommand parsing that we do here. This\npatch series here thus cleans up and modernizes that part a bit so that\ngit-rerere(1) behaves like every other Git command that happens to have\nsubcommands.\n\nThis series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with\nps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global\nrerere cache state, 2026-10-23) merged into it.\n\nChanges in v5:\n  - Explicitly docmuent the change in behaviour for the \"--skip-lock\"\n    flag.\n  - Add another patch to fix our documentation of `git rerere diff`,\n    which has been stale for the last two decades.\n  - Fix a regression where we didn't print the synopsis anymore when an\n    unknown subcommand is being passed.\n  - NULL-terminate argv.\n  - Link to v4: https://patch.msgid.link/20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.im\n\nChanges in v4:\n  - Some more polishing for `RERERE_{NO,}AUTOUPDATE` documentation.\n  - Die in case both of these flags are passed.\n  - Link to v3: https://patch.msgid.link/20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im\n\nChanges in v3:\n  - Clarify what `RERERE_NOAUTOUPDATE` does.\n  - Link to v2: https://patch.msgid.link/20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im\n\nChanges in v2:\n  - Document rerere flags.\n  - Rename `rerere_record()` to just `rerere()`.\n  - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (13):\n      rerere: rename `repo_rerere()`\n      rerere: convert flags into an enum\n      builtin/rerere: drop `the_repository`\n      builtin/rerere: stop passing flags to subcommands that ignore them\n      builtin/rerere: turn \"forget\" into a proper subcommand\n      builtin/rerere: turn \"clear\" into a proper subcommand\n      builtin/rerere: turn \"status\" into a proper subcommand\n      builtin/rerere: turn \"remaining\" into a proper subcommand\n      builtin/rerere: turn \"diff\" into a proper subcommand\n      builtin/rerere: turn \"gc\" into a proper subcommand\n      builtin/rerere: use `OPT_SUBCOMMAND()`\n      builtin/rerere: introduce proper usage strings for subcommands\n      Documentation/git-rerere: drop claim that we pass args to diff(1)\n\n Documentation/git-rerere.adoc |  11 +-\n apply.c                       |   2 +-\n builtin/am.c                  |   4 +-\n builtin/commit.c              |   2 +-\n builtin/merge.c               |   2 +-\n builtin/rerere.c              | 328 ++++++++++++++++++++++++++++++++----------\n builtin/stash.c               |   2 +-\n rerere.c                      |  14 +-\n rerere.h                      |  43 ++++--\n sequencer.c                   |   4 +-\n t/t4200-rerere.sh             |   5 -\n 11 files changed, 309 insertions(+), 108 deletions(-)\n\nRange-diff versus v4:\n\n 1:  0bb466edb5e =  1:  1587a58d92c rerere: rename `repo_rerere()`\n 2:  cc7e58429b2 !  2:  9ae3253dda0 rerere: convert flags into an enum\n    @@ rerere.h: struct rerere_id {\n     +\tRERERE_AUTOUPDATE = (1 << 0),\n     +\n     +\t/*\n    -+\t * update the file in the working tree but don't touch the index. This\n    ++\t * Update the file in the working tree but don't touch the index. This\n     +\t * can be used to explicitly override \"rerere.autoUpdate\".\n     +\t *\n     +\t * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is\n 3:  85299db3099 =  3:  e87e54d9b8a builtin/rerere: drop `the_repository`\n 4:  2f41c69859d =  4:  59ff81ab701 builtin/rerere: stop passing flags to subcommands that ignore them\n 5:  461e1c0848f =  5:  214ba91b19a builtin/rerere: turn \"forget\" into a proper subcommand\n 6:  09bc2e4b0da =  6:  e8f7fe874e7 builtin/rerere: turn \"clear\" into a proper subcommand\n 7:  6d058b1cef3 =  7:  e63f6f77887 builtin/rerere: turn \"status\" into a proper subcommand\n 8:  cfa7939b6b0 =  8:  893cd386a4c builtin/rerere: turn \"remaining\" into a proper subcommand\n 9:  13f60ac35aa =  9:  b7ff0206cac builtin/rerere: turn \"diff\" into a proper subcommand\n10:  f33edb14768 ! 10:  c40013dcbef builtin/rerere: turn \"gc\" into a proper subcommand\n    @@ Commit message\n         proper subcommands as supported by our parse-options subsystem. Refactor\n         the \"gc\" subcommand to use parse-options as a preparatory step.\n     \n    +    Note that this results in an intentional change in behaviour, as we\n    +    previously accepted the \"--skip-lock\" flag both before the subcommand\n    +    and after the subcommand name, whereas after this change we only allow\n    +    it after the subcommand name. But that flag has only recently been\n    +    introduced via 5f6b6aa3ab4 (rerere: add \"gc --skip-locked\" for auto\n    +    maintenance, 2026-10-13), which is not yet part of any release, so it's\n    +    unlikely that anybody will complain about this change.\n    +\n         Signed-off-by: Patrick Steinhardt <ps@pks.im>\n     \n      ## builtin/rerere.c ##\n11:  bb81a6d1d53 ! 11:  be17f9cc9a8 builtin/rerere: use `OPT_SUBCOMMAND()`\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     -\t\tflags = RERERE_AUTOUPDATE;\n     -\tif (autoupdate == 0)\n     -\t\tflags = RERERE_NOAUTOUPDATE;\n    -+\tif (!fn) {\n    -+\t\tstruct strvec args = STRVEC_INIT;\n    -+\t\tconst char **args_copy;\n    -+\t\tint ret;\n    - \n    +-\n     -\tif (argc < 1)\n     -\t\treturn rerere(repo, flags);\n     -\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     -\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n     -\telse\n     -\t\tusage_with_options(rerere_usage, options);\n    ++\tif (!fn) {\n    ++\t\tstruct strvec args = STRVEC_INIT;\n    ++\t\tconst char **args_copy;\n    ++\t\tint ret;\n    ++\n    ++\t\t/*\n    ++\t\t * The user may have either passed options for `git rerere`\n    ++\t\t * itself or they may have mistyped the subcommand name. We try\n    ++\t\t * to distinguish these two cases by checking whether argv[0]\n    ++\t\t * is a flag or not.\n    ++\t\t */\n    ++\t\tif (argc && !starts_with(argv[0], \"-\"))\n    ++\t\t\tusage_with_options(rerere_usage, options);\n    ++\n     +\t\tstrvec_push(&args, \"perform\");\n     +\t\tstrvec_pushv(&args, argv);\n    - \n    --\treturn 0;\n    ++\n     +\t\t/*\n     +\t\t * We need to copy the array as it will be modified by\n     +\t\t * `parse_options()`, and if so we leak the strings\n     +\t\t * referenced by `args`.\n     +\t\t */\n    -+\t\tCALLOC_ARRAY(args_copy, args.nr);\n    ++\t\tCALLOC_ARRAY(args_copy, args.nr + 1);\n     +\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n     +\n     +\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n    @@ builtin/rerere.c: int cmd_rerere(int argc,\n     +\t\tfree(args_copy);\n     +\t\treturn ret;\n     +\t}\n    -+\n    + \n    +-\treturn 0;\n     +\treturn fn(argc, argv, prefix, repo);\n      }\n12:  d9f0b174247 = 12:  7b85011eeeb builtin/rerere: introduce proper usage strings for subcommands\n -:  ----------- > 13:  ce0b34c4aee Documentation/git-rerere: drop claim that we pass args to diff(1)\n\n---\nbase-commit: 710910c03a22ac663885049213b9fef5853ea8e0\nchange-id: 20261027-pks-rerere-subcommands-318d41553438\n\n\n"},{"id":"558822","messageId":"20261119-pks-rerere-subcommands-v5-1-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 01/13] rerere: rename `repo_rerere()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:02Z","receivedAt":"2026-11-19T11:47:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `repo_rerere()` function is the only function in \"rerere.h\" that\ndoes not have a `rerere_` prefix. And while it does indeed receive a\nrepository as first parameter, that's not a good-enough reason to give\nit a `repo_` prefix.\n\nRename the function to just `rerere()`. Move around and extend\ndocumentation of this function to better explain what it does.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n apply.c          | 2 +-\n builtin/am.c     | 4 ++--\n builtin/commit.c | 2 +-\n builtin/merge.c  | 2 +-\n builtin/rerere.c | 2 +-\n builtin/stash.c  | 2 +-\n rerere.c         | 7 +------\n rerere.h         | 9 ++++++++-\n sequencer.c      | 4 ++--\n 9 files changed, 18 insertions(+), 16 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex a0b7119c639..646fabeafa3 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\t * tree with conflict markers, but that isn't written with --cached.\n \t\t */\n \t\tif (!state->cached)\n-\t\t\trepo_rerere(state->repo, 0);\n+\t\t\trerere(state->repo, 0);\n \t}\n \n \treturn errs;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex e9623b83077..4a5b37bee00 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n \t\to.verbosity = 0;\n \n \tif (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {\n-\t\trepo_rerere(the_repository, state->allow_rerere_autoupdate);\n+\t\trerere(the_repository, state->allow_rerere_autoupdate);\n \t\tfree(their_tree_name);\n \t\treturn error(_(\"Failed to merge in the changes.\"));\n \t}\n@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)\n \t\t\tgoto next;\n \t}\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \n \tdo_commit(state);\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 8ffd42681bb..3a4b94ad623 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,\n \n \tgit_test_write_commit_graph_or_die(the_repository);\n \n-\trepo_rerere(the_repository, 0);\n+\trerere(the_repository, 0);\n \trun_auto_maintenance(the_repository, quiet);\n \trun_commit_hook(use_editor, repo_get_index_file(the_repository),\n \t\t\tNULL, \"post-commit\", NULL);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex d7bf209114f..089e36e8575 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)\n \tfputs(msgbuf.buf, fp);\n \tstrbuf_release(&msgbuf);\n \tfclose(fp);\n-\trepo_rerere(the_repository, allow_rerere_auto);\n+\trerere(the_repository, allow_rerere_auto);\n \tprintf(_(\"Automatic merge failed; \"\n \t\t\t\"fix conflicts and then commit the result.\\n\"));\n \treturn 1;\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2c17f02f56d..a499e7b9151 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -83,7 +83,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn repo_rerere(the_repository, flags);\n+\t\treturn rerere(the_repository, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex e1a3a76bd04..91870a255fd 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,\n \t\tret = error(_(\"could not write index\"));\n \n \tif (ret) {\n-\t\trepo_rerere(the_repository, 0);\n+\t\trerere(the_repository, 0);\n \n \t\tif (index)\n \t\t\tfprintf_ln(stderr, _(\"Index was not unstashed.\"));\ndiff --git a/rerere.c b/rerere.c\nindex e0897612085..47a4a325bf5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-/*\n- * The main entry point that is called internally from codepaths that\n- * perform mergy operations, possibly leaving conflicted index entries\n- * and working tree files.\n- */\n-int repo_rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, int flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\ndiff --git a/rerere.h b/rerere.h\nindex d3cbd10e13f..dd9da03d6db 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       int flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n-int repo_rerere(struct repository *, int);\n+/*\n+ * The main entry point that is called internally from codepaths that\n+ * perform mergy operations, possibly leaving conflicted index entries\n+ * and working tree files. It records (and optionally updates) resolved\n+ * conflicts and reuses recorded resolutions for unresolved conflicts.\n+ */\n+int rerere(struct repository *r, int flags);\n+\n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n  * the recorded resolution (e.g. \"preimage\", \"postimage\"), return the\ndiff --git a/sequencer.c b/sequencer.c\nindex 508ec717920..ace1cfac1cb 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      short_commit_name(r, commit), msg.subject);\n \t\tprint_advice(r, res == 1, opts);\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \t\tgoto leave;\n \t}\n \n@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,\n \n \trollback_lock_file(&lock);\n \tif (ret)\n-\t\trepo_rerere(r, opts->allow_rerere_auto);\n+\t\trerere(r, opts->allow_rerere_auto);\n \telse\n \t\t/*\n \t\t * In case of problems, we now want to return a positive\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558823","messageId":"20261119-pks-rerere-subcommands-v5-2-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 02/13] rerere: convert flags into an enum","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:03Z","receivedAt":"2026-11-19T11:47:03Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Our modern coding guidelines say that flags should typically be passed\naround as enums so that it becomes trivial to see what kind of flags are\nexpected. Adapt the rerere flags accordingly and document them.\n\nWhile at it, detect the case where both `RERERE_AUTOUPDATE` and\n`RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot\nof sense, and it's not obvious which of those flags takes precedence\n(it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of\nthose flags, but let's be safe rather than sorry and `BUG()` in case\nboth are passed.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n rerere.c |  9 ++++++---\n rerere.h | 36 +++++++++++++++++++++++++++---------\n 2 files changed, 33 insertions(+), 12 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 47a4a325bf5..47d9077eeca 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags)\n+\t\t       enum rerere_flags flags)\n {\n \tint lock_timeout_ms = 1000;\n \tint fd;\n@@ -922,6 +922,8 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \trepo_config_get_bool(r, \"rerere.autoupdate\", &cache->autoupdate);\n \trepo_config_get_int(r, \"rerere.locktimeout\", &lock_timeout_ms);\n \n+\tif ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))\n+\t\tBUG(\"RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE\");\n \tif (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))\n \t\tcache->autoupdate = !!(flags & RERERE_AUTOUPDATE);\n \tif ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))\n@@ -951,7 +953,7 @@ int rerere_cache_setup(struct rerere_cache *cache,\n \treturn fd;\n }\n \n-int rerere(struct repository *r, int flags)\n+int rerere(struct repository *r, enum rerere_flags flags)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n@@ -1336,7 +1338,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)\n \treturn needed;\n }\n \n-void rerere_gc(struct repository *r, struct string_list *rr, int flags)\n+void rerere_gc(struct repository *r, struct string_list *rr,\n+\t       enum rerere_flags flags)\n {\n \tstruct rerere_cache cache;\n \tstruct string_list to_remove = STRING_LIST_INIT_DUP;\ndiff --git a/rerere.h b/rerere.h\nindex dd9da03d6db..239172e969a 100644\n--- a/rerere.h\n+++ b/rerere.h\n@@ -9,12 +9,6 @@\n struct pathspec;\n struct repository;\n \n-#define RERERE_AUTOUPDATE   01\n-#define RERERE_NOAUTOUPDATE 02\n-#define RERERE_READONLY     04\n-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */\n-#define RERERE_NOWAIT       010\n-\n /*\n  * Marks paths that have been hand-resolved and added to the\n  * index. Set in the util field of such paths after calling\n@@ -39,10 +33,33 @@ struct rerere_id {\n \tint variant;\n };\n \n+enum rerere_flags {\n+\t/*\n+\t * Auto-update the index with previously recorded resolutions. This can\n+\t * be used to explicitly override \"rerere.autoUpdate\".\n+\t */\n+\tRERERE_AUTOUPDATE = (1 << 0),\n+\n+\t/*\n+\t * Update the file in the working tree but don't touch the index. This\n+\t * can be used to explicitly override \"rerere.autoUpdate\".\n+\t *\n+\t * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is\n+\t * invalid to pass both flags at the same time.\n+\t */\n+\tRERERE_NOAUTOUPDATE = (1 << 1),\n+\n+\t/* Skip acquiring the MERGE_RR.lock for a read-only operation. */\n+\tRERERE_READONLY = (1 << 2),\n+\n+\t/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */\n+\tRERERE_NOWAIT = (1 << 3),\n+};\n+\n int rerere_cache_setup(struct rerere_cache *cache,\n \t\t       struct repository *r,\n \t\t       struct string_list *merge_rr,\n-\t\t       int flags);\n+\t\t       enum rerere_flags flags);\n void rerere_cache_release(struct rerere_cache *cache);\n \n /*\n@@ -51,7 +68,7 @@ void rerere_cache_release(struct rerere_cache *cache);\n  * and working tree files. It records (and optionally updates) resolved\n  * conflicts and reuses recorded resolutions for unresolved conflicts.\n  */\n-int rerere(struct repository *r, int flags);\n+int rerere(struct repository *r, enum rerere_flags flags);\n \n /*\n  * Given the conflict ID and the name of a \"file\" used for replaying\n@@ -65,7 +82,8 @@ const char *rerere_path(struct repository *,\n int rerere_forget(struct repository *, struct pathspec *);\n int rerere_remaining(struct repository *, struct string_list *);\n void rerere_clear(struct repository *, struct string_list *);\n-void rerere_gc(struct repository *, struct string_list *, int);\n+void rerere_gc(struct repository *, struct string_list *,\n+\t       enum rerere_flags flags);\n \n /*\n  * Check whether garbage collection for rerere entries is needed, which is\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558824","messageId":"20261119-pks-rerere-subcommands-v5-3-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 03/13] builtin/rerere: drop `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:04Z","receivedAt":"2026-11-19T11:47:04Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in git-rerere(1).\nAs that command cannot run outside of a repository these references can\nbe trivially replaced by the repository that's passed in as parameter to\n`cmd_rerere()`. We don't have to worry about the repository being `NULL`\nwhen called with \"-h\", either, as there are no references to the repo\nbefore we call `parse_options()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 24 +++++++++++-------------\n 1 file changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex a499e7b9151..83fb3783c61 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n-\t       struct repository *repo UNUSED)\n+\t       struct repository *repo)\n {\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tint autoupdate = -1, skip_locked = 0, flags = 0;\n@@ -75,7 +73,7 @@ int cmd_rerere(int argc,\n \tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n \t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n \n-\trepo_config(the_repository, git_xmerge_config, NULL);\n+\trepo_config(repo, git_xmerge_config, NULL);\n \n \tif (autoupdate == 1)\n \t\tflags = RERERE_AUTOUPDATE;\n@@ -83,7 +81,7 @@ int cmd_rerere(int argc,\n \t\tflags = RERERE_NOAUTOUPDATE;\n \n \tif (argc < 1)\n-\t\treturn rerere(the_repository, flags);\n+\t\treturn rerere(repo, flags);\n \n \tif (!strcmp(argv[0], \"forget\")) {\n \t\tstruct pathspec pathspec;\n@@ -94,21 +92,21 @@ int cmd_rerere(int argc,\n \t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n \t\t\t       prefix, argv + 1);\n \n-\t\tret = rerere_forget(the_repository, &pathspec);\n+\t\tret = rerere_forget(repo, &pathspec);\n \n \t\tclear_pathspec(&pathspec);\n \t\treturn ret;\n \t}\n \n \tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(the_repository, &merge_rr);\n+\t\trerere_clear(repo, &merge_rr);\n \t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(the_repository, &merge_rr,\n+\t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\")) {\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t       flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n@@ -116,7 +114,7 @@ int cmd_rerere(int argc,\n \n \t\trerere_cache_release(&cache);\n \t} else if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(the_repository, &merge_rr);\n+\t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n \t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -129,16 +127,16 @@ int cmd_rerere(int argc,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n-\t\tif (rerere_cache_setup(&cache, the_repository, &merge_rr,\n+\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n \t\t\t\t      flags | RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n \t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(the_repository, &buf, id, \"preimage\"),\n+\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n \t\t\t\t     path, path, path))\n \t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(the_repository, &buf, id, NULL));\n+\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n \t\t}\n \n \t\trerere_cache_release(&cache);\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558825","messageId":"20261119-pks-rerere-subcommands-v5-4-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 04/13] builtin/rerere: stop passing flags to subcommands that ignore them","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:05Z","receivedAt":"2026-11-19T11:47:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has a \"--[no-]rerere-autoupdate\" flag. If\npassed, we explicitly enable or disable recording clean merge\nresolutions that are staged in the index. This flag only matters to\ngit-rerere(1) when not executed with any subcommand, but we also forward\nthe flag to `git rerere status` and `git rerere diff`.\n\nThis is mostly harmless as we would ignore those flags anyway, but it\nmakes subsequent refactorings harder to understand. Prepare for these\nrefactorings by not using the flag in those subcommands anymore.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 83fb3783c61..405276cc94b 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -107,7 +107,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n \t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n@@ -128,7 +128,7 @@ int cmd_rerere(int argc,\n \t\tstruct rerere_cache cache;\n \n \t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t      flags | RERERE_READONLY) < 0)\n+\t\t\t\t       RERERE_READONLY) < 0)\n \t\t\treturn 0;\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tconst char *path = merge_rr.items[i].string;\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558826","messageId":"20261119-pks-rerere-subcommands-v5-5-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 05/13] builtin/rerere: turn \"forget\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:06Z","receivedAt":"2026-11-19T11:47:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The git-rerere(1) command has its own, home-grown implementation of\nsubcommands. Of course this implementation is inconsistent with how\nsubcommands typically work:\n\n  - Options from other subcommands apply to each other.\n\n  - We don't have proper usage strings.\n\n  - Running `git rerere <subcmd> -h` doesn't print the options that are\n    supported by that subcommand, but instead it just prints the help of\n    git-rerere(1) itself.\n\nA subsequent commit will thus introduce proper subcommands as supported\nby our parse-options subsystem. Refactor the \"forget\" subcommand to use\nparse-options as a preparatory step. The other commands will follow in\nsubsequent commits until all of them have been converted, and then we\nswitch over to `OPT_SUBCOMMAND()`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 38 ++++++++++++++++++++++++--------------\n 1 file changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 405276cc94b..5d2ae154ff8 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_forget(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct pathspec pathspec;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (!argc)\n+\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n+\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n+\n+\tret = rerere_forget(repo, &pathspec);\n+\n+\tclear_pathspec(&pathspec);\n+\treturn ret;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -83,20 +105,8 @@ int cmd_rerere(int argc,\n \tif (argc < 1)\n \t\treturn rerere(repo, flags);\n \n-\tif (!strcmp(argv[0], \"forget\")) {\n-\t\tstruct pathspec pathspec;\n-\t\tint ret;\n-\n-\t\tif (argc < 2)\n-\t\t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n-\t\tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,\n-\t\t\t       prefix, argv + 1);\n-\n-\t\tret = rerere_forget(repo, &pathspec);\n-\n-\t\tclear_pathspec(&pathspec);\n-\t\treturn ret;\n-\t}\n+\tif (!strcmp(argv[0], \"forget\"))\n+\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n \n \tif (!strcmp(argv[0], \"clear\")) {\n \t\trerere_clear(repo, &merge_rr);\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558827","messageId":"20261119-pks-rerere-subcommands-v5-6-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 06/13] builtin/rerere: turn \"clear\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:07Z","receivedAt":"2026-11-19T11:47:07Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"clear\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 25 ++++++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 5d2ae154ff8..62f69b488b0 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,\n \treturn ret;\n }\n \n+static int cmd_rerere_clear(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_clear(repo, &merge_rr);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -107,9 +127,8 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\n-\tif (!strcmp(argv[0], \"clear\")) {\n-\t\trerere_clear(repo, &merge_rr);\n+\telse if (!strcmp(argv[0], \"clear\")) {\n+\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558828","messageId":"20261119-pks-rerere-subcommands-v5-7-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 07/13] builtin/rerere: turn \"status\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:08Z","receivedAt":"2026-11-19T11:47:08Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"status\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------\n 1 file changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 62f69b488b0..2bcd270a1f1 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_status(int argc,\n+\t\t\t     const char **argv,\n+\t\t\t     const char *prefix,\n+\t\t\t     struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\tfor (size_t i = 0; i < merge_rr.nr; i++)\n+\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\treturn 0;\n+}\n+\n int cmd_rerere(int argc,\n \t       const char **argv,\n \t       const char *prefix,\n@@ -132,17 +158,9 @@ int cmd_rerere(int argc,\n \t} else if (!strcmp(argv[0], \"gc\"))\n \t\trerere_gc(repo, &merge_rr,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n-\telse if (!strcmp(argv[0], \"status\")) {\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++)\n-\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\n-\t\trerere_cache_release(&cache);\n-\t} else if (!strcmp(argv[0], \"remaining\")) {\n+\telse if (!strcmp(argv[0], \"status\"))\n+\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"remaining\")) {\n \t\trerere_remaining(repo, &merge_rr);\n \t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n \t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558829","messageId":"20261119-pks-rerere-subcommands-v5-8-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 08/13] builtin/rerere: turn \"remaining\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:09Z","receivedAt":"2026-11-19T11:47:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"remaining\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------\n 1 file changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 2bcd270a1f1..3f82bcbeb10 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_remaining(int argc,\n+\t\t\t\tconst char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_remaining(repo, &merge_rr);\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n+\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n+\t\telse\n+\t\t\t/* prepare for later call to\n+\t\t\t * string_list_clear() */\n+\t\t\tmerge_rr.items[i].util = NULL;\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_status(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -160,17 +188,9 @@ int cmd_rerere(int argc,\n \t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\")) {\n-\t\trerere_remaining(repo, &merge_rr);\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tif (merge_rr.items[i].util != RERERE_RESOLVED)\n-\t\t\t\tprintf(\"%s\\n\", merge_rr.items[i].string);\n-\t\t\telse\n-\t\t\t\t/* prepare for later call to\n-\t\t\t\t * string_list_clear() */\n-\t\t\t\tmerge_rr.items[i].util = NULL;\n-\t\t}\n-\t} else if (!strcmp(argv[0], \"diff\")) {\n+\telse if (!strcmp(argv[0], \"remaining\"))\n+\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n+\telse if (!strcmp(argv[0], \"diff\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tstruct rerere_cache cache;\n \n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558830","messageId":"20261119-pks-rerere-subcommands-v5-9-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 09/13] builtin/rerere: turn \"diff\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:10Z","receivedAt":"2026-11-19T11:47:10Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"diff\" subcommand to use parse-options as a preparatory step.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3f82bcbeb10..40bae5cb9cc 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_diff(int argc,\n+\t\t\t   const char **argv,\n+\t\t\t   const char *prefix,\n+\t\t\t   struct repository *repo)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct rerere_cache cache;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n+\t\t\t       RERERE_READONLY) < 0)\n+\t\treturn 0;\n+\n+\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n+\t\tconst char *path = merge_rr.items[i].string;\n+\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n+\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"), path, path, path))\n+\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n+\t\t\t    rerere_path(repo, &buf, id, NULL));\n+\t}\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\trerere_cache_release(&cache);\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_forget(int argc,\n \t\t\t     const char **argv,\n \t\t\t     const char *prefix,\n@@ -190,25 +224,9 @@ int cmd_rerere(int argc,\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n \t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\")) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tstruct rerere_cache cache;\n-\n-\t\tif (rerere_cache_setup(&cache, repo, &merge_rr,\n-\t\t\t\t       RERERE_READONLY) < 0)\n-\t\t\treturn 0;\n-\t\tfor (size_t i = 0; i < merge_rr.nr; i++) {\n-\t\t\tconst char *path = merge_rr.items[i].string;\n-\t\t\tconst struct rerere_id *id = merge_rr.items[i].util;\n-\t\t\tif (diff_two(rerere_path(repo, &buf, id, \"preimage\"),\n-\t\t\t\t     path, path, path))\n-\t\t\t\tdie(_(\"unable to generate diff for '%s'\"),\n-\t\t\t\t    rerere_path(repo, &buf, id, NULL));\n-\t\t}\n-\n-\t\trerere_cache_release(&cache);\n-\t\tstrbuf_release(&buf);\n-\t} else\n+\telse if (!strcmp(argv[0], \"diff\"))\n+\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n+\telse\n \t\tusage_with_options(rerere_usage, options);\n \n \tstring_list_clear(&merge_rr, 1);\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558831","messageId":"20261119-pks-rerere-subcommands-v5-10-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 10/13] builtin/rerere: turn \"gc\" into a proper subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:11Z","receivedAt":"2026-11-19T11:47:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"As explained in a preceding commit, a subsequent commit will introduce\nproper subcommands as supported by our parse-options subsystem. Refactor\nthe \"gc\" subcommand to use parse-options as a preparatory step.\n\nNote that this results in an intentional change in behaviour, as we\npreviously accepted the \"--skip-lock\" flag both before the subcommand\nand after the subcommand name, whereas after this change we only allow\nit after the subcommand name. But that flag has only recently been\nintroduced via 5f6b6aa3ab4 (rerere: add \"gc --skip-locked\" for auto\nmaintenance, 2026-10-13), which is not yet part of any release, so it's\nunlikely that anybody will complain about this change.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------\n t/t4200-rerere.sh |  5 -----\n 2 files changed, 30 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 40bae5cb9cc..3162b074ec6 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,\n \treturn ret;\n }\n \n+static int cmd_rerere_gc(int argc,\n+\t\t\t const char **argv,\n+\t\t\t const char *prefix,\n+\t\t\t struct repository *repo)\n+{\n+\tint skip_locked = 0;\n+\tstruct option options[] = {\n+\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n+\t\t\t\tN_(\"skip gc while another process holds the lock\")),\n+\t\tOPT_END(),\n+\t};\n+\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\trerere_gc(repo, &merge_rr,\n+\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\n+\tstring_list_clear(&merge_rr, 1);\n+\treturn 0;\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -187,21 +211,16 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n-\tint autoupdate = -1, skip_locked = 0, flags = 0;\n+\tint autoupdate = -1, flags = 0;\n \n \tstruct option options[] = {\n \t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n-\t\tOPT_HIDDEN_BOOL(0, \"skip-locked\", &skip_locked,\n-\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n-\n-\tif (skip_locked && (argc < 1 || strcmp(argv[0], \"gc\")))\n-\t\tdie(_(\"the option '%s' requires '%s'\"), \"--skip-locked\", \"gc\");\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage,\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n \n \trepo_config(repo, git_xmerge_config, NULL);\n \n@@ -215,11 +234,10 @@ int cmd_rerere(int argc,\n \n \tif (!strcmp(argv[0], \"forget\"))\n \t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\")) {\n+\telse if (!strcmp(argv[0], \"clear\"))\n \t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\t} else if (!strcmp(argv[0], \"gc\"))\n-\t\trerere_gc(repo, &merge_rr,\n-\t\t\t  skip_locked ? RERERE_NOWAIT : 0);\n+\telse if (!strcmp(argv[0], \"gc\"))\n+\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"status\"))\n \t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n \telse if (!strcmp(argv[0], \"remaining\"))\n@@ -229,6 +247,5 @@ int cmd_rerere(int argc,\n \telse\n \t\tusage_with_options(rerere_usage, options);\n \n-\tstring_list_clear(&merge_rr, 1);\n \treturn 0;\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex ab412ecc6e8..0d4cbf5114a 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '\n \ttest_path_is_missing $rr2/preimage\n '\n \n-test_expect_success '--skip-locked is only accepted by gc' '\n-\ttest_must_fail git rerere --skip-locked clear 2>err &&\n-\ttest_grep \"option .--skip-locked. requires .gc.\" err\n-'\n-\n test_expect_success 'a held lock is waited out within rerere.lockTimeout' '\n \tgit reset --hard &&\n \trm -rf $rr &&\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558832","messageId":"20261119-pks-rerere-subcommands-v5-11-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 11/13] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:12Z","receivedAt":"2026-11-19T11:47:12Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In git-rerere(1) we have our own custom logic to parse subcommands. In\npreceding commits we have refactored all of those subcommands so that\nthey are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\nthese so that we get rid of our custom subcommand parsing.\n\nUnfortunately this means that we have a backwards-incompatible change\nbecause we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\nsubcommands. But this was arguably broken and misleading as we ignore\nthis flag for any other subcommand aynway. So we cheat a bit and simply\ncall it a bug that those flags were accepted in the first place.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rerere.c | 95 +++++++++++++++++++++++++++++++++++++++-----------------\n 1 file changed, 66 insertions(+), 29 deletions(-)\n\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 3162b074ec6..8707c65560d 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -5,6 +5,7 @@\n #include \"rerere.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,\n \treturn 0;\n }\n \n+static int cmd_rerere_perform(int argc,\n+\t\t\t      const char **argv,\n+\t\t\t      const char *prefix,\n+\t\t\t      struct repository *repo)\n+{\n+\tint autoupdate = -1;\n+\tstruct option options[] = {\n+\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n+\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_END(),\n+\t};\n+\tenum rerere_flags flags = 0;\n+\n+\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\tif (argc)\n+\t\tusage(_(\"too many arguments\"));\n+\n+\tif (autoupdate == 1)\n+\t\tflags = RERERE_AUTOUPDATE;\n+\tif (autoupdate == 0)\n+\t\tflags = RERERE_NOAUTOUPDATE;\n+\n+\treturn rerere(repo, flags);\n+}\n+\n static int cmd_rerere_remaining(int argc,\n \t\t\t\tconst char **argv,\n \t\t\t\tconst char *prefix,\n@@ -211,41 +237,52 @@ int cmd_rerere(int argc,\n \t       const char *prefix,\n \t       struct repository *repo)\n {\n-\tint autoupdate = -1, flags = 0;\n-\n+\tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n-\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n-\t\t\tN_(\"register clean resolutions in index\"), 1),\n+\t\tOPT_SUBCOMMAND(\"clear\", &fn, cmd_rerere_clear),\n+\t\tOPT_SUBCOMMAND(\"diff\", &fn, cmd_rerere_diff),\n+\t\tOPT_SUBCOMMAND(\"forget\", &fn, cmd_rerere_forget),\n+\t\tOPT_SUBCOMMAND(\"gc\", &fn, cmd_rerere_gc),\n+\t\tOPT_SUBCOMMAND(\"remaining\", &fn, cmd_rerere_remaining),\n+\t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n-\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT);\n-\n+\t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n \trepo_config(repo, git_xmerge_config, NULL);\n \n-\tif (autoupdate == 1)\n-\t\tflags = RERERE_AUTOUPDATE;\n-\tif (autoupdate == 0)\n-\t\tflags = RERERE_NOAUTOUPDATE;\n-\n-\tif (argc < 1)\n-\t\treturn rerere(repo, flags);\n-\n-\tif (!strcmp(argv[0], \"forget\"))\n-\t\treturn cmd_rerere_forget(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"clear\"))\n-\t\treturn cmd_rerere_clear(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"gc\"))\n-\t\treturn cmd_rerere_gc(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"status\"))\n-\t\treturn cmd_rerere_status(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"remaining\"))\n-\t\treturn cmd_rerere_remaining(argc, argv, prefix, repo);\n-\telse if (!strcmp(argv[0], \"diff\"))\n-\t\treturn cmd_rerere_diff(argc, argv, prefix, repo);\n-\telse\n-\t\tusage_with_options(rerere_usage, options);\n+\tif (!fn) {\n+\t\tstruct strvec args = STRVEC_INIT;\n+\t\tconst char **args_copy;\n+\t\tint ret;\n+\n+\t\t/*\n+\t\t * The user may have either passed options for `git rerere`\n+\t\t * itself or they may have mistyped the subcommand name. We try\n+\t\t * to distinguish these two cases by checking whether argv[0]\n+\t\t * is a flag or not.\n+\t\t */\n+\t\tif (argc && !starts_with(argv[0], \"-\"))\n+\t\t\tusage_with_options(rerere_usage, options);\n+\n+\t\tstrvec_push(&args, \"perform\");\n+\t\tstrvec_pushv(&args, argv);\n+\n+\t\t/*\n+\t\t * We need to copy the array as it will be modified by\n+\t\t * `parse_options()`, and if so we leak the strings\n+\t\t * referenced by `args`.\n+\t\t */\n+\t\tCALLOC_ARRAY(args_copy, args.nr + 1);\n+\t\tCOPY_ARRAY(args_copy, args.v, args.nr);\n+\n+\t\tret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);\n+\n+\t\tstrvec_clear(&args);\n+\t\tfree(args_copy);\n+\t\treturn ret;\n+\t}\n \n-\treturn 0;\n+\treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558833","messageId":"20261119-pks-rerere-subcommands-v5-12-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 12/13] builtin/rerere: introduce proper usage strings for subcommands","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:13Z","receivedAt":"2026-11-19T11:47:13Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Adapt git-rerere(1) to have proper usage strings for each of the\nsubcommands.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc |  8 +++++-\n builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 58 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex 4e6ab9a27c9..e04e9ef3ef8 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges\n SYNOPSIS\n --------\n [verse]\n-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]\n+'git rerere' [--[no-]rerere-autoupdate]\n+'git rerere' clear\n+'git rerere' diff\n+'git rerere' forget <pathspec>...\n+'git rerere' gc\n+'git rerere' remaining\n+'git rerere' status\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 8707c65560d..5f1c0f31f6a 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -10,10 +10,13 @@\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\n \n-static const char * const rerere_usage[] = {\n-\tN_(\"git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\"),\n-\tNULL,\n-};\n+#define RERERE_USAGE N_(\"git rerere [--[no-]rerere-autoupdate]\")\n+#define RERERE_CLEAR_USAGE N_(\"git rerere clear\")\n+#define RERERE_DIFF_USAGE N_(\"git rerere diff\")\n+#define RERERE_FORGET_USAGE N_(\"git rerere forget <pathspec>...\")\n+#define RERERE_GC_USAGE N_(\"git rerere gc\")\n+#define RERERE_REMAINING_USAGE N_(\"git rerere remaining\")\n+#define RERERE_STATUS_USAGE N_(\"git rerere status\")\n \n static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)\n {\n@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_clear_usage[] = {\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_diff_usage[] = {\n+\t\tRERERE_DIFF_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_forget_usage[] = {\n+\t\tRERERE_FORGET_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct pathspec pathspec;\n \tint ret;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);\n \tif (!argc)\n \t\twarning(_(\"'git rerere forget' without paths is deprecated\"));\n \tparse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);\n@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,\n \t\t\t\tN_(\"skip gc while another process holds the lock\")),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_gc_usage[] = {\n+\t\tRERERE_GC_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,\n \t\t\tN_(\"register clean resolutions in index\"), 1),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tNULL,\n+\t};\n \tenum rerere_flags flags = 0;\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_remaining_usage[] = {\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,\n \tstruct option options[] = {\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_status_usage[] = {\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \tstruct string_list merge_rr = STRING_LIST_INIT_DUP;\n \tstruct rerere_cache cache;\n \n-\targc = parse_options(argc, argv, prefix, options, rerere_usage, 0);\n+\targc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);\n \tif (argc)\n \t\tusage(_(\"too many arguments\"));\n \n@@ -247,6 +278,16 @@ int cmd_rerere(int argc,\n \t\tOPT_SUBCOMMAND(\"status\", &fn, cmd_rerere_status),\n \t\tOPT_END(),\n \t};\n+\tconst char * const rerere_usage[] = {\n+\t\tRERERE_USAGE,\n+\t\tRERERE_CLEAR_USAGE,\n+\t\tRERERE_DIFF_USAGE,\n+\t\tRERERE_FORGET_USAGE,\n+\t\tRERERE_GC_USAGE,\n+\t\tRERERE_REMAINING_USAGE,\n+\t\tRERERE_STATUS_USAGE,\n+\t\tNULL,\n+\t};\n \n \targc = parse_options(argc, argv, prefix, options, rerere_usage,\n \t\t\t     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);\n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558834","messageId":"20261119-pks-rerere-subcommands-v5-13-0c1092b88958@pks.im","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im","subject":"[PATCH v5 13/13] Documentation/git-rerere: drop claim that we pass args to diff(1)","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T11:47:14Z","receivedAt":"2026-11-19T11:47:14Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Back in the old days, `git rerere diff` accepted arbitrary arguments\nthat would be passed on to the system `diff` command. This has changed\nin 658f3650273 (Make git-rerere a builtin, 2006-12-20), even though that\nchange seems to have been unintentional. And in fact, our documentation\nstill claims that arbitrary arguments are accepted.\n\nWhile the original change was unintended, nobody has complained in the\nlast two decades, so it's rather unlikely that anybody cares about this\nregression nowadays. Adapt the documentation to match current behaviour.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-rerere.adoc | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc\nindex e04e9ef3ef8..2a5b443610a 100644\n--- a/Documentation/git-rerere.adoc\n+++ b/Documentation/git-rerere.adoc\n@@ -56,8 +56,7 @@ conflicts in paths that match <pathspec>.\n \n Display diffs for the current state of the resolution.  It is\n useful for tracking what has changed while the user is resolving\n-conflicts.  Additional arguments are passed directly to the system\n-'diff' command installed in PATH.\n+conflicts.\n \n 'status'::\n \n\n-- \n2.56.1.831.g720f3f5937.dirty\n\n\n"},{"id":"558899","messageId":"xmqqwlq8tpbm.fsf@gitster.g","threadId":"66677","inReplyTo":"20261119-pks-rerere-subcommands-v5-11-0c1092b88958@pks.im","subject":"Re: [PATCH v5 11/13] builtin/rerere: use `OPT_SUBCOMMAND()`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T22:43:25Z","receivedAt":"2026-11-19T22:43:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In git-rerere(1) we have our own custom logic to parse subcommands. In\n> preceding commits we have refactored all of those subcommands so that\n> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use\n> these so that we get rid of our custom subcommand parsing.\n>\n> Unfortunately this means that we have a backwards-incompatible change\n> because we no longer accept the \"--[no-]rerere-autoupdate\" flag for all\n> subcommands. But this was arguably broken and misleading as we ignore\n> this flag for any other subcommand aynway. So we cheat a bit and simply\n> call it a bug that those flags were accepted in the first place.\n\nAynway.\n\n> +static int cmd_rerere_perform(int argc,\n> +\t\t\t      const char **argv,\n> +\t\t\t      const char *prefix,\n> +\t\t\t      struct repository *repo)\n> +{\n> +\tint autoupdate = -1;\n> +\tstruct option options[] = {\n> +\t\tOPT_SET_INT(0, \"rerere-autoupdate\", &autoupdate,\n> +\t\t\tN_(\"register clean resolutions in index\"), 1),\n> +\t\tOPT_END(),\n> +\t};\n> +\tenum rerere_flags flags = 0;\n\nThe \"register clean resolutions in index\" text used to be given for \"-h\"\n\n    $ rungit master rerere -h\n    usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]\n\n        --[no-]rerere-autoupdate\n                              register clean resolutions in index\n\nbut we moved it to this subcommand.\n\nIt was a bug that \"git rerere diff --no-rerere-autoupdate\" did not\ncomplain.  Because this option only appears here, those subcommands\nwould now complain when they see the --no-rerere-autoupdate option.\n\nWhich is very good.\n\nWhat is a bit sad is that it has become very hard to actually see\nthis help text.\n\n    $ rungit seen rerere -h\n    usage: git rerere [--[no-]rerere-autoupdate]\n       or: git rerere clear\n       or: git rerere diff\n       or: git rerere forget <pathspec>...\n       or: git rerere gc\n       or: git rerere remaining\n       or: git rerere status\n\nBecause the primary subcommand (i.e., record and replay after you\ngot a conflict in the working tree) does not have a subcommand verb,\n\"git rerere -h\" would trigger the help for the top-level command,\nand the help is shown from there without using the options[] array\nin this subcommand.\n\nI said \"very hard\", not impossible, because there is an awkward way\nto see this.\n\n    $ rungit seen rerere -- -h\n    $ rungit seen rerere --rerere-autoupdate -h\n\nBoth of which would give you\n\n    usage: git rerere [--[no-]rerere-autoupdate]\n\n        --[no-]rerere-autoupdate\n                              register clean resolutions in index\n\nbut it probably is not what users will ever use.\n\nI think it is OK to stop here and leave the above as-is.  The only\npeople who use this option are those who already know and are used\nto it.  Everybody else I would imagine would rather use\n\n\tgit -c rerere.autoupdate=no rerere\n\ninstead.\n\nIt might have fallouts on --git-completion-helper, too.\n\n    $ rungit master rerere --git-completion-helper\n    --rerere-autoupdate --no-rerere-autoupdate\n    $ rungit seen rerere --git-completion-helper\n    clear diff forget gc remaining status\n\nArguably, the updated choices are better, but I do not know offhand\nhow the bash completion script uses this (specifically, the old output\nwas so bad that it may have workaround that we will no longer need with\nyour improvements).\n\nThanks.\n\n\n"}]}