[PATCH v5 00/13] builtin/rerere: convert to use subcommands
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 19, 2026, 11:47 UTC
- Message-ID
- <20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im>
- In-Reply-To
- <20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im>
Hi,
while reviewing some patch series around git-rerere(1) recently I was a bit appalled by our custom subcommand parsing that we do here. This patch series here thus cleans up and modernizes that part a bit so that git-rerere(1) behaves like every other Git command that happens to have subcommands.
This series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with ps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global rerere cache state, 2026-10-23) merged into it.
Changes in v5:
- Explicitly docmuent the change in behaviour for the "--skip-lock"
flag.
- Add another patch to fix our documentation of `git rerere diff`,
which has been stale for the last two decades.
- Fix a regression where we didn't print the synopsis anymore when an
unknown subcommand is being passed.
- NULL-terminate argv.
- Link to v4: https://patch.msgid.link/20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.imChanges in v4:
- Some more polishing for `RERERE_{NO,}AUTOUPDATE` documentation.
- Die in case both of these flags are passed.
- Link to v3: https://patch.msgid.link/20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.imChanges in v3: - Clarify what `RERERE_NOAUTOUPDATE` does. - Link to v2: https://patch.msgid.link/20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im
Changes in v2: - Document rerere flags. - Rename `rerere_record()` to just `rerere()`. - Link to v1: https://patch.msgid.link/20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (13):
rerere: rename `repo_rerere()`
rerere: convert flags into an enum
builtin/rerere: drop `the_repository`
builtin/rerere: stop passing flags to subcommands that ignore them
builtin/rerere: turn "forget" into a proper subcommand
builtin/rerere: turn "clear" into a proper subcommand
builtin/rerere: turn "status" into a proper subcommand
builtin/rerere: turn "remaining" into a proper subcommand
builtin/rerere: turn "diff" into a proper subcommand
builtin/rerere: turn "gc" into a proper subcommand
builtin/rerere: use `OPT_SUBCOMMAND()`
builtin/rerere: introduce proper usage strings for subcommands
Documentation/git-rerere: drop claim that we pass args to diff(1)Documentation/git-rerere.adoc | 11 +- apply.c | 2 +- builtin/am.c | 4 +- builtin/commit.c | 2 +- builtin/merge.c | 2 +- builtin/rerere.c | 328 ++++++++++++++++++++++++++++++++---------- builtin/stash.c | 2 +- rerere.c | 14 +- rerere.h | 43 ++++-- sequencer.c | 4 +- t/t4200-rerere.sh | 5 - 11 files changed, 309 insertions(+), 108 deletions(-)
Range-diff versus v4:
1: 0bb466edb5e = 1: 1587a58d92c rerere: rename `repo_rerere()`
2: cc7e58429b2 ! 2: 9ae3253dda0 rerere: convert flags into an enum
@@ rerere.h: struct rerere_id {
+ RERERE_AUTOUPDATE = (1 << 0),
+
+ /*
-+ * update the file in the working tree but don't touch the index. This
++ * Update the file in the working tree but don't touch the index. This
+ * can be used to explicitly override "rerere.autoUpdate".
+ *
+ * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is
3: 85299db3099 = 3: e87e54d9b8a builtin/rerere: drop `the_repository`
4: 2f41c69859d = 4: 59ff81ab701 builtin/rerere: stop passing flags to subcommands that ignore them
5: 461e1c0848f = 5: 214ba91b19a builtin/rerere: turn "forget" into a proper subcommand
6: 09bc2e4b0da = 6: e8f7fe874e7 builtin/rerere: turn "clear" into a proper subcommand
7: 6d058b1cef3 = 7: e63f6f77887 builtin/rerere: turn "status" into a proper subcommand
8: cfa7939b6b0 = 8: 893cd386a4c builtin/rerere: turn "remaining" into a proper subcommand
9: 13f60ac35aa = 9: b7ff0206cac builtin/rerere: turn "diff" into a proper subcommand
10: f33edb14768 ! 10: c40013dcbef builtin/rerere: turn "gc" into a proper subcommand
@@ Commit message
proper subcommands as supported by our parse-options subsystem. Refactor
the "gc" subcommand to use parse-options as a preparatory step.
+ Note that this results in an intentional change in behaviour, as we
+ previously accepted the "--skip-lock" flag both before the subcommand
+ and after the subcommand name, whereas after this change we only allow
+ it after the subcommand name. But that flag has only recently been
+ introduced via 5f6b6aa3ab4 (rerere: add "gc --skip-locked" for auto
+ maintenance, 2026-10-13), which is not yet part of any release, so it's
+ unlikely that anybody will complain about this change.
+
Signed-off-by: Patrick Steinhardt <ps@pks.im>
## builtin/rerere.c ##
11: bb81a6d1d53 ! 11: be17f9cc9a8 builtin/rerere: use `OPT_SUBCOMMAND()`
@@ builtin/rerere.c: int cmd_rerere(int argc,
- flags = RERERE_AUTOUPDATE;
- if (autoupdate == 0)
- flags = RERERE_NOAUTOUPDATE;
-+ if (!fn) {
-+ struct strvec args = STRVEC_INIT;
-+ const char **args_copy;
-+ int ret;
-
+-
- if (argc < 1)
- return rerere(repo, flags);
-
@@ builtin/rerere.c: int cmd_rerere(int argc,
- return cmd_rerere_diff(argc, argv, prefix, repo);
- else
- usage_with_options(rerere_usage, options);
++ if (!fn) {
++ struct strvec args = STRVEC_INIT;
++ const char **args_copy;
++ int ret;
++
++ /*
++ * The user may have either passed options for `git rerere`
++ * itself or they may have mistyped the subcommand name. We try
++ * to distinguish these two cases by checking whether argv[0]
++ * is a flag or not.
++ */
++ if (argc && !starts_with(argv[0], "-"))
++ usage_with_options(rerere_usage, options);
++
+ strvec_push(&args, "perform");
+ strvec_pushv(&args, argv);
-
-- return 0;
++
+ /*
+ * We need to copy the array as it will be modified by
+ * `parse_options()`, and if so we leak the strings
+ * referenced by `args`.
+ */
-+ CALLOC_ARRAY(args_copy, args.nr);
++ CALLOC_ARRAY(args_copy, args.nr + 1);
+ COPY_ARRAY(args_copy, args.v, args.nr);
+
+ ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
@@ builtin/rerere.c: int cmd_rerere(int argc,
+ free(args_copy);
+ return ret;
+ }
-+
+
+- return 0;
+ return fn(argc, argv, prefix, repo);
}
12: d9f0b174247 = 12: 7b85011eeeb builtin/rerere: introduce proper usage strings for subcommands
-: ----------- > 13: ce0b34c4aee Documentation/git-rerere: drop claim that we pass args to diff(1)--- base-commit: 710910c03a22ac663885049213b9fef5853ea8e0 change-id: 20261027-pks-rerere-subcommands-318d41553438