threads / patch / 66677

patch, 12 partsbuiltin/rerere: convert to use subcommands

Subject: [PATCH 00/12] builtin/rerere: convert to use subcommands

## tl;dr

Junio Hamano asks whether moving git rerere to standard subcommand parsing silently breaks scripts that put options before the subcommand. Read the story.

replies: 107people: 6as markdown or json

Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · lore
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.

Thanks!
Patrick
---
Patrick Steinhardt (12):
      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.adoc |   8 +-
 apply.c                       |   2 +-
 builtin/am.c                  |   4 +-
 builtin/commit.c              |   2 +-
 builtin/merge.c               |   2 +-
 builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------
 builtin/stash.c               |   2 +-
 rerere.c                      |   7 +-
 rerere.h                      |  21 +--
 sequencer.c                   |   4 +-
 t/t4200-rerere.sh             |   5 -
 11 files changed, 275 insertions(+), 101 deletions(-)

--- base-commit: 710910c03a22ac663885049213b9fef5853ea8e0 change-id: 20261027-pks-rerere-subcommands-318d41553438

Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 01/12] rerere: rename `repo_rerere()`

The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix.

Rename the function to `rerere_record()` to be consistent with all the other functions.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 apply.c          | 2 +-
 builtin/am.c     | 4 ++--
 builtin/commit.c | 2 +-
 builtin/merge.c  | 2 +-
 builtin/rerere.c | 2 +-
 builtin/stash.c  | 2 +-
 rerere.c         | 2 +-
 rerere.h         | 2 +-
 sequencer.c      | 4 ++--
 9 files changed, 11 insertions(+), 11 deletions(-)
Show changes to 9 files +11 −11

apply.c, builtin/am.c, builtin/commit.c, builtin/merge.c, builtin/rerere.c, builtin/stash.c, rerere.c, rerere.h, sequencer.c

diff --git a/apply.c b/apply.c
index a0b7119c639..d0b100ca065 100644
--- a/apply.c
+++ b/apply.c
@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		 * tree with conflict markers, but that isn't written with --cached.
 		 */
 		if (!state->cached)
-			repo_rerere(state->repo, 0);
+			rerere_record(state->repo, 0);
 	}
 
 	return errs;
diff --git a/builtin/am.c b/builtin/am.c
index e9623b83077..1d156cf877c 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		o.verbosity = 0;
 
 	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-		repo_rerere(the_repository, state->allow_rerere_autoupdate);
+		rerere_record(the_repository, state->allow_rerere_autoupdate);
 		free(their_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
 			goto next;
 	}
 
-	repo_rerere(the_repository, 0);
+	rerere_record(the_repository, 0);
 
 	do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8ffd42681bb..c472e8f6638 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,
 
 	git_test_write_commit_graph_or_die(the_repository);
 
-	repo_rerere(the_repository, 0);
+	rerere_record(the_repository, 0);
 	run_auto_maintenance(the_repository, quiet);
 	run_commit_hook(use_editor, repo_get_index_file(the_repository),
 			NULL, "post-commit", NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index d7bf209114f..aaf15fdd69d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
-	repo_rerere(the_repository, allow_rerere_auto);
+	rerere_record(the_repository, allow_rerere_auto);
 	printf(_("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n"));
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2c17f02f56d..1717fb7a65d 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -83,7 +83,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return repo_rerere(the_repository, flags);
+		return rerere_record(the_repository, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
diff --git a/builtin/stash.c b/builtin/stash.c
index e1a3a76bd04..1b9c7f0eb6b 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
 		ret = error(_("could not write index"));
 
 	if (ret) {
-		repo_rerere(the_repository, 0);
+		rerere_record(the_repository, 0);
 
 		if (index)
 			fprintf_ln(stderr, _("Index was not unstashed."));
diff --git a/rerere.c b/rerere.c
index e0897612085..fd1c1ed6015 100644
--- a/rerere.c
+++ b/rerere.c
@@ -956,7 +956,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
  * perform mergy operations, possibly leaving conflicted index entries
  * and working tree files.
  */
-int repo_rerere(struct repository *r, int flags)
+int rerere_record(struct repository *r, int flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
diff --git a/rerere.h b/rerere.h
index d3cbd10e13f..a19d2407b59 100644
--- a/rerere.h
+++ b/rerere.h
@@ -45,7 +45,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 		       int flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int repo_rerere(struct repository *, int);
+int rerere_record(struct repository *, int);
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
diff --git a/sequencer.c b/sequencer.c
index 508ec717920..58e58503794 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,
 		      : _("could not apply %s... %s"),
 		      short_commit_name(r, commit), msg.subject);
 		print_advice(r, res == 1, opts);
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere_record(r, opts->allow_rerere_auto);
 		goto leave;
 	}
 
@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,
 
 	rollback_lock_file(&lock);
 	if (ret)
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere_record(r, opts->allow_rerere_auto);
 	else
 		/*
 		 * In case of problems, we now want to return a positive
-- 
2.56.0.341.g393f52fd96.dirty
Junio C Hamano· Oct 27, 2026, 19:48 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 01/12] rerere: rename `repo_rerere()`

Patrick Steinhardt <ps@pks.im> writes:
Show 7 quoted lines
> The `repo_rerere()` function is the only function in "rerere.h" that
> does not have a `rerere_` prefix. And while it does indeed receive a
> repository as first parameter, that's not a good-enough reason to give
> it a `repo_` prefix.
>
> Rename the function to `rerere_record()` to be consistent with all the
> other functions.

I do not think the convention to give "repo_" prefix to variants of functions that worked only on the_repository should stay with us forever, and losing repo prefix from this function would be an excellent first move towards that future.

I howevr take isseus with the verb "record" in its new name. What the function does is not just record. It autonomously finds out what situation it is in and does the logical next thing, which varies. It resolves when a recorded resolution exist. it records when seeing a particular conflict for the first time. There was no single good verb to express that. Perhaps "to rerere" or "to perform rerere" can be invented as a verb to describe such an intelligent operation?

Patrick Steinhardt· Oct 28, 2026, 08:33 UTC · re: Junio C Hamano · lore

Re: [PATCH 01/12] rerere: rename `repo_rerere()`

On Tue, Oct 27, 2026 at 12:48:36PM -0700, Junio C Hamano wrote:
Show 23 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > The `repo_rerere()` function is the only function in "rerere.h" that
> > does not have a `rerere_` prefix. And while it does indeed receive a
> > repository as first parameter, that's not a good-enough reason to give
> > it a `repo_` prefix.
> >
> > Rename the function to `rerere_record()` to be consistent with all the
> > other functions.
> 
> I do not think the convention to give "repo_" prefix to variants of
> functions that worked only on the_repository should stay with us
> forever, and losing repo prefix from this function would be an
> excellent first move towards that future.
> 
> I howevr take isseus with the verb "record" in its new name.  What
> the function does is not just record.  It autonomously finds out
> what situation it is in and does the logical next thing, which
> varies.  It resolves when a recorded resolution exist.  it records
> when seeing a particular conflict for the first time.  There was no
> single good verb to express that.  Perhaps "to rerere" or "to
> perform rerere" can be invented as a verb to describe such an
> intelligent operation?
I was picking "record" because that's also what git-rerere(1) says:
  This command assists the developer in this process by recording
  conflicted automerge results and corresponding hand resolve results on
  the initial manual merge, and applying previously recorded hand
  resolutions to their corresponding automerge results.

But I guess your point is valid, as we don't only do that, but also update merge conflicts locally. I'd pick your "perform" proposal in that case and rename it to `rerere_perform()` instead. That name is somewhat vague, but I guess that cannot be helped because it actually does a bunch of things at once.

I guess that can be helped with documentation though.
Patrick
Junio C Hamano· Oct 28, 2026, 16:25 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 01/12] rerere: rename `repo_rerere()`

Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
> I was picking "record" because that's also what git-rerere(1) says:
>
>   This command assists the developer in this process by recording
>   conflicted automerge results and corresponding hand resolve results on
>   the initial manual merge, and applying previously recorded hand
>   resolutions to their corresponding automerge results.
>
> But I guess your point is valid, as we don't only do that, but also
> update merge conflicts locally. I'd pick your "perform" proposal in that
Yup, the description above says "recording" and "applying".
> case and rename it to `rerere_perform()` instead. That name is somewhat
> vague, but I guess that cannot be helped because it actually does a
> bunch of things at once.
Let's just call it rerere(), then.

It was the original name for the operation before it was renamed in 35843b1123 (rerere.c: remove implicit dependency on the_index, 2018-09-21), which taught it to take an instance of a repository structure.

Going back to that original name is in line with what I said earlier. The "repo_" prefix is a mistaken trend, and once everything becomes free from the_repository, it would become redundant and unnecessary.

Thanks.
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 02/12] rerere: convert flags into an enum

Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 rerere.c |  7 ++++---
 rerere.h | 21 ++++++++++++---------
 2 files changed, 16 insertions(+), 12 deletions(-)
Show changes to 2 files +16 −12

rerere.c, rerere.h

diff --git a/rerere.c b/rerere.c
index fd1c1ed6015..1ae7983445a 100644
--- a/rerere.c
+++ b/rerere.c
@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags)
+		       enum rerere_flags flags)
 {
 	int lock_timeout_ms = 1000;
 	int fd;
@@ -956,7 +956,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
  * perform mergy operations, possibly leaving conflicted index entries
  * and working tree files.
  */
-int rerere_record(struct repository *r, int flags)
+int rerere_record(struct repository *r, enum rerere_flags flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
@@ -1341,7 +1341,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr, int flags)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_flags flags)
 {
 	struct rerere_cache cache;
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
diff --git a/rerere.h b/rerere.h
index a19d2407b59..362b348af25 100644
--- a/rerere.h
+++ b/rerere.h
@@ -9,12 +9,6 @@
 struct pathspec;
 struct repository;
 
-#define RERERE_AUTOUPDATE   01
-#define RERERE_NOAUTOUPDATE 02
-#define RERERE_READONLY     04
-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
-#define RERERE_NOWAIT       010
-
 /*
  * Marks paths that have been hand-resolved and added to the
  * index. Set in the util field of such paths after calling
@@ -39,13 +33,21 @@ struct rerere_id {
 	int variant;
 };
 
+enum rerere_flags {
+	RERERE_AUTOUPDATE = (1 << 0),
+	RERERE_NOAUTOUPDATE = (1 << 1),
+	RERERE_READONLY = (1 << 2),
+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
+	RERERE_NOWAIT = (1 << 3),
+};
+
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags);
+		       enum rerere_flags flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int rerere_record(struct repository *, int);
+int rerere_record(struct repository *r, enum rerere_flags flags);
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
@@ -58,7 +60,8 @@ const char *rerere_path(struct repository *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *, int);
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
-- 
2.56.0.341.g393f52fd96.dirty
Mark C. Chu-Carroll· Oct 27, 2026, 14:47 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 02/12] rerere: convert flags into an enum

On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:
Show 12 quoted lines
> Our modern coding guidelines say that flags should typically be passed
> around as enums so that it becomes trivial to see what kind of flags are
> expected. Adapt the rerere flags accordingly.
> 
>   <snip>
> +enum rerere_flags {
> +	RERERE_AUTOUPDATE = (1 << 0),
> +	RERERE_NOAUTOUPDATE = (1 << 1),
> +	RERERE_READONLY = (1 << 2),
> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
> +	RERERE_NOWAIT = (1 << 3),
> +};

If we're moving to using enum flags, then wouldn't it be better to explicitly add a "RERE_MERGE_LOCK_TOKEN" to the enum for that case, rather than have this value only documented by a comment?

  -Mark
Junio C Hamano· Oct 27, 2026, 19:40 UTC · re: Mark C. Chu-Carroll · lore

Re: [PATCH 02/12] rerere: convert flags into an enum

"Mark C. Chu-Carroll" <markchucarroll@fastmail.com> writes:
Show 17 quoted lines
> On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:
>> Our modern coding guidelines say that flags should typically be passed
>> around as enums so that it becomes trivial to see what kind of flags are
>> expected. Adapt the rerere flags accordingly.
>> 
>>   <snip>
>> +enum rerere_flags {
>> +	RERERE_AUTOUPDATE = (1 << 0),
>> +	RERERE_NOAUTOUPDATE = (1 << 1),
>> +	RERERE_READONLY = (1 << 2),
>> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
>> +	RERERE_NOWAIT = (1 << 3),
>> +};
>
> If we're moving to using enum flags, then wouldn't it be better to
> explicitly add a "RERE_MERGE_LOCK_TOKEN" to the enum for that case, 
> rather than have this value only documented by a comment?

Perhaps you misunderstand what the comment says. It is an explanation for the next line, i.e., it tells the API users "If you want the 'immediate failure when locked' behaviour, pass the _NOWAIT bit".

Patrick Steinhardt· Oct 28, 2026, 08:33 UTC · re: Junio C Hamano · lore

Re: [PATCH 02/12] rerere: convert flags into an enum

On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:
Show 24 quoted lines
> "Mark C. Chu-Carroll" <markchucarroll@fastmail.com> writes:
> 
> > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:
> >> Our modern coding guidelines say that flags should typically be passed
> >> around as enums so that it becomes trivial to see what kind of flags are
> >> expected. Adapt the rerere flags accordingly.
> >> 
> >>   <snip>
> >> +enum rerere_flags {
> >> +	RERERE_AUTOUPDATE = (1 << 0),
> >> +	RERERE_NOAUTOUPDATE = (1 << 1),
> >> +	RERERE_READONLY = (1 << 2),
> >> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
> >> +	RERERE_NOWAIT = (1 << 3),
> >> +};
> >
> > If we're moving to using enum flags, then wouldn't it be better to
> > explicitly add a "RERE_MERGE_LOCK_TOKEN" to the enum for that case, 
> > rather than have this value only documented by a comment?
> 
> Perhaps you misunderstand what the comment says.  It is an
> explanation for the next line, i.e., it tells the API users "If you
> want the 'immediate failure when locked' behaviour, pass the _NOWAIT
> bit".

Yeah, this. I guess we can help that though by documenting all of the flags while at it.

Patrick
Mark C. Chu-Carroll· Oct 28, 2026, 14:11 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 02/12] rerere: convert flags into an enum

On Wed, 28 Oct 2026 09:33:25 +0100, Patrick Steinhardt <ps@pks.im> wrote:
Show 28 quoted lines
> On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:
> > "Mark C. Chu-Carroll" <markchucarroll@fastmail.com> writes:
> > 
> > > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:
> > >> Our modern coding guidelines say that flags should typically be passed
> > >> around as enums so that it becomes trivial to see what kind of flags are
> > >> expected. Adapt the rerere flags accordingly.
> > >> 
> > >>   <snip>
> > >> +enum rerere_flags {
> > >> +	RERERE_AUTOUPDATE = (1 << 0),
> > >> +	RERERE_NOAUTOUPDATE = (1 << 1),
> > >> +	RERERE_READONLY = (1 << 2),
> > >> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
> > >> +	RERERE_NOWAIT = (1 << 3),
> > >> +};
> > >
> > > If we're moving to using enum flags, then wouldn't it be better to
> > > explicitly add a "RERE_MERGE_LOCK_TOKEN" to the enum for that case, 
> > > rather than have this value only documented by a comment?
> > 
> > Perhaps you misunderstand what the comment says.  It is an
> > explanation for the next line, i.e., it tells the API users "If you
> > want the 'immediate failure when locked' behaviour, pass the _NOWAIT
> > bit".
> 
> Yeah, this. I guess we can help that though by documenting all of the
> flags while at it.

Ah, yeah. I misunderstood that. Obvious in retrospect, but I was puzzling over that for a while.

    -Mark
Junio C Hamano· Oct 28, 2026, 16:25 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 02/12] rerere: convert flags into an enum

Patrick Steinhardt <ps@pks.im> writes:
Show 28 quoted lines
> On Tue, Oct 27, 2026 at 12:40:45PM -0700, Junio C Hamano wrote:
>> "Mark C. Chu-Carroll" <markchucarroll@fastmail.com> writes:
>> 
>> > On Tue, 27 Oct 2026 11:46:45 +0100, Patrick Steinhardt <ps@pks.im> wrote:
>> >> Our modern coding guidelines say that flags should typically be passed
>> >> around as enums so that it becomes trivial to see what kind of flags are
>> >> expected. Adapt the rerere flags accordingly.
>> >> 
>> >>   <snip>
>> >> +enum rerere_flags {
>> >> +	RERERE_AUTOUPDATE = (1 << 0),
>> >> +	RERERE_NOAUTOUPDATE = (1 << 1),
>> >> +	RERERE_READONLY = (1 << 2),
>> >> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
>> >> +	RERERE_NOWAIT = (1 << 3),
>> >> +};
>> >
>> > If we're moving to using enum flags, then wouldn't it be better to
>> > explicitly add a "RERE_MERGE_LOCK_TOKEN" to the enum for that case, 
>> > rather than have this value only documented by a comment?
>> 
>> Perhaps you misunderstand what the comment says.  It is an
>> explanation for the next line, i.e., it tells the API users "If you
>> want the 'immediate failure when locked' behaviour, pass the _NOWAIT
>> bit".
>
> Yeah, this. I guess we can help that though by documenting all of the
> flags while at it.
Great.
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 03/12] builtin/rerere: drop `the_repository`

There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Show changes to builtin/rerere.c +11 −13
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1717fb7a65d..556f267f37d 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int autoupdate = -1, skip_locked = 0, flags = 0;
@@ -75,7 +73,7 @@ int cmd_rerere(int argc,
 	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
 		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
 
-	repo_config(the_repository, git_xmerge_config, NULL);
+	repo_config(repo, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
 		flags = RERERE_AUTOUPDATE;
@@ -83,7 +81,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return rerere_record(the_repository, flags);
+		return rerere_record(repo, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
@@ -94,21 +92,21 @@ int cmd_rerere(int argc,
 		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
 			       prefix, argv + 1);
 
-		ret = rerere_forget(the_repository, &pathspec);
+		ret = rerere_forget(repo, &pathspec);
 
 		clear_pathspec(&pathspec);
 		return ret;
 	}
 
 	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(the_repository, &merge_rr);
+		rerere_clear(repo, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr,
+		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				       flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
@@ -116,7 +114,7 @@ int cmd_rerere(int argc,
 
 		rerere_cache_release(&cache);
 	} else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(the_repository, &merge_rr);
+		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
 				printf("%s\n", merge_rr.items[i].string);
@@ -129,16 +127,16 @@ int cmd_rerere(int argc,
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				      flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
 			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
+			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
 				     path, path, path))
 				die(_("unable to generate diff for '%s'"),
-				    rerere_path(the_repository, &buf, id, NULL));
+				    rerere_path(repo, &buf, id, NULL));
 		}
 
 		rerere_cache_release(&cache);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 04/12] builtin/rerere: stop passing flags to subcommands that ignore them

The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`.

This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/rerere.c +2 −2
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 556f267f37d..d65870779f3 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -107,7 +107,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
 			printf("%s\n", merge_rr.items[i].string);
@@ -128,7 +128,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				      flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 05/12] builtin/rerere: turn "forget" into a proper subcommand

The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work:

  - Options from other subcommands apply to each other.
  - We don't have proper usage strings.
  - Running `git rerere <subcmd> -h` doesn't print the options that are
    supported by that subcommand, but instead it just prints the help of
    git-rerere(1) itself.

A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Show changes to builtin/rerere.c +24 −14
diff --git a/builtin/rerere.c b/builtin/rerere.c
index d65870779f3..0f55619bf62 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_forget(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct pathspec pathspec;
+	int ret;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (!argc)
+		warning(_("'git rerere forget' without paths is deprecated"));
+	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+
+	ret = rerere_forget(repo, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -83,20 +105,8 @@ int cmd_rerere(int argc,
 	if (argc < 1)
 		return rerere_record(repo, flags);
 
-	if (!strcmp(argv[0], "forget")) {
-		struct pathspec pathspec;
-		int ret;
-
-		if (argc < 2)
-			warning(_("'git rerere forget' without paths is deprecated"));
-		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
-			       prefix, argv + 1);
-
-		ret = rerere_forget(repo, &pathspec);
-
-		clear_pathspec(&pathspec);
-		return ret;
-	}
+	if (!strcmp(argv[0], "forget"))
+		return cmd_rerere_forget(argc, argv, prefix, repo);
 
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(repo, &merge_rr);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 06/12] builtin/rerere: turn "clear" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Show changes to builtin/rerere.c +22 −3
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 0f55619bf62..96e98bc411c 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_clear(int argc,
+			    const char **argv,
+			    const char *prefix,
+			    struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_clear(repo, &merge_rr);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -107,9 +127,8 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-
-	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(repo, &merge_rr);
+	else if (!strcmp(argv[0], "clear")) {
+		return cmd_rerere_clear(argc, argv, prefix, repo);
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 07/12] builtin/rerere: turn "status" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +29 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 96e98bc411c..e2955fea20e 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_status(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+	for (size_t i = 0; i < merge_rr.nr; i++)
+		printf("%s\n", merge_rr.items[i].string);
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	return 0;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -132,17 +158,9 @@ int cmd_rerere(int argc,
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-	else if (!strcmp(argv[0], "status")) {
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++)
-			printf("%s\n", merge_rr.items[i].string);
-
-		rerere_cache_release(&cache);
-	} else if (!strcmp(argv[0], "remaining")) {
+	else if (!strcmp(argv[0], "status"))
+		return cmd_rerere_status(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "remaining")) {
 		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 08/12] builtin/rerere: turn "remaining" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +31 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index e2955fea20e..31c1b37540e 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_remaining(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_remaining(repo, &merge_rr);
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		if (merge_rr.items[i].util != RERERE_RESOLVED)
+			printf("%s\n", merge_rr.items[i].string);
+		else
+			/* prepare for later call to
+			 * string_list_clear() */
+			merge_rr.items[i].util = NULL;
+	}
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_status(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -160,17 +188,9 @@ int cmd_rerere(int argc,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(repo, &merge_rr);
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			if (merge_rr.items[i].util != RERERE_RESOLVED)
-				printf("%s\n", merge_rr.items[i].string);
-			else
-				/* prepare for later call to
-				 * string_list_clear() */
-				merge_rr.items[i].util = NULL;
-		}
-	} else if (!strcmp(argv[0], "diff")) {
+	else if (!strcmp(argv[0], "remaining"))
+		return cmd_rerere_remaining(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "diff")) {
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 09/12] builtin/rerere: turn "diff" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
Show changes to builtin/rerere.c +37 −19
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 31c1b37540e..87ee4eddd0a 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,
 	return 0;
 }
 
+static int cmd_rerere_diff(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct strbuf buf = STRBUF_INIT;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		const char *path = merge_rr.items[i].string;
+		const struct rerere_id *id = merge_rr.items[i].util;
+		if (diff_two(rerere_path(repo, &buf, id, "preimage"), path, path, path))
+			die(_("unable to generate diff for '%s'"),
+			    rerere_path(repo, &buf, id, NULL));
+	}
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	strbuf_release(&buf);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -190,25 +224,9 @@ int cmd_rerere(int argc,
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
 		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff")) {
-		struct strbuf buf = STRBUF_INIT;
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			const char *path = merge_rr.items[i].string;
-			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
-				     path, path, path))
-				die(_("unable to generate diff for '%s'"),
-				    rerere_path(repo, &buf, id, NULL));
-		}
-
-		rerere_cache_release(&cache);
-		strbuf_release(&buf);
-	} else
+	else if (!strcmp(argv[0], "diff"))
+		return cmd_rerere_diff(argc, argv, prefix, repo);
+	else
 		usage_with_options(rerere_usage, options);
 
 	string_list_clear(&merge_rr, 1);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 10/12] builtin/rerere: turn "gc" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
 t/t4200-rerere.sh |  5 -----
 2 files changed, 30 insertions(+), 18 deletions(-)
Show changes to 2 files +30 −18

builtin/rerere.c, t/t4200-rerere.sh

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 87ee4eddd0a..67626e13845 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_gc(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo)
+{
+	int skip_locked = 0;
+	struct option options[] = {
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+				N_("skip gc while another process holds the lock")),
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_gc(repo, &merge_rr,
+		  skip_locked ? RERERE_NOWAIT : 0);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -187,21 +211,16 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, skip_locked = 0, flags = 0;
+	int autoupdate = -1, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
-		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
-			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
-
-	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
-		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+	argc = parse_options(argc, argv, prefix, options, rerere_usage,
+			     PARSE_OPT_KEEP_UNKNOWN_OPT);
 
 	repo_config(repo, git_xmerge_config, NULL);
 
@@ -215,11 +234,10 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear")) {
+	else if (!strcmp(argv[0], "clear"))
 		return cmd_rerere_clear(argc, argv, prefix, repo);
-	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(repo, &merge_rr,
-			  skip_locked ? RERERE_NOWAIT : 0);
+	else if (!strcmp(argv[0], "gc"))
+		return cmd_rerere_gc(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
@@ -229,6 +247,5 @@ int cmd_rerere(int argc,
 	else
 		usage_with_options(rerere_usage, options);
 
-	string_list_clear(&merge_rr, 1);
 	return 0;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ab412ecc6e8..0d4cbf5114a 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
 	test_path_is_missing $rr2/preimage
 '
 
-test_expect_success '--skip-locked is only accepted by gc' '
-	test_must_fail git rerere --skip-locked clear 2>err &&
-	test_grep "option .--skip-locked. requires .gc." err
-'
-
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

In git-rerere(1) we have our own custom logic to parse subcommands. In preceding commits we have refactored all of those subcommands so that they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use these so that we get rid of our custom subcommand parsing.

Unfortunately this means that we have a backwards-incompatible change because we no longer accept the "--[no-]rerere-autoupdate" flag for all subcommands. But this was arguably broken and misleading as we ignore this flag for any other subcommand aynway. So we cheat a bit and simply call it a bug that those flags were accepted in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 28 deletions(-)
Show changes to builtin/rerere.c +56 −28
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 67626e13845..80ecca1fe0d 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -5,6 +5,7 @@
 #include "rerere.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "strvec.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
 	return 0;
 }
 
+static int cmd_rerere_record(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	int autoupdate = -1;
+	struct option options[] = {
+		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+			N_("register clean resolutions in index"), 1),
+		OPT_END(),
+	};
+	enum rerere_flags flags = 0;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (autoupdate == 1)
+		flags = RERERE_AUTOUPDATE;
+	if (autoupdate == 0)
+		flags = RERERE_NOAUTOUPDATE;
+
+	return rerere_record(repo, flags);
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -211,41 +237,43 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	int autoupdate = -1, flags = 0;
-
+	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
-			N_("register clean resolutions in index"), 1),
+		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
+		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
+		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
+		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
+		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
+		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
-			     PARSE_OPT_KEEP_UNKNOWN_OPT);
-
+			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
 	repo_config(repo, git_xmerge_config, NULL);
 
-	if (autoupdate == 1)
-		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_record(repo, flags);
-
-	if (!strcmp(argv[0], "forget"))
-		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear"))
-		return cmd_rerere_clear(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "gc"))
-		return cmd_rerere_gc(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "status"))
-		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining"))
-		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff"))
-		return cmd_rerere_diff(argc, argv, prefix, repo);
-	else
-		usage_with_options(rerere_usage, options);
+		strvec_push(&args, "record");
+		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);
+		COPY_ARRAY(args_copy, args.v, args.nr);
+
+		ret = cmd_rerere_record(args.nr, args_copy, prefix, repo);
+
+		strvec_clear(&args);
+		free(args_copy);
+		return ret;
+	}
+
+	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 27, 2026, 10:46 UTC · re: Patrick Steinhardt · lore

[PATCH 12/12] builtin/rerere: introduce proper usage strings for subcommands

Adapt git-rerere(1) to have proper usage strings for each of the subcommands.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc |  8 +++++-
 builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 11 deletions(-)
Show changes to 2 files +58 −11

Documentation/git-rerere.adoc, builtin/rerere.c

diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index 4e6ab9a27c9..e04e9ef3ef8 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
 SYNOPSIS
 --------
 [verse]
-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
+'git rerere' [--[no-]rerere-autoupdate]
+'git rerere' clear
+'git rerere' diff
+'git rerere' forget <pathspec>...
+'git rerere' gc
+'git rerere' remaining
+'git rerere' status
 
 DESCRIPTION
 -----------
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 80ecca1fe0d..97a08ecd6e7 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -10,10 +10,13 @@
 #include "xdiff-interface.h"
 #include "pathspec.h"
 
-static const char * const rerere_usage[] = {
-	N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
-	NULL,
-};
+#define RERERE_USAGE N_("git rerere [--[no-]rerere-autoupdate]")
+#define RERERE_CLEAR_USAGE N_("git rerere clear")
+#define RERERE_DIFF_USAGE N_("git rerere diff")
+#define RERERE_FORGET_USAGE N_("git rerere forget <pathspec>...")
+#define RERERE_GC_USAGE N_("git rerere gc")
+#define RERERE_REMAINING_USAGE N_("git rerere remaining")
+#define RERERE_STATUS_USAGE N_("git rerere status")
 
 static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)
 {
@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_clear_usage[] = {
+		RERERE_CLEAR_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_diff_usage[] = {
+		RERERE_DIFF_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_forget_usage[] = {
+		RERERE_FORGET_USAGE,
+		NULL,
+	};
 	struct pathspec pathspec;
 	int ret;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);
 	if (!argc)
 		warning(_("'git rerere forget' without paths is deprecated"));
 	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,
 				N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
+	const char * const rerere_gc_usage[] = {
+		RERERE_GC_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -164,6 +183,10 @@ static int cmd_rerere_record(int argc,
 			N_("register clean resolutions in index"), 1),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		NULL,
+	};
 	enum rerere_flags flags = 0;
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_remaining_usage[] = {
+		RERERE_REMAINING_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_status_usage[] = {
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -247,6 +278,16 @@ int cmd_rerere(int argc,
 		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		RERERE_CLEAR_USAGE,
+		RERERE_DIFF_USAGE,
+		RERERE_FORGET_USAGE,
+		RERERE_GC_USAGE,
+		RERERE_REMAINING_USAGE,
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
-- 
2.56.0.341.g393f52fd96.dirty
Junio C Hamano· Oct 27, 2026, 19:52 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 00/12] builtin/rerere: convert to use subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
> 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.

As the inventor of the mechanism, I took special interest in the topic, and overall found them well done. I wasn't even aware that we were so close to get rid of USE_THE_REPOSITORY_VARIABLE in builtin/rerere.c with such a small change (even though as I've said I do not think it is high priority to make cmd_foo() not rely on the_repository). Very nicely done.

Thanks.  
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 00/12] builtin/rerere: convert to use subcommands

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 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 (12):
      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.adoc |   8 +-
 apply.c                       |   2 +-
 builtin/am.c                  |   4 +-
 builtin/commit.c              |   2 +-
 builtin/merge.c               |   2 +-
 builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------
 builtin/stash.c               |   2 +-
 rerere.c                      |  12 +-
 rerere.h                      |  37 +++--
 sequencer.c                   |   4 +-
 t/t4200-rerere.sh             |   5 -
 11 files changed, 291 insertions(+), 106 deletions(-)
Range-diff versus v1:
 1:  ce75cde848d !  1:  1f3fbbad575 rerere: rename `repo_rerere()`
    @@ Commit message
         repository as first parameter, that's not a good-enough reason to give
         it a `repo_` prefix.
     
    -    Rename the function to `rerere_record()` to be consistent with all the
    -    other functions.
    +    Rename the function to just `rerere()`. Move around and extend
    +    documentation of this function to better explain what it does.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
    @@ apply.c: static int write_out_results(struct apply_state *state, struct patch *l
      		 */
      		if (!state->cached)
     -			repo_rerere(state->repo, 0);
    -+			rerere_record(state->repo, 0);
    ++			rerere(state->repo, 0);
      	}
      
      	return errs;
    @@ builtin/am.c: static int fall_back_threeway(const struct am_state *state, const
      
      	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
     -		repo_rerere(the_repository, state->allow_rerere_autoupdate);
    -+		rerere_record(the_repository, state->allow_rerere_autoupdate);
    ++		rerere(the_repository, state->allow_rerere_autoupdate);
      		free(their_tree_name);
      		return error(_("Failed to merge in the changes."));
      	}
    @@ builtin/am.c: static void am_resolve(struct am_state *state, int allow_empty)
      	}
      
     -	repo_rerere(the_repository, 0);
    -+	rerere_record(the_repository, 0);
    ++	rerere(the_repository, 0);
      
      	do_commit(state);
      
    @@ builtin/commit.c: int cmd_commit(int argc,
      	git_test_write_commit_graph_or_die(the_repository);
      
     -	repo_rerere(the_repository, 0);
    -+	rerere_record(the_repository, 0);
    ++	rerere(the_repository, 0);
      	run_auto_maintenance(the_repository, quiet);
      	run_commit_hook(use_editor, repo_get_index_file(the_repository),
      			NULL, "post-commit", NULL);
    @@ builtin/merge.c: static int suggest_conflicts(void)
      	strbuf_release(&msgbuf);
      	fclose(fp);
     -	repo_rerere(the_repository, allow_rerere_auto);
    -+	rerere_record(the_repository, allow_rerere_auto);
    ++	rerere(the_repository, allow_rerere_auto);
      	printf(_("Automatic merge failed; "
      			"fix conflicts and then commit the result.\n"));
      	return 1;
    @@ builtin/rerere.c: int cmd_rerere(int argc,
      
      	if (argc < 1)
     -		return repo_rerere(the_repository, flags);
    -+		return rerere_record(the_repository, flags);
    ++		return rerere(the_repository, flags);
      
      	if (!strcmp(argv[0], "forget")) {
      		struct pathspec pathspec;
    @@ builtin/stash.c: static enum stash_apply_result do_apply_stash(const char *prefi
      
      	if (ret) {
     -		repo_rerere(the_repository, 0);
    -+		rerere_record(the_repository, 0);
    ++		rerere(the_repository, 0);
      
      		if (index)
      			fprintf_ln(stderr, _("Index was not unstashed."));
     
      ## rerere.c ##
     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
    -  * perform mergy operations, possibly leaving conflicted index entries
    -  * and working tree files.
    -  */
    + 	return fd;
    + }
    + 
    +-/*
    +- * The main entry point that is called internally from codepaths that
    +- * perform mergy operations, possibly leaving conflicted index entries
    +- * and working tree files.
    +- */
     -int repo_rerere(struct repository *r, int flags)
    -+int rerere_record(struct repository *r, int flags)
    ++int rerere(struct repository *r, int flags)
      {
      	struct string_list merge_rr = STRING_LIST_INIT_DUP;
      	struct rerere_cache cache;
    @@ rerere.h: int rerere_cache_setup(struct rerere_cache *cache,
      void rerere_cache_release(struct rerere_cache *cache);
      
     -int repo_rerere(struct repository *, int);
    -+int rerere_record(struct repository *, int);
    ++/*
    ++ * The main entry point that is called internally from codepaths that
    ++ * perform mergy operations, possibly leaving conflicted index entries
    ++ * and working tree files. It records (and optionally updates) resolved
    ++ * conflicts and reuses recorded resolutions for unresolved conflicts.
    ++ */
    ++int rerere(struct repository *r, int flags);
    ++
      /*
       * Given the conflict ID and the name of a "file" used for replaying
       * the recorded resolution (e.g. "preimage", "postimage"), return the
    @@ sequencer.c: static enum pick_result do_pick_commit(struct repository *r,
      		      short_commit_name(r, commit), msg.subject);
      		print_advice(r, res == 1, opts);
     -		repo_rerere(r, opts->allow_rerere_auto);
    -+		rerere_record(r, opts->allow_rerere_auto);
    ++		rerere(r, opts->allow_rerere_auto);
      		goto leave;
      	}
      
    @@ sequencer.c: static int do_merge(struct repository *r,
      	rollback_lock_file(&lock);
      	if (ret)
     -		repo_rerere(r, opts->allow_rerere_auto);
    -+		rerere_record(r, opts->allow_rerere_auto);
    ++		rerere(r, opts->allow_rerere_auto);
      	else
      		/*
      		 * In case of problems, we now want to return a positive
 2:  18259e1556a !  2:  e910458a47c rerere: convert flags into an enum
    @@ Commit message
     
         Our modern coding guidelines say that flags should typically be passed
         around as enums so that it becomes trivial to see what kind of flags are
    -    expected. Adapt the rerere flags accordingly.
    +    expected. Adapt the rerere flags accordingly and document them.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
    @@ rerere.c: static int is_rerere_enabled(struct repository *r)
      	int lock_timeout_ms = 1000;
      	int fd;
     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
    -  * perform mergy operations, possibly leaving conflicted index entries
    -  * and working tree files.
    -  */
    --int rerere_record(struct repository *r, int flags)
    -+int rerere_record(struct repository *r, enum rerere_flags flags)
    + 	return fd;
    + }
    + 
    +-int rerere(struct repository *r, int flags)
    ++int rerere(struct repository *r, enum rerere_flags flags)
      {
      	struct string_list merge_rr = STRING_LIST_INIT_DUP;
      	struct rerere_cache cache;
    @@ rerere.h: struct rerere_id {
      };
      
     +enum rerere_flags {
    ++	/*
    ++	 * Auto-update the index with previously recorded resolutions. This can
    ++	 * be used to explicitly override "rerere.autoUpdate".
    ++	 */
     +	RERERE_AUTOUPDATE = (1 << 0),
    ++
    ++	/* Reverse of RERERE_AUTOUPDATE. */
     +	RERERE_NOAUTOUPDATE = (1 << 1),
    ++
    ++	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
     +	RERERE_READONLY = (1 << 2),
    -+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
    ++
    ++	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
     +	RERERE_NOWAIT = (1 << 3),
     +};
     +
    @@ rerere.h: struct rerere_id {
     +		       enum rerere_flags flags);
      void rerere_cache_release(struct rerere_cache *cache);
      
    --int rerere_record(struct repository *, int);
    -+int rerere_record(struct repository *r, enum rerere_flags flags);
    + /*
    +@@ rerere.h: void rerere_cache_release(struct rerere_cache *cache);
    +  * and working tree files. It records (and optionally updates) resolved
    +  * conflicts and reuses recorded resolutions for unresolved conflicts.
    +  */
    +-int rerere(struct repository *r, int flags);
    ++int rerere(struct repository *r, enum rerere_flags flags);
    + 
      /*
       * Given the conflict ID and the name of a "file" used for replaying
    -  * the recorded resolution (e.g. "preimage", "postimage"), return the
     @@ rerere.h: const char *rerere_path(struct repository *,
      int rerere_forget(struct repository *, struct pathspec *);
      int rerere_remaining(struct repository *, struct string_list *);
 3:  89ae664d90d !  3:  5254d1ac3ba builtin/rerere: drop `the_repository`
    @@ builtin/rerere.c: int cmd_rerere(int argc,
      		flags = RERERE_NOAUTOUPDATE;
      
      	if (argc < 1)
    --		return rerere_record(the_repository, flags);
    -+		return rerere_record(repo, flags);
    +-		return rerere(the_repository, flags);
    ++		return rerere(repo, flags);
      
      	if (!strcmp(argv[0], "forget")) {
      		struct pathspec pathspec;
 4:  5eff73de7bc =  4:  8b24e253e6b builtin/rerere: stop passing flags to subcommands that ignore them
 5:  621c5f6ab1b !  5:  43dde532e63 builtin/rerere: turn "forget" into a proper subcommand
    @@ builtin/rerere.c: static int diff_two(const char *file1, const char *label1,
      	       const char *prefix,
     @@ builtin/rerere.c: int cmd_rerere(int argc,
      	if (argc < 1)
    - 		return rerere_record(repo, flags);
    + 		return rerere(repo, flags);
      
     -	if (!strcmp(argv[0], "forget")) {
     -		struct pathspec pathspec;
 6:  d01fa02064c =  6:  13fd07a2f53 builtin/rerere: turn "clear" into a proper subcommand
 7:  2bebea6449e =  7:  c5d48081cc9 builtin/rerere: turn "status" into a proper subcommand
 8:  5594019f31f =  8:  5c6891f6a48 builtin/rerere: turn "remaining" into a proper subcommand
 9:  e8a2f8ce209 =  9:  b7ed9ef810b builtin/rerere: turn "diff" into a proper subcommand
10:  deebcee0379 = 10:  0ceff6d241b builtin/rerere: turn "gc" into a proper subcommand
11:  56037e9a761 ! 11:  3b8b4b65a53 builtin/rerere: use `OPT_SUBCOMMAND()`
    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,
      	return 0;
      }
      
    -+static int cmd_rerere_record(int argc,
    -+			     const char **argv,
    -+			     const char *prefix,
    -+			     struct repository *repo)
    ++static int cmd_rerere_perform(int argc,
    ++			      const char **argv,
    ++			      const char *prefix,
    ++			      struct repository *repo)
     +{
     +	int autoupdate = -1;
     +	struct option options[] = {
    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,
     +	if (autoupdate == 0)
     +		flags = RERERE_NOAUTOUPDATE;
     +
    -+	return rerere_record(repo, flags);
    ++	return rerere(repo, flags);
     +}
     +
      static int cmd_rerere_remaining(int argc,
    @@ builtin/rerere.c: int cmd_rerere(int argc,
     +		int ret;
      
     -	if (argc < 1)
    --		return rerere_record(repo, flags);
    +-		return rerere(repo, flags);
     -
     -	if (!strcmp(argv[0], "forget"))
     -		return cmd_rerere_forget(argc, argv, prefix, repo);
    @@ builtin/rerere.c: int cmd_rerere(int argc,
     -		return cmd_rerere_diff(argc, argv, prefix, repo);
     -	else
     -		usage_with_options(rerere_usage, options);
    -+		strvec_push(&args, "record");
    ++		strvec_push(&args, "perform");
     +		strvec_pushv(&args, argv);
      
     -	return 0;
    @@ builtin/rerere.c: int cmd_rerere(int argc,
     +		CALLOC_ARRAY(args_copy, args.nr);
     +		COPY_ARRAY(args_copy, args.v, args.nr);
     +
    -+		ret = cmd_rerere_record(args.nr, args_copy, prefix, repo);
    ++		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
     +
     +		strvec_clear(&args);
     +		free(args_copy);
12:  102223da27b ! 12:  05adadc9dd8 builtin/rerere: introduce proper usage strings for subcommands
    @@ builtin/rerere.c: static int cmd_rerere_gc(int argc,
      	if (argc)
      		usage(_("too many arguments"));
      
    -@@ builtin/rerere.c: static int cmd_rerere_record(int argc,
    +@@ builtin/rerere.c: static int cmd_rerere_perform(int argc,
      			N_("register clean resolutions in index"), 1),
      		OPT_END(),
      	};

--- base-commit: 710910c03a22ac663885049213b9fef5853ea8e0 change-id: 20261027-pks-rerere-subcommands-318d41553438

Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 01/12] rerere: rename `repo_rerere()`

The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix.

Rename the function to just `rerere()`. Move around and extend documentation of this function to better explain what it does.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 apply.c          | 2 +-
 builtin/am.c     | 4 ++--
 builtin/commit.c | 2 +-
 builtin/merge.c  | 2 +-
 builtin/rerere.c | 2 +-
 builtin/stash.c  | 2 +-
 rerere.c         | 7 +------
 rerere.h         | 9 ++++++++-
 sequencer.c      | 4 ++--
 9 files changed, 18 insertions(+), 16 deletions(-)
Show changes to 9 files +18 −16

apply.c, builtin/am.c, builtin/commit.c, builtin/merge.c, builtin/rerere.c, builtin/stash.c, rerere.c, rerere.h, sequencer.c

diff --git a/apply.c b/apply.c
index a0b7119c639..646fabeafa3 100644
--- a/apply.c
+++ b/apply.c
@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		 * tree with conflict markers, but that isn't written with --cached.
 		 */
 		if (!state->cached)
-			repo_rerere(state->repo, 0);
+			rerere(state->repo, 0);
 	}
 
 	return errs;
diff --git a/builtin/am.c b/builtin/am.c
index e9623b83077..4a5b37bee00 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		o.verbosity = 0;
 
 	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-		repo_rerere(the_repository, state->allow_rerere_autoupdate);
+		rerere(the_repository, state->allow_rerere_autoupdate);
 		free(their_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
 			goto next;
 	}
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 
 	do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8ffd42681bb..3a4b94ad623 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,
 
 	git_test_write_commit_graph_or_die(the_repository);
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 	run_auto_maintenance(the_repository, quiet);
 	run_commit_hook(use_editor, repo_get_index_file(the_repository),
 			NULL, "post-commit", NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index d7bf209114f..089e36e8575 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
-	repo_rerere(the_repository, allow_rerere_auto);
+	rerere(the_repository, allow_rerere_auto);
 	printf(_("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n"));
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2c17f02f56d..a499e7b9151 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -83,7 +83,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return repo_rerere(the_repository, flags);
+		return rerere(the_repository, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
diff --git a/builtin/stash.c b/builtin/stash.c
index e1a3a76bd04..91870a255fd 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
 		ret = error(_("could not write index"));
 
 	if (ret) {
-		repo_rerere(the_repository, 0);
+		rerere(the_repository, 0);
 
 		if (index)
 			fprintf_ln(stderr, _("Index was not unstashed."));
diff --git a/rerere.c b/rerere.c
index e0897612085..47a4a325bf5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-/*
- * The main entry point that is called internally from codepaths that
- * perform mergy operations, possibly leaving conflicted index entries
- * and working tree files.
- */
-int repo_rerere(struct repository *r, int flags)
+int rerere(struct repository *r, int flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
diff --git a/rerere.h b/rerere.h
index d3cbd10e13f..dd9da03d6db 100644
--- a/rerere.h
+++ b/rerere.h
@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,
 		       int flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int repo_rerere(struct repository *, int);
+/*
+ * The main entry point that is called internally from codepaths that
+ * perform mergy operations, possibly leaving conflicted index entries
+ * and working tree files. It records (and optionally updates) resolved
+ * conflicts and reuses recorded resolutions for unresolved conflicts.
+ */
+int rerere(struct repository *r, int flags);
+
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
diff --git a/sequencer.c b/sequencer.c
index 508ec717920..ace1cfac1cb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,
 		      : _("could not apply %s... %s"),
 		      short_commit_name(r, commit), msg.subject);
 		print_advice(r, res == 1, opts);
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 		goto leave;
 	}
 
@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,
 
 	rollback_lock_file(&lock);
 	if (ret)
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 	else
 		/*
 		 * In case of problems, we now want to return a positive
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 02/12] rerere: convert flags into an enum

Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly and document them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 rerere.c |  7 ++++---
 rerere.h | 30 +++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 12 deletions(-)
Show changes to 2 files +25 −12

rerere.c, rerere.h

diff --git a/rerere.c b/rerere.c
index 47a4a325bf5..3652b7ac2d5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags)
+		       enum rerere_flags flags)
 {
 	int lock_timeout_ms = 1000;
 	int fd;
@@ -951,7 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-int rerere(struct repository *r, int flags)
+int rerere(struct repository *r, enum rerere_flags flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
@@ -1336,7 +1336,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr, int flags)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_flags flags)
 {
 	struct rerere_cache cache;
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
diff --git a/rerere.h b/rerere.h
index dd9da03d6db..f13790c5dcd 100644
--- a/rerere.h
+++ b/rerere.h
@@ -9,12 +9,6 @@
 struct pathspec;
 struct repository;
 
-#define RERERE_AUTOUPDATE   01
-#define RERERE_NOAUTOUPDATE 02
-#define RERERE_READONLY     04
-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
-#define RERERE_NOWAIT       010
-
 /*
  * Marks paths that have been hand-resolved and added to the
  * index. Set in the util field of such paths after calling
@@ -39,10 +33,27 @@ struct rerere_id {
 	int variant;
 };
 
+enum rerere_flags {
+	/*
+	 * Auto-update the index with previously recorded resolutions. This can
+	 * be used to explicitly override "rerere.autoUpdate".
+	 */
+	RERERE_AUTOUPDATE = (1 << 0),
+
+	/* Reverse of RERERE_AUTOUPDATE. */
+	RERERE_NOAUTOUPDATE = (1 << 1),
+
+	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
+	RERERE_READONLY = (1 << 2),
+
+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
+	RERERE_NOWAIT = (1 << 3),
+};
+
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags);
+		       enum rerere_flags flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
 /*
@@ -51,7 +62,7 @@ void rerere_cache_release(struct rerere_cache *cache);
  * and working tree files. It records (and optionally updates) resolved
  * conflicts and reuses recorded resolutions for unresolved conflicts.
  */
-int rerere(struct repository *r, int flags);
+int rerere(struct repository *r, enum rerere_flags flags);
 
 /*
  * Given the conflict ID and the name of a "file" used for replaying
@@ -65,7 +76,8 @@ const char *rerere_path(struct repository *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *, int);
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
-- 
2.56.0.341.g393f52fd96.dirty
Karthik Nayak· Nov 6, 2026, 10:51 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 02/12] rerere: convert flags into an enum

Patrick Steinhardt <ps@pks.im> writes:
Show 18 quoted lines
> diff --git a/rerere.h b/rerere.h
> index dd9da03d6db..f13790c5dcd 100644
> --- a/rerere.h
> +++ b/rerere.h
> @@ -39,10 +33,27 @@ struct rerere_id {
>  	int variant;
>  };
>
> +enum rerere_flags {
> +	/*
> +	 * Auto-update the index with previously recorded resolutions. This can
> +	 * be used to explicitly override "rerere.autoUpdate".
> +	 */
> +	RERERE_AUTOUPDATE = (1 << 0),
> +
> +	/* Reverse of RERERE_AUTOUPDATE. */
> +	RERERE_NOAUTOUPDATE = (1 << 1),
> +
Nit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict
resolution information to the stderr instead of updating the index.
Perhaps that's something to document?
Show 15 quoted lines
> +	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
> +	RERERE_READONLY = (1 << 2),
> +
> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
> +	RERERE_NOWAIT = (1 << 3),
> +};
> +
>  int rerere_cache_setup(struct rerere_cache *cache,
>  		       struct repository *r,
>  		       struct string_list *merge_rr,
> -		       int flags);
> +		       enum rerere_flags flags);
>  void rerere_cache_release(struct rerere_cache *cache);
>
>  /*
Patrick Steinhardt· Nov 6, 2026, 11:39 UTC · re: Karthik Nayak · lore

Re: [PATCH v2 02/12] rerere: convert flags into an enum

On Fri, Nov 06, 2026 at 05:51:13AM -0500, Karthik Nayak wrote:
Show 24 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > diff --git a/rerere.h b/rerere.h
> > index dd9da03d6db..f13790c5dcd 100644
> > --- a/rerere.h
> > +++ b/rerere.h
> > @@ -39,10 +33,27 @@ struct rerere_id {
> >  	int variant;
> >  };
> >
> > +enum rerere_flags {
> > +	/*
> > +	 * Auto-update the index with previously recorded resolutions. This can
> > +	 * be used to explicitly override "rerere.autoUpdate".
> > +	 */
> > +	RERERE_AUTOUPDATE = (1 << 0),
> > +
> > +	/* Reverse of RERERE_AUTOUPDATE. */
> > +	RERERE_NOAUTOUPDATE = (1 << 1),
> > +
> 
> Nit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict
> resolution information to the stderr instead of updating the index.
> Perhaps that's something to document?

Well, the fact that it prints to stderr is not specific to NOAUTOUPDATE. We print messages in both cases, just at different times:

  - When `RERERE_AUTOUPDATE` is set we print the messages in
    `update_paths()`.
  - When `RERERE_NOAUTOUPDATE` is set (or `RERERE_AUTOUPDATE` is simply
    unset) then we print the message in `do_rerere_one_path()`.

The messages are different of course, but I don't really think that this matters for the flag here. What we might want to say though is that we don't update the index, but the working tree does get updated.

Will adapt, thanks.
Patrick
Karthik Nayak· Nov 6, 2026, 13:50 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 02/12] rerere: convert flags into an enum

Patrick Steinhardt <ps@pks.im> writes:
Show 35 quoted lines
> On Fri, Nov 06, 2026 at 05:51:13AM -0500, Karthik Nayak wrote:
>> Patrick Steinhardt <ps@pks.im> writes:
>>
>> > diff --git a/rerere.h b/rerere.h
>> > index dd9da03d6db..f13790c5dcd 100644
>> > --- a/rerere.h
>> > +++ b/rerere.h
>> > @@ -39,10 +33,27 @@ struct rerere_id {
>> >  	int variant;
>> >  };
>> >
>> > +enum rerere_flags {
>> > +	/*
>> > +	 * Auto-update the index with previously recorded resolutions. This can
>> > +	 * be used to explicitly override "rerere.autoUpdate".
>> > +	 */
>> > +	RERERE_AUTOUPDATE = (1 << 0),
>> > +
>> > +	/* Reverse of RERERE_AUTOUPDATE. */
>> > +	RERERE_NOAUTOUPDATE = (1 << 1),
>> > +
>>
>> Nit: From my understanding, RERERE_NOAUTOUPDATE outputs the conflict
>> resolution information to the stderr instead of updating the index.
>> Perhaps that's something to document?
>
> Well, the fact that it prints to stderr is not specific to NOAUTOUPDATE.
> We print messages in both cases, just at different times:
>
>   - When `RERERE_AUTOUPDATE` is set we print the messages in
>     `update_paths()`.
>
>   - When `RERERE_NOAUTOUPDATE` is set (or `RERERE_AUTOUPDATE` is simply
>     unset) then we print the message in `do_rerere_one_path()`.
>
I didn't dig enough to find the former.
Show 7 quoted lines
> The messages are different of course, but I don't really think that this
> matters for the flag here. What we might want to say though is that we
> don't update the index, but the working tree does get updated.
>
> Will adapt, thanks.
>
> Patrick
Sounds good.
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 03/12] builtin/rerere: drop `the_repository`

There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Show changes to builtin/rerere.c +11 −13
diff --git a/builtin/rerere.c b/builtin/rerere.c
index a499e7b9151..83fb3783c61 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int autoupdate = -1, skip_locked = 0, flags = 0;
@@ -75,7 +73,7 @@ int cmd_rerere(int argc,
 	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
 		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
 
-	repo_config(the_repository, git_xmerge_config, NULL);
+	repo_config(repo, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
 		flags = RERERE_AUTOUPDATE;
@@ -83,7 +81,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return rerere(the_repository, flags);
+		return rerere(repo, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
@@ -94,21 +92,21 @@ int cmd_rerere(int argc,
 		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
 			       prefix, argv + 1);
 
-		ret = rerere_forget(the_repository, &pathspec);
+		ret = rerere_forget(repo, &pathspec);
 
 		clear_pathspec(&pathspec);
 		return ret;
 	}
 
 	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(the_repository, &merge_rr);
+		rerere_clear(repo, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr,
+		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				       flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
@@ -116,7 +114,7 @@ int cmd_rerere(int argc,
 
 		rerere_cache_release(&cache);
 	} else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(the_repository, &merge_rr);
+		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
 				printf("%s\n", merge_rr.items[i].string);
@@ -129,16 +127,16 @@ int cmd_rerere(int argc,
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				      flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
 			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
+			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
 				     path, path, path))
 				die(_("unable to generate diff for '%s'"),
-				    rerere_path(the_repository, &buf, id, NULL));
+				    rerere_path(repo, &buf, id, NULL));
 		}
 
 		rerere_cache_release(&cache);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 04/12] builtin/rerere: stop passing flags to subcommands that ignore them

The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`.

This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/rerere.c +2 −2
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 83fb3783c61..405276cc94b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -107,7 +107,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
 			printf("%s\n", merge_rr.items[i].string);
@@ -128,7 +128,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				      flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 05/12] builtin/rerere: turn "forget" into a proper subcommand

The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work:

  - Options from other subcommands apply to each other.
  - We don't have proper usage strings.
  - Running `git rerere <subcmd> -h` doesn't print the options that are
    supported by that subcommand, but instead it just prints the help of
    git-rerere(1) itself.

A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Show changes to builtin/rerere.c +24 −14
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 405276cc94b..5d2ae154ff8 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_forget(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct pathspec pathspec;
+	int ret;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (!argc)
+		warning(_("'git rerere forget' without paths is deprecated"));
+	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+
+	ret = rerere_forget(repo, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -83,20 +105,8 @@ int cmd_rerere(int argc,
 	if (argc < 1)
 		return rerere(repo, flags);
 
-	if (!strcmp(argv[0], "forget")) {
-		struct pathspec pathspec;
-		int ret;
-
-		if (argc < 2)
-			warning(_("'git rerere forget' without paths is deprecated"));
-		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
-			       prefix, argv + 1);
-
-		ret = rerere_forget(repo, &pathspec);
-
-		clear_pathspec(&pathspec);
-		return ret;
-	}
+	if (!strcmp(argv[0], "forget"))
+		return cmd_rerere_forget(argc, argv, prefix, repo);
 
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(repo, &merge_rr);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 06/12] builtin/rerere: turn "clear" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Show changes to builtin/rerere.c +22 −3
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 5d2ae154ff8..62f69b488b0 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_clear(int argc,
+			    const char **argv,
+			    const char *prefix,
+			    struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_clear(repo, &merge_rr);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -107,9 +127,8 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-
-	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(repo, &merge_rr);
+	else if (!strcmp(argv[0], "clear")) {
+		return cmd_rerere_clear(argc, argv, prefix, repo);
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 07/12] builtin/rerere: turn "status" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +29 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 62f69b488b0..2bcd270a1f1 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_status(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+	for (size_t i = 0; i < merge_rr.nr; i++)
+		printf("%s\n", merge_rr.items[i].string);
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	return 0;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -132,17 +158,9 @@ int cmd_rerere(int argc,
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-	else if (!strcmp(argv[0], "status")) {
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++)
-			printf("%s\n", merge_rr.items[i].string);
-
-		rerere_cache_release(&cache);
-	} else if (!strcmp(argv[0], "remaining")) {
+	else if (!strcmp(argv[0], "status"))
+		return cmd_rerere_status(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "remaining")) {
 		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 08/12] builtin/rerere: turn "remaining" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +31 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2bcd270a1f1..3f82bcbeb10 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_remaining(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_remaining(repo, &merge_rr);
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		if (merge_rr.items[i].util != RERERE_RESOLVED)
+			printf("%s\n", merge_rr.items[i].string);
+		else
+			/* prepare for later call to
+			 * string_list_clear() */
+			merge_rr.items[i].util = NULL;
+	}
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_status(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -160,17 +188,9 @@ int cmd_rerere(int argc,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(repo, &merge_rr);
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			if (merge_rr.items[i].util != RERERE_RESOLVED)
-				printf("%s\n", merge_rr.items[i].string);
-			else
-				/* prepare for later call to
-				 * string_list_clear() */
-				merge_rr.items[i].util = NULL;
-		}
-	} else if (!strcmp(argv[0], "diff")) {
+	else if (!strcmp(argv[0], "remaining"))
+		return cmd_rerere_remaining(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "diff")) {
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 09/12] builtin/rerere: turn "diff" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
Show changes to builtin/rerere.c +37 −19
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3f82bcbeb10..40bae5cb9cc 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,
 	return 0;
 }
 
+static int cmd_rerere_diff(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct strbuf buf = STRBUF_INIT;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		const char *path = merge_rr.items[i].string;
+		const struct rerere_id *id = merge_rr.items[i].util;
+		if (diff_two(rerere_path(repo, &buf, id, "preimage"), path, path, path))
+			die(_("unable to generate diff for '%s'"),
+			    rerere_path(repo, &buf, id, NULL));
+	}
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	strbuf_release(&buf);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -190,25 +224,9 @@ int cmd_rerere(int argc,
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
 		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff")) {
-		struct strbuf buf = STRBUF_INIT;
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			const char *path = merge_rr.items[i].string;
-			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
-				     path, path, path))
-				die(_("unable to generate diff for '%s'"),
-				    rerere_path(repo, &buf, id, NULL));
-		}
-
-		rerere_cache_release(&cache);
-		strbuf_release(&buf);
-	} else
+	else if (!strcmp(argv[0], "diff"))
+		return cmd_rerere_diff(argc, argv, prefix, repo);
+	else
 		usage_with_options(rerere_usage, options);
 
 	string_list_clear(&merge_rr, 1);
-- 
2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 10/12] builtin/rerere: turn "gc" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
 t/t4200-rerere.sh |  5 -----
 2 files changed, 30 insertions(+), 18 deletions(-)
Show changes to 2 files +30 −18

builtin/rerere.c, t/t4200-rerere.sh

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 40bae5cb9cc..3162b074ec6 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_gc(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo)
+{
+	int skip_locked = 0;
+	struct option options[] = {
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+				N_("skip gc while another process holds the lock")),
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_gc(repo, &merge_rr,
+		  skip_locked ? RERERE_NOWAIT : 0);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -187,21 +211,16 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, skip_locked = 0, flags = 0;
+	int autoupdate = -1, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
-		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
-			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
-
-	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
-		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+	argc = parse_options(argc, argv, prefix, options, rerere_usage,
+			     PARSE_OPT_KEEP_UNKNOWN_OPT);
 
 	repo_config(repo, git_xmerge_config, NULL);
 
@@ -215,11 +234,10 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear")) {
+	else if (!strcmp(argv[0], "clear"))
 		return cmd_rerere_clear(argc, argv, prefix, repo);
-	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(repo, &merge_rr,
-			  skip_locked ? RERERE_NOWAIT : 0);
+	else if (!strcmp(argv[0], "gc"))
+		return cmd_rerere_gc(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
@@ -229,6 +247,5 @@ int cmd_rerere(int argc,
 	else
 		usage_with_options(rerere_usage, options);
 
-	string_list_clear(&merge_rr, 1);
 	return 0;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ab412ecc6e8..0d4cbf5114a 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
 	test_path_is_missing $rr2/preimage
 '
 
-test_expect_success '--skip-locked is only accepted by gc' '
-	test_must_fail git rerere --skip-locked clear 2>err &&
-	test_grep "option .--skip-locked. requires .gc." err
-'
-
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
-- 
2.56.0.341.g393f52fd96.dirty
Karthik Nayak· Nov 6, 2026, 10:56 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 10/12] builtin/rerere: turn "gc" into a proper subcommand

Patrick Steinhardt <ps@pks.im> writes:
> As explained in a preceding commit, a subsequent commit will introduce
> proper subcommands as supported by our parse-options subsystem. Refactor
> the "gc" subcommand to use parse-options as a preparatory step.
>

Okay so the commits till here are mostly straightforward extraction to prepare for the subcommand introduction. Reading on....

Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

In git-rerere(1) we have our own custom logic to parse subcommands. In preceding commits we have refactored all of those subcommands so that they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use these so that we get rid of our custom subcommand parsing.

Unfortunately this means that we have a backwards-incompatible change because we no longer accept the "--[no-]rerere-autoupdate" flag for all subcommands. But this was arguably broken and misleading as we ignore this flag for any other subcommand aynway. So we cheat a bit and simply call it a bug that those flags were accepted in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 28 deletions(-)
Show changes to builtin/rerere.c +56 −28
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3162b074ec6..97c791e420b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -5,6 +5,7 @@
 #include "rerere.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "strvec.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
 	return 0;
 }
 
+static int cmd_rerere_perform(int argc,
+			      const char **argv,
+			      const char *prefix,
+			      struct repository *repo)
+{
+	int autoupdate = -1;
+	struct option options[] = {
+		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+			N_("register clean resolutions in index"), 1),
+		OPT_END(),
+	};
+	enum rerere_flags flags = 0;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (autoupdate == 1)
+		flags = RERERE_AUTOUPDATE;
+	if (autoupdate == 0)
+		flags = RERERE_NOAUTOUPDATE;
+
+	return rerere(repo, flags);
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -211,41 +237,43 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	int autoupdate = -1, flags = 0;
-
+	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
-			N_("register clean resolutions in index"), 1),
+		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
+		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
+		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
+		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
+		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
+		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
-			     PARSE_OPT_KEEP_UNKNOWN_OPT);
-
+			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
 	repo_config(repo, git_xmerge_config, NULL);
 
-	if (autoupdate == 1)
-		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);
-
-	if (!strcmp(argv[0], "forget"))
-		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear"))
-		return cmd_rerere_clear(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "gc"))
-		return cmd_rerere_gc(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "status"))
-		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining"))
-		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff"))
-		return cmd_rerere_diff(argc, argv, prefix, repo);
-	else
-		usage_with_options(rerere_usage, options);
+		strvec_push(&args, "perform");
+		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);
+		COPY_ARRAY(args_copy, args.v, args.nr);
+
+		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
+
+		strvec_clear(&args);
+		free(args_copy);
+		return ret;
+	}
+
+	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.0.341.g393f52fd96.dirty
Karthik Nayak· Nov 6, 2026, 11:44 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

Patrick Steinhardt <ps@pks.im> writes:
Show 11 quoted lines
> In git-rerere(1) we have our own custom logic to parse subcommands. In
> preceding commits we have refactored all of those subcommands so that
> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use
> these so that we get rid of our custom subcommand parsing.
>
> Unfortunately this means that we have a backwards-incompatible change
> because we no longer accept the "--[no-]rerere-autoupdate" flag for all
> subcommands. But this was arguably broken and misleading as we ignore
> this flag for any other subcommand aynway. So we cheat a bit and simply
> call it a bug that those flags were accepted in the first place.
>
Okay.
Show 46 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 56 insertions(+), 28 deletions(-)
>
> diff --git a/builtin/rerere.c b/builtin/rerere.c
> index 3162b074ec6..97c791e420b 100644
> --- a/builtin/rerere.c
> +++ b/builtin/rerere.c
> @@ -5,6 +5,7 @@
>  #include "rerere.h"
>  #include "strbuf.h"
>  #include "string-list.h"
> +#include "strvec.h"
>  #include "xdiff/xdiff.h"
>  #include "xdiff-interface.h"
>  #include "pathspec.h"
> @@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
>  	return 0;
>  }
>
> +static int cmd_rerere_perform(int argc,
> +			      const char **argv,
> +			      const char *prefix,
> +			      struct repository *repo)
> +{
> +	int autoupdate = -1;
> +	struct option options[] = {
> +		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
> +			N_("register clean resolutions in index"), 1),
> +		OPT_END(),
> +	};
> +	enum rerere_flags flags = 0;
> +
> +	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
> +	if (argc)
> +		usage(_("too many arguments"));
> +
> +	if (autoupdate == 1)
> +		flags = RERERE_AUTOUPDATE;
> +	if (autoupdate == 0)
> +		flags = RERERE_NOAUTOUPDATE;
> +
> +	return rerere(repo, flags);
> +}
> +

So I guess this would be the default case if no subcommand is used, meaning the subcommands should be optional.

Show 26 quoted lines
>  static int cmd_rerere_remaining(int argc,
>  				const char **argv,
>  				const char *prefix,
> @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
>  	       const char *prefix,
>  	       struct repository *repo)
>  {
> -	int autoupdate = -1, flags = 0;
> -
> +	parse_opt_subcommand_fn *fn = NULL;
>  	struct option options[] = {
> -		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
> -			N_("register clean resolutions in index"), 1),
> +		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
> +		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
> +		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
> +		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
> +		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
> +		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
>  		OPT_END(),
>  	};
>
>  	argc = parse_options(argc, argv, prefix, options, rerere_usage,
> -			     PARSE_OPT_KEEP_UNKNOWN_OPT);
> -
> +			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
So this matches what I thought.
Show 7 quoted lines
>  	repo_config(repo, git_xmerge_config, NULL);
>
> -	if (autoupdate == 1)
> -		flags = RERERE_AUTOUPDATE;
> -	if (autoupdate == 0)
> -		flags = RERERE_NOAUTOUPDATE;
> +	if (!fn) {

Okay if there's no function we call the default case. I wonder if we could've done the inverse to reduce code block. if (fn) reutrn fn(...). Doesn't matter much anyway.

Show 22 quoted lines
> +		struct strvec args = STRVEC_INIT;
> +		const char **args_copy;
> +		int ret;
>
> -	if (argc < 1)
> -		return rerere(repo, flags);
> -
> -	if (!strcmp(argv[0], "forget"))
> -		return cmd_rerere_forget(argc, argv, prefix, repo);
> -	else if (!strcmp(argv[0], "clear"))
> -		return cmd_rerere_clear(argc, argv, prefix, repo);
> -	else if (!strcmp(argv[0], "gc"))
> -		return cmd_rerere_gc(argc, argv, prefix, repo);
> -	else if (!strcmp(argv[0], "status"))
> -		return cmd_rerere_status(argc, argv, prefix, repo);
> -	else if (!strcmp(argv[0], "remaining"))
> -		return cmd_rerere_remaining(argc, argv, prefix, repo);
> -	else if (!strcmp(argv[0], "diff"))
> -		return cmd_rerere_diff(argc, argv, prefix, repo);
> -	else
> -		usage_with_options(rerere_usage, options);
> +		strvec_push(&args, "perform");
Worthwhile adding a comment that this is a dummy placeholder subcommand?
Show 11 quoted lines
> +		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);
> +		COPY_ARRAY(args_copy, args.v, args.nr);
> +

Since we need to add the dummy 'perform' and don't want to clear the actual argv, we copy it over. makes sense.

Show 12 quoted lines
> +		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
> +
> +		strvec_clear(&args);
> +		free(args_copy);
> +		return ret;
> +	}
> +
> +	return fn(argc, argv, prefix, repo);
>  }
>
> --
> 2.56.0.341.g393f52fd96.dirty
Patrick Steinhardt· Nov 6, 2026, 14:25 UTC · re: Karthik Nayak · lore

Re: [PATCH v2 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

On Fri, Nov 06, 2026 at 03:44:38AM -0800, Karthik Nayak wrote:
Show 42 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/builtin/rerere.c b/builtin/rerere.c
> > index 3162b074ec6..97c791e420b 100644
> > --- a/builtin/rerere.c
> > +++ b/builtin/rerere.c
> > @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
> >  	       const char *prefix,
> >  	       struct repository *repo)
> >  {
> > -	int autoupdate = -1, flags = 0;
> > -
> > +	parse_opt_subcommand_fn *fn = NULL;
> >  	struct option options[] = {
> > -		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
> > -			N_("register clean resolutions in index"), 1),
> > +		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
> > +		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
> > +		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
> > +		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
> > +		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
> > +		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
> >  		OPT_END(),
> >  	};
> >
> >  	argc = parse_options(argc, argv, prefix, options, rerere_usage,
> > -			     PARSE_OPT_KEEP_UNKNOWN_OPT);
> > -
> > +			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
> 
> So this matches what I thought.
> 
> >  	repo_config(repo, git_xmerge_config, NULL);
> >
> > -	if (autoupdate == 1)
> > -		flags = RERERE_AUTOUPDATE;
> > -	if (autoupdate == 0)
> > -		flags = RERERE_NOAUTOUPDATE;
> > +	if (!fn) {
> 
> Okay if there's no function we call the default case. I wonder if we
> could've done the inverse to reduce code block. if (fn) reutrn fn(...).
> Doesn't matter much anyway.

I think that the result is actually harder to read in that case, even though that might just be my personal opinion. But having a return in the middle of the function is awkward, and I like that the variables that are specific to the default subcommand are nicely scoped to the block so that they obviously cannot be used by any other subcommand.

So I prefer to keep this as-is.
Show 24 quoted lines
> > +		struct strvec args = STRVEC_INIT;
> > +		const char **args_copy;
> > +		int ret;
> >
> > -	if (argc < 1)
> > -		return rerere(repo, flags);
> > -
> > -	if (!strcmp(argv[0], "forget"))
> > -		return cmd_rerere_forget(argc, argv, prefix, repo);
> > -	else if (!strcmp(argv[0], "clear"))
> > -		return cmd_rerere_clear(argc, argv, prefix, repo);
> > -	else if (!strcmp(argv[0], "gc"))
> > -		return cmd_rerere_gc(argc, argv, prefix, repo);
> > -	else if (!strcmp(argv[0], "status"))
> > -		return cmd_rerere_status(argc, argv, prefix, repo);
> > -	else if (!strcmp(argv[0], "remaining"))
> > -		return cmd_rerere_remaining(argc, argv, prefix, repo);
> > -	else if (!strcmp(argv[0], "diff"))
> > -		return cmd_rerere_diff(argc, argv, prefix, repo);
> > -	else
> > -		usage_with_options(rerere_usage, options);
> > +		strvec_push(&args, "perform");
> 
> Worthwhile adding a comment that this is a dummy placeholder subcommand?
Hmm. I could add something like this:
Show changes to builtin/rerere.c +1 −0
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 97c791e420b..f88bc43e363 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -257,6 +257,7 @@ int cmd_rerere(int argc,
 		const char **args_copy;
 		int ret;
 
+		/* This is a dummy subcommand name. */
 		strvec_push(&args, "perform");
 		strvec_pushv(&args, argv);

But does that really add much value? I myself don't think so, but if you
feel that it does I'm happy to add it in.

Thanks!

Patrick
Patrick Steinhardt· Oct 29, 2026, 09:57 UTC · re: Patrick Steinhardt · lore

[PATCH v2 12/12] builtin/rerere: introduce proper usage strings for subcommands

Adapt git-rerere(1) to have proper usage strings for each of the subcommands.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc |  8 +++++-
 builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 11 deletions(-)
Show changes to 2 files +58 −11

Documentation/git-rerere.adoc, builtin/rerere.c

diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index 4e6ab9a27c9..e04e9ef3ef8 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
 SYNOPSIS
 --------
 [verse]
-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
+'git rerere' [--[no-]rerere-autoupdate]
+'git rerere' clear
+'git rerere' diff
+'git rerere' forget <pathspec>...
+'git rerere' gc
+'git rerere' remaining
+'git rerere' status
 
 DESCRIPTION
 -----------
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 97c791e420b..051e50838ce 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -10,10 +10,13 @@
 #include "xdiff-interface.h"
 #include "pathspec.h"
 
-static const char * const rerere_usage[] = {
-	N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
-	NULL,
-};
+#define RERERE_USAGE N_("git rerere [--[no-]rerere-autoupdate]")
+#define RERERE_CLEAR_USAGE N_("git rerere clear")
+#define RERERE_DIFF_USAGE N_("git rerere diff")
+#define RERERE_FORGET_USAGE N_("git rerere forget <pathspec>...")
+#define RERERE_GC_USAGE N_("git rerere gc")
+#define RERERE_REMAINING_USAGE N_("git rerere remaining")
+#define RERERE_STATUS_USAGE N_("git rerere status")
 
 static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)
 {
@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_clear_usage[] = {
+		RERERE_CLEAR_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_diff_usage[] = {
+		RERERE_DIFF_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_forget_usage[] = {
+		RERERE_FORGET_USAGE,
+		NULL,
+	};
 	struct pathspec pathspec;
 	int ret;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);
 	if (!argc)
 		warning(_("'git rerere forget' without paths is deprecated"));
 	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,
 				N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
+	const char * const rerere_gc_usage[] = {
+		RERERE_GC_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,
 			N_("register clean resolutions in index"), 1),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		NULL,
+	};
 	enum rerere_flags flags = 0;
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_remaining_usage[] = {
+		RERERE_REMAINING_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_status_usage[] = {
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -247,6 +278,16 @@ int cmd_rerere(int argc,
 		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		RERERE_CLEAR_USAGE,
+		RERERE_DIFF_USAGE,
+		RERERE_FORGET_USAGE,
+		RERERE_GC_USAGE,
+		RERERE_REMAINING_USAGE,
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
-- 
2.56.0.341.g393f52fd96.dirty
Karthik Nayak· Nov 6, 2026, 11:45 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v2 00/12] builtin/rerere: convert to use subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> 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.
>
Looks to be in good shape!
Thanks
Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 00/12] builtin/rerere: convert to use subcommands

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 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 (12):
      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.adoc |   8 +-
 apply.c                       |   2 +-
 builtin/am.c                  |   4 +-
 builtin/commit.c              |   2 +-
 builtin/merge.c               |   2 +-
 builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------
 builtin/stash.c               |   2 +-
 rerere.c                      |  12 +-
 rerere.h                      |  40 ++++--
 sequencer.c                   |   4 +-
 t/t4200-rerere.sh             |   5 -
 11 files changed, 294 insertions(+), 106 deletions(-)
Range-diff versus v2:
 1:  8d6b21c1ea2 =  1:  022fe75450a rerere: rename `repo_rerere()`
 2:  3dd2a9cc7e0 !  2:  1cb50bf5937 rerere: convert flags into an enum
    @@ rerere.h: struct rerere_id {
     +	 */
     +	RERERE_AUTOUPDATE = (1 << 0),
     +
    -+	/* Reverse of RERERE_AUTOUPDATE. */
    ++	/*
    ++	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
    ++	 * working tree but don't touch the index.
    ++	 */
     +	RERERE_NOAUTOUPDATE = (1 << 1),
     +
     +	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
 3:  a69e7f43d2b =  3:  d18adf008c9 builtin/rerere: drop `the_repository`
 4:  86654ba3606 =  4:  bc2eea0ba84 builtin/rerere: stop passing flags to subcommands that ignore them
 5:  f532910d986 =  5:  2b45e209b08 builtin/rerere: turn "forget" into a proper subcommand
 6:  6340e1db614 =  6:  8e1a5cf4239 builtin/rerere: turn "clear" into a proper subcommand
 7:  1c623efc48e =  7:  aede0d76e54 builtin/rerere: turn "status" into a proper subcommand
 8:  debe0999ecb =  8:  114e40d5a51 builtin/rerere: turn "remaining" into a proper subcommand
 9:  00bcc60a186 =  9:  7c523f60339 builtin/rerere: turn "diff" into a proper subcommand
10:  9cc14c726eb = 10:  6962d3ae764 builtin/rerere: turn "gc" into a proper subcommand
11:  8c90e572751 = 11:  d9021a91b8e builtin/rerere: use `OPT_SUBCOMMAND()`
12:  11baa9ee058 = 12:  3b59da3d583 builtin/rerere: introduce proper usage strings for subcommands

--- base-commit: 710910c03a22ac663885049213b9fef5853ea8e0 change-id: 20261027-pks-rerere-subcommands-318d41553438

Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 01/12] rerere: rename `repo_rerere()`

The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix.

Rename the function to just `rerere()`. Move around and extend documentation of this function to better explain what it does.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 apply.c          | 2 +-
 builtin/am.c     | 4 ++--
 builtin/commit.c | 2 +-
 builtin/merge.c  | 2 +-
 builtin/rerere.c | 2 +-
 builtin/stash.c  | 2 +-
 rerere.c         | 7 +------
 rerere.h         | 9 ++++++++-
 sequencer.c      | 4 ++--
 9 files changed, 18 insertions(+), 16 deletions(-)
Show changes to 9 files +18 −16

apply.c, builtin/am.c, builtin/commit.c, builtin/merge.c, builtin/rerere.c, builtin/stash.c, rerere.c, rerere.h, sequencer.c

diff --git a/apply.c b/apply.c
index a0b7119c639..646fabeafa3 100644
--- a/apply.c
+++ b/apply.c
@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		 * tree with conflict markers, but that isn't written with --cached.
 		 */
 		if (!state->cached)
-			repo_rerere(state->repo, 0);
+			rerere(state->repo, 0);
 	}
 
 	return errs;
diff --git a/builtin/am.c b/builtin/am.c
index e9623b83077..4a5b37bee00 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		o.verbosity = 0;
 
 	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-		repo_rerere(the_repository, state->allow_rerere_autoupdate);
+		rerere(the_repository, state->allow_rerere_autoupdate);
 		free(their_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
 			goto next;
 	}
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 
 	do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8ffd42681bb..3a4b94ad623 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,
 
 	git_test_write_commit_graph_or_die(the_repository);
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 	run_auto_maintenance(the_repository, quiet);
 	run_commit_hook(use_editor, repo_get_index_file(the_repository),
 			NULL, "post-commit", NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index d7bf209114f..089e36e8575 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
-	repo_rerere(the_repository, allow_rerere_auto);
+	rerere(the_repository, allow_rerere_auto);
 	printf(_("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n"));
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2c17f02f56d..a499e7b9151 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -83,7 +83,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return repo_rerere(the_repository, flags);
+		return rerere(the_repository, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
diff --git a/builtin/stash.c b/builtin/stash.c
index e1a3a76bd04..91870a255fd 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
 		ret = error(_("could not write index"));
 
 	if (ret) {
-		repo_rerere(the_repository, 0);
+		rerere(the_repository, 0);
 
 		if (index)
 			fprintf_ln(stderr, _("Index was not unstashed."));
diff --git a/rerere.c b/rerere.c
index e0897612085..47a4a325bf5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-/*
- * The main entry point that is called internally from codepaths that
- * perform mergy operations, possibly leaving conflicted index entries
- * and working tree files.
- */
-int repo_rerere(struct repository *r, int flags)
+int rerere(struct repository *r, int flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
diff --git a/rerere.h b/rerere.h
index d3cbd10e13f..dd9da03d6db 100644
--- a/rerere.h
+++ b/rerere.h
@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,
 		       int flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int repo_rerere(struct repository *, int);
+/*
+ * The main entry point that is called internally from codepaths that
+ * perform mergy operations, possibly leaving conflicted index entries
+ * and working tree files. It records (and optionally updates) resolved
+ * conflicts and reuses recorded resolutions for unresolved conflicts.
+ */
+int rerere(struct repository *r, int flags);
+
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
diff --git a/sequencer.c b/sequencer.c
index 508ec717920..ace1cfac1cb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,
 		      : _("could not apply %s... %s"),
 		      short_commit_name(r, commit), msg.subject);
 		print_advice(r, res == 1, opts);
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 		goto leave;
 	}
 
@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,
 
 	rollback_lock_file(&lock);
 	if (ret)
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 	else
 		/*
 		 * In case of problems, we now want to return a positive
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 02/12] rerere: convert flags into an enum

Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly and document them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 rerere.c |  7 ++++---
 rerere.h | 33 ++++++++++++++++++++++++---------
 2 files changed, 28 insertions(+), 12 deletions(-)
Show changes to 2 files +28 −12

rerere.c, rerere.h

diff --git a/rerere.c b/rerere.c
index 47a4a325bf5..3652b7ac2d5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags)
+		       enum rerere_flags flags)
 {
 	int lock_timeout_ms = 1000;
 	int fd;
@@ -951,7 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-int rerere(struct repository *r, int flags)
+int rerere(struct repository *r, enum rerere_flags flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
@@ -1336,7 +1336,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr, int flags)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_flags flags)
 {
 	struct rerere_cache cache;
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
diff --git a/rerere.h b/rerere.h
index dd9da03d6db..21ff867d824 100644
--- a/rerere.h
+++ b/rerere.h
@@ -9,12 +9,6 @@
 struct pathspec;
 struct repository;
 
-#define RERERE_AUTOUPDATE   01
-#define RERERE_NOAUTOUPDATE 02
-#define RERERE_READONLY     04
-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
-#define RERERE_NOWAIT       010
-
 /*
  * Marks paths that have been hand-resolved and added to the
  * index. Set in the util field of such paths after calling
@@ -39,10 +33,30 @@ struct rerere_id {
 	int variant;
 };
 
+enum rerere_flags {
+	/*
+	 * Auto-update the index with previously recorded resolutions. This can
+	 * be used to explicitly override "rerere.autoUpdate".
+	 */
+	RERERE_AUTOUPDATE = (1 << 0),
+
+	/*
+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
+	 * working tree but don't touch the index.
+	 */
+	RERERE_NOAUTOUPDATE = (1 << 1),
+
+	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
+	RERERE_READONLY = (1 << 2),
+
+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
+	RERERE_NOWAIT = (1 << 3),
+};
+
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags);
+		       enum rerere_flags flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
 /*
@@ -51,7 +65,7 @@ void rerere_cache_release(struct rerere_cache *cache);
  * and working tree files. It records (and optionally updates) resolved
  * conflicts and reuses recorded resolutions for unresolved conflicts.
  */
-int rerere(struct repository *r, int flags);
+int rerere(struct repository *r, enum rerere_flags flags);
 
 /*
  * Given the conflict ID and the name of a "file" used for replaying
@@ -65,7 +79,8 @@ const char *rerere_path(struct repository *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *, int);
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
-- 
2.56.0.500.g5d06dc02cd.dirty
Junio C Hamano· Nov 6, 2026, 16:39 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v3 02/12] rerere: convert flags into an enum

Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> +enum rerere_flags {
> +	/*
> +	 * Auto-update the index with previously recorded resolutions. This can
> +	 * be used to explicitly override "rerere.autoUpdate".
> +	 */
> +	RERERE_AUTOUPDATE = (1 << 0),
> +
> +	/*
> +	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
> +	 * working tree but don't touch the index.
> +	 */
> +	RERERE_NOAUTOUPDATE = (1 << 1),

As you have updated the comment in this iteration, I'll throw a bit of review in. The new comment is not wrong per-se, but the one from the previous iteration was sufficient to convey the same thing. In other words, I see no improvement in v3 over what you had in v2 for this bit.

What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is needed in the first place. In other words, "How is it different from the lack of RERERE_AUTOUPDATE bit?" is not answered here. And I think that is a lot more important thing to clarify.

Show 6 quoted lines
> +	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
> +	RERERE_READONLY = (1 << 2),
> +
> +	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
> +	RERERE_NOWAIT = (1 << 3),
> +};
Patrick Steinhardt· Nov 9, 2026, 07:06 UTC · re: Junio C Hamano · lore

Re: [PATCH v3 02/12] rerere: convert flags into an enum

On Fri, Nov 06, 2026 at 08:39:37AM -0800, Junio C Hamano wrote:
Show 20 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > +enum rerere_flags {
> > +	/*
> > +	 * Auto-update the index with previously recorded resolutions. This can
> > +	 * be used to explicitly override "rerere.autoUpdate".
> > +	 */
> > +	RERERE_AUTOUPDATE = (1 << 0),
> > +
> > +	/*
> > +	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
> > +	 * working tree but don't touch the index.
> > +	 */
> > +	RERERE_NOAUTOUPDATE = (1 << 1),
> 
> As you have updated the comment in this iteration, I'll throw a bit
> of review in.  The new comment is not wrong per-se, but the one from
> the previous iteration was sufficient to convey the same thing.  In
> other words, I see no improvement in v3 over what you had in v2 for
> this bit.

I wouldn't necessarily say so, as an unknowing reader might not know that we still update the working tree. I myself certainly didn't, and I had to dig a bit to figure out what happens with this flag, mostly because I am not familiar with the rerere subsystem.

> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is
> needed in the first place.  In other words, "How is it different
> from the lack of RERERE_AUTOUPDATE bit?" is not answered here.  And
> I think that is a lot more important thing to clarify.

Heh, in this case _I_ thought that it's implicitly clear from the comment of `RERERE_AUTOUPDATE`: it overrides "rerere.autoUpdate". I figured that updating these comments would cause some discussions, and that's exactly why I didn't dare to update them at all in v1 :)

How about this instead:
    Only update the file in the working tree, but don't touch the index.
    This can be passed to explicitly override "rerere.autoUpdate".
Patrick
Junio C Hamano· Nov 9, 2026, 15:40 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v3 02/12] rerere: convert flags into an enum

Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is
>> needed in the first place.  In other words, "How is it different
>> from the lack of RERERE_AUTOUPDATE bit?" is not answered here.  And
>> I think that is a lot more important thing to clarify.
>
> Heh, in this case _I_ thought that it's implicitly clear from the
> comment of `RERERE_AUTOUPDATE`: it overrides "rerere.autoUpdate". I
> figured that updating these comments would cause some discussions, and
> that's exactly why I didn't dare to update them at all in v1 :)
;-)
Junio C Hamano· Nov 9, 2026, 19:13 UTC · re: Junio C Hamano · lore

Re: [PATCH v3 02/12] rerere: convert flags into an enum

Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
>
>>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is
>>> needed in the first place.  In other words, "How is it different
>>> from the lack of RERERE_AUTOUPDATE bit?" is not answered here.  And
>>> I think that is a lot more important thing to clarify.
>>
>> Heh, in this case _I_ thought that it's implicitly clear from the
>> comment of `RERERE_AUTOUPDATE`: it overrides "rerere.autoUpdate". I
>> figured that updating these comments would cause some discussions, and
>> that's exactly why I didn't dare to update them at all in v1 :)
>
> ;-)

The command line can give us not two (which could be represented with a single bit) but three choices, (0) the command line has no preference on --[no-]autoupdate and follow the configured default, (1) --autoupdate, or (2) --no-autoupdate, and that is exactly why we have these two independent-looking bits.

But two bits can express another combination (i.e., both bits on), which probably is invalid. The underlying OPT_UYN() calls parse_opt_tertiary() which only chooses between 1 and 2 so we should be safe on the setting side, but I offhand do not remember if we detect when both bits are on and BUG() out where we consume the value.

Thanks.
Patrick Steinhardt· Nov 11, 2026, 11:02 UTC · re: Junio C Hamano · lore

Re: [PATCH v3 02/12] rerere: convert flags into an enum

On Mon, Nov 09, 2026 at 11:13:53AM -0800, Junio C Hamano wrote:
Show 28 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> >>> What BOTH versions lack is an explanation why RERERE_NOAUTOUPDATE is
> >>> needed in the first place.  In other words, "How is it different
> >>> from the lack of RERERE_AUTOUPDATE bit?" is not answered here.  And
> >>> I think that is a lot more important thing to clarify.
> >>
> >> Heh, in this case _I_ thought that it's implicitly clear from the
> >> comment of `RERERE_AUTOUPDATE`: it overrides "rerere.autoUpdate". I
> >> figured that updating these comments would cause some discussions, and
> >> that's exactly why I didn't dare to update them at all in v1 :)
> >
> > ;-)
> 
> The command line can give us not two (which could be represented
> with a single bit) but three choices, (0) the command line has no
> preference on --[no-]autoupdate and follow the configured default,
> (1) --autoupdate, or (2) --no-autoupdate, and that is exactly why we
> have these two independent-looking bits.
> 
> But two bits can express another combination (i.e., both bits on),
> which probably is invalid.  The underlying OPT_UYN() calls
> parse_opt_tertiary() which only chooses between 1 and 2 so we should
> be safe on the setting side, but I offhand do not remember if we
> detect when both bits are on and BUG() out where we consume the
> value.
We have this bit in `rerere_cache_setup()`:
	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);

So `RERERE_AUTOUPDATE` takes precedence over `RERERE_NOAUTOUPDATE`, but all callers know to only pass one of these flags. I agree though that we should detect this misuse and complain about it, it's certainly not obvious at all.

Patrick
Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 03/12] builtin/rerere: drop `the_repository`

There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Show changes to builtin/rerere.c +11 −13
diff --git a/builtin/rerere.c b/builtin/rerere.c
index a499e7b9151..83fb3783c61 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int autoupdate = -1, skip_locked = 0, flags = 0;
@@ -75,7 +73,7 @@ int cmd_rerere(int argc,
 	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
 		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
 
-	repo_config(the_repository, git_xmerge_config, NULL);
+	repo_config(repo, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
 		flags = RERERE_AUTOUPDATE;
@@ -83,7 +81,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return rerere(the_repository, flags);
+		return rerere(repo, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
@@ -94,21 +92,21 @@ int cmd_rerere(int argc,
 		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
 			       prefix, argv + 1);
 
-		ret = rerere_forget(the_repository, &pathspec);
+		ret = rerere_forget(repo, &pathspec);
 
 		clear_pathspec(&pathspec);
 		return ret;
 	}
 
 	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(the_repository, &merge_rr);
+		rerere_clear(repo, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr,
+		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				       flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
@@ -116,7 +114,7 @@ int cmd_rerere(int argc,
 
 		rerere_cache_release(&cache);
 	} else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(the_repository, &merge_rr);
+		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
 				printf("%s\n", merge_rr.items[i].string);
@@ -129,16 +127,16 @@ int cmd_rerere(int argc,
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				      flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
 			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
+			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
 				     path, path, path))
 				die(_("unable to generate diff for '%s'"),
-				    rerere_path(the_repository, &buf, id, NULL));
+				    rerere_path(repo, &buf, id, NULL));
 		}
 
 		rerere_cache_release(&cache);
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 04/12] builtin/rerere: stop passing flags to subcommands that ignore them

The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`.

This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/rerere.c +2 −2
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 83fb3783c61..405276cc94b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -107,7 +107,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
 			printf("%s\n", merge_rr.items[i].string);
@@ -128,7 +128,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				      flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:13 UTC · re: Patrick Steinhardt · lore

[PATCH v3 05/12] builtin/rerere: turn "forget" into a proper subcommand

The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work:

  - Options from other subcommands apply to each other.
  - We don't have proper usage strings.
  - Running `git rerere <subcmd> -h` doesn't print the options that are
    supported by that subcommand, but instead it just prints the help of
    git-rerere(1) itself.

A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Show changes to builtin/rerere.c +24 −14
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 405276cc94b..5d2ae154ff8 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_forget(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct pathspec pathspec;
+	int ret;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (!argc)
+		warning(_("'git rerere forget' without paths is deprecated"));
+	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+
+	ret = rerere_forget(repo, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -83,20 +105,8 @@ int cmd_rerere(int argc,
 	if (argc < 1)
 		return rerere(repo, flags);
 
-	if (!strcmp(argv[0], "forget")) {
-		struct pathspec pathspec;
-		int ret;
-
-		if (argc < 2)
-			warning(_("'git rerere forget' without paths is deprecated"));
-		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
-			       prefix, argv + 1);
-
-		ret = rerere_forget(repo, &pathspec);
-
-		clear_pathspec(&pathspec);
-		return ret;
-	}
+	if (!strcmp(argv[0], "forget"))
+		return cmd_rerere_forget(argc, argv, prefix, repo);
 
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(repo, &merge_rr);
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 06/12] builtin/rerere: turn "clear" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Show changes to builtin/rerere.c +22 −3
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 5d2ae154ff8..62f69b488b0 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_clear(int argc,
+			    const char **argv,
+			    const char *prefix,
+			    struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_clear(repo, &merge_rr);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -107,9 +127,8 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-
-	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(repo, &merge_rr);
+	else if (!strcmp(argv[0], "clear")) {
+		return cmd_rerere_clear(argc, argv, prefix, repo);
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 07/12] builtin/rerere: turn "status" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +29 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 62f69b488b0..2bcd270a1f1 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_status(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+	for (size_t i = 0; i < merge_rr.nr; i++)
+		printf("%s\n", merge_rr.items[i].string);
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	return 0;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -132,17 +158,9 @@ int cmd_rerere(int argc,
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-	else if (!strcmp(argv[0], "status")) {
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++)
-			printf("%s\n", merge_rr.items[i].string);
-
-		rerere_cache_release(&cache);
-	} else if (!strcmp(argv[0], "remaining")) {
+	else if (!strcmp(argv[0], "status"))
+		return cmd_rerere_status(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "remaining")) {
 		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 08/12] builtin/rerere: turn "remaining" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +31 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2bcd270a1f1..3f82bcbeb10 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_remaining(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_remaining(repo, &merge_rr);
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		if (merge_rr.items[i].util != RERERE_RESOLVED)
+			printf("%s\n", merge_rr.items[i].string);
+		else
+			/* prepare for later call to
+			 * string_list_clear() */
+			merge_rr.items[i].util = NULL;
+	}
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_status(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -160,17 +188,9 @@ int cmd_rerere(int argc,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(repo, &merge_rr);
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			if (merge_rr.items[i].util != RERERE_RESOLVED)
-				printf("%s\n", merge_rr.items[i].string);
-			else
-				/* prepare for later call to
-				 * string_list_clear() */
-				merge_rr.items[i].util = NULL;
-		}
-	} else if (!strcmp(argv[0], "diff")) {
+	else if (!strcmp(argv[0], "remaining"))
+		return cmd_rerere_remaining(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "diff")) {
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 09/12] builtin/rerere: turn "diff" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
Show changes to builtin/rerere.c +37 −19
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3f82bcbeb10..40bae5cb9cc 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,
 	return 0;
 }
 
+static int cmd_rerere_diff(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct strbuf buf = STRBUF_INIT;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		const char *path = merge_rr.items[i].string;
+		const struct rerere_id *id = merge_rr.items[i].util;
+		if (diff_two(rerere_path(repo, &buf, id, "preimage"), path, path, path))
+			die(_("unable to generate diff for '%s'"),
+			    rerere_path(repo, &buf, id, NULL));
+	}
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	strbuf_release(&buf);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -190,25 +224,9 @@ int cmd_rerere(int argc,
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
 		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff")) {
-		struct strbuf buf = STRBUF_INIT;
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			const char *path = merge_rr.items[i].string;
-			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
-				     path, path, path))
-				die(_("unable to generate diff for '%s'"),
-				    rerere_path(repo, &buf, id, NULL));
-		}
-
-		rerere_cache_release(&cache);
-		strbuf_release(&buf);
-	} else
+	else if (!strcmp(argv[0], "diff"))
+		return cmd_rerere_diff(argc, argv, prefix, repo);
+	else
 		usage_with_options(rerere_usage, options);
 
 	string_list_clear(&merge_rr, 1);
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 10/12] builtin/rerere: turn "gc" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
 t/t4200-rerere.sh |  5 -----
 2 files changed, 30 insertions(+), 18 deletions(-)
Show changes to 2 files +30 −18

builtin/rerere.c, t/t4200-rerere.sh

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 40bae5cb9cc..3162b074ec6 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_gc(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo)
+{
+	int skip_locked = 0;
+	struct option options[] = {
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+				N_("skip gc while another process holds the lock")),
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_gc(repo, &merge_rr,
+		  skip_locked ? RERERE_NOWAIT : 0);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -187,21 +211,16 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, skip_locked = 0, flags = 0;
+	int autoupdate = -1, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
-		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
-			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
-
-	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
-		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+	argc = parse_options(argc, argv, prefix, options, rerere_usage,
+			     PARSE_OPT_KEEP_UNKNOWN_OPT);
 
 	repo_config(repo, git_xmerge_config, NULL);
 
@@ -215,11 +234,10 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear")) {
+	else if (!strcmp(argv[0], "clear"))
 		return cmd_rerere_clear(argc, argv, prefix, repo);
-	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(repo, &merge_rr,
-			  skip_locked ? RERERE_NOWAIT : 0);
+	else if (!strcmp(argv[0], "gc"))
+		return cmd_rerere_gc(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
@@ -229,6 +247,5 @@ int cmd_rerere(int argc,
 	else
 		usage_with_options(rerere_usage, options);
 
-	string_list_clear(&merge_rr, 1);
 	return 0;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ab412ecc6e8..0d4cbf5114a 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
 	test_path_is_missing $rr2/preimage
 '
 
-test_expect_success '--skip-locked is only accepted by gc' '
-	test_must_fail git rerere --skip-locked clear 2>err &&
-	test_grep "option .--skip-locked. requires .gc." err
-'
-
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

In git-rerere(1) we have our own custom logic to parse subcommands. In preceding commits we have refactored all of those subcommands so that they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use these so that we get rid of our custom subcommand parsing.

Unfortunately this means that we have a backwards-incompatible change because we no longer accept the "--[no-]rerere-autoupdate" flag for all subcommands. But this was arguably broken and misleading as we ignore this flag for any other subcommand aynway. So we cheat a bit and simply call it a bug that those flags were accepted in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 28 deletions(-)
Show changes to builtin/rerere.c +56 −28
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3162b074ec6..97c791e420b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -5,6 +5,7 @@
 #include "rerere.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "strvec.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
 	return 0;
 }
 
+static int cmd_rerere_perform(int argc,
+			      const char **argv,
+			      const char *prefix,
+			      struct repository *repo)
+{
+	int autoupdate = -1;
+	struct option options[] = {
+		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+			N_("register clean resolutions in index"), 1),
+		OPT_END(),
+	};
+	enum rerere_flags flags = 0;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (autoupdate == 1)
+		flags = RERERE_AUTOUPDATE;
+	if (autoupdate == 0)
+		flags = RERERE_NOAUTOUPDATE;
+
+	return rerere(repo, flags);
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -211,41 +237,43 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	int autoupdate = -1, flags = 0;
-
+	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
-			N_("register clean resolutions in index"), 1),
+		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
+		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
+		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
+		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
+		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
+		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
-			     PARSE_OPT_KEEP_UNKNOWN_OPT);
-
+			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
 	repo_config(repo, git_xmerge_config, NULL);
 
-	if (autoupdate == 1)
-		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);
-
-	if (!strcmp(argv[0], "forget"))
-		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear"))
-		return cmd_rerere_clear(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "gc"))
-		return cmd_rerere_gc(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "status"))
-		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining"))
-		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff"))
-		return cmd_rerere_diff(argc, argv, prefix, repo);
-	else
-		usage_with_options(rerere_usage, options);
+		strvec_push(&args, "perform");
+		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);
+		COPY_ARRAY(args_copy, args.v, args.nr);
+
+		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
+
+		strvec_clear(&args);
+		free(args_copy);
+		return ret;
+	}
+
+	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 6, 2026, 15:14 UTC · re: Patrick Steinhardt · lore

[PATCH v3 12/12] builtin/rerere: introduce proper usage strings for subcommands

Adapt git-rerere(1) to have proper usage strings for each of the subcommands.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc |  8 +++++-
 builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 11 deletions(-)
Show changes to 2 files +58 −11

Documentation/git-rerere.adoc, builtin/rerere.c

diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index 4e6ab9a27c9..e04e9ef3ef8 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
 SYNOPSIS
 --------
 [verse]
-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
+'git rerere' [--[no-]rerere-autoupdate]
+'git rerere' clear
+'git rerere' diff
+'git rerere' forget <pathspec>...
+'git rerere' gc
+'git rerere' remaining
+'git rerere' status
 
 DESCRIPTION
 -----------
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 97c791e420b..051e50838ce 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -10,10 +10,13 @@
 #include "xdiff-interface.h"
 #include "pathspec.h"
 
-static const char * const rerere_usage[] = {
-	N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
-	NULL,
-};
+#define RERERE_USAGE N_("git rerere [--[no-]rerere-autoupdate]")
+#define RERERE_CLEAR_USAGE N_("git rerere clear")
+#define RERERE_DIFF_USAGE N_("git rerere diff")
+#define RERERE_FORGET_USAGE N_("git rerere forget <pathspec>...")
+#define RERERE_GC_USAGE N_("git rerere gc")
+#define RERERE_REMAINING_USAGE N_("git rerere remaining")
+#define RERERE_STATUS_USAGE N_("git rerere status")
 
 static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)
 {
@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_clear_usage[] = {
+		RERERE_CLEAR_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_diff_usage[] = {
+		RERERE_DIFF_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_forget_usage[] = {
+		RERERE_FORGET_USAGE,
+		NULL,
+	};
 	struct pathspec pathspec;
 	int ret;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);
 	if (!argc)
 		warning(_("'git rerere forget' without paths is deprecated"));
 	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,
 				N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
+	const char * const rerere_gc_usage[] = {
+		RERERE_GC_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,
 			N_("register clean resolutions in index"), 1),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		NULL,
+	};
 	enum rerere_flags flags = 0;
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_remaining_usage[] = {
+		RERERE_REMAINING_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_status_usage[] = {
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -247,6 +278,16 @@ int cmd_rerere(int argc,
 		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		RERERE_CLEAR_USAGE,
+		RERERE_DIFF_USAGE,
+		RERERE_FORGET_USAGE,
+		RERERE_GC_USAGE,
+		RERERE_REMAINING_USAGE,
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
-- 
2.56.0.500.g5d06dc02cd.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 00/12] builtin/rerere: convert to use subcommands

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 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.im
Changes 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 (12):
      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.adoc |   8 +-
 apply.c                       |   2 +-
 builtin/am.c                  |   4 +-
 builtin/commit.c              |   2 +-
 builtin/merge.c               |   2 +-
 builtin/rerere.c              | 319 ++++++++++++++++++++++++++++++++----------
 builtin/stash.c               |   2 +-
 rerere.c                      |  14 +-
 rerere.h                      |  43 ++++--
 sequencer.c                   |   4 +-
 t/t4200-rerere.sh             |   5 -
 11 files changed, 299 insertions(+), 106 deletions(-)
Range-diff versus v3:
 1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`
 2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum
    @@ Commit message
         around as enums so that it becomes trivial to see what kind of flags are
         expected. Adapt the rerere flags accordingly and document them.
     
    +    While at it, detect the case where both `RERERE_AUTOUPDATE` and
    +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot
    +    of sense, and it's not obvious which of those flags takes precedence
    +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of
    +    those flags, but let's be safe rather than sorry and `BUG()` in case
    +    both are passed.
    +
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## rerere.c ##
    @@ rerere.c: static int is_rerere_enabled(struct repository *r)
      {
      	int lock_timeout_ms = 1000;
      	int fd;
    +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
    + 	repo_config_get_bool(r, "rerere.autoupdate", &cache->autoupdate);
    + 	repo_config_get_int(r, "rerere.locktimeout", &lock_timeout_ms);
    + 
    ++	if ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))
    ++		BUG("RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE");
    + 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
    + 		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);
    + 	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
     @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
      	return fd;
      }
    @@ rerere.h: struct rerere_id {
     +	RERERE_AUTOUPDATE = (1 << 0),
     +
     +	/*
    -+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
    -+	 * working tree but don't touch the index.
    ++	 * 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
    ++	 * invalid to pass both flags at the same time.
     +	 */
     +	RERERE_NOAUTOUPDATE = (1 << 1),
     +
 3:  99faad47068 =  3:  48692c2c88d builtin/rerere: drop `the_repository`
 4:  f164c482227 =  4:  e76991dd39d builtin/rerere: stop passing flags to subcommands that ignore them
 5:  0573d2323e8 =  5:  2474dca4713 builtin/rerere: turn "forget" into a proper subcommand
 6:  2098dedf4fd =  6:  cecdbb1c63b builtin/rerere: turn "clear" into a proper subcommand
 7:  e8eaa2b4092 =  7:  54fc766f9d2 builtin/rerere: turn "status" into a proper subcommand
 8:  a5781284b8b =  8:  fa2c839b2cb builtin/rerere: turn "remaining" into a proper subcommand
 9:  9a4278df0ea =  9:  416b8311ca9 builtin/rerere: turn "diff" into a proper subcommand
10:  e63b9be0d74 = 10:  adb2b68f833 builtin/rerere: turn "gc" into a proper subcommand
11:  47889896ecb = 11:  a12e19cb2e8 builtin/rerere: use `OPT_SUBCOMMAND()`
12:  5e16a247b49 = 12:  4b1b6170ba3 builtin/rerere: introduce proper usage strings for subcommands

--- base-commit: 710910c03a22ac663885049213b9fef5853ea8e0 change-id: 20261027-pks-rerere-subcommands-318d41553438

Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 01/12] rerere: rename `repo_rerere()`

The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix.

Rename the function to just `rerere()`. Move around and extend documentation of this function to better explain what it does.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 apply.c          | 2 +-
 builtin/am.c     | 4 ++--
 builtin/commit.c | 2 +-
 builtin/merge.c  | 2 +-
 builtin/rerere.c | 2 +-
 builtin/stash.c  | 2 +-
 rerere.c         | 7 +------
 rerere.h         | 9 ++++++++-
 sequencer.c      | 4 ++--
 9 files changed, 18 insertions(+), 16 deletions(-)
Show changes to 9 files +18 −16

apply.c, builtin/am.c, builtin/commit.c, builtin/merge.c, builtin/rerere.c, builtin/stash.c, rerere.c, rerere.h, sequencer.c

diff --git a/apply.c b/apply.c
index a0b7119c639..646fabeafa3 100644
--- a/apply.c
+++ b/apply.c
@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		 * tree with conflict markers, but that isn't written with --cached.
 		 */
 		if (!state->cached)
-			repo_rerere(state->repo, 0);
+			rerere(state->repo, 0);
 	}
 
 	return errs;
diff --git a/builtin/am.c b/builtin/am.c
index e9623b83077..4a5b37bee00 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		o.verbosity = 0;
 
 	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-		repo_rerere(the_repository, state->allow_rerere_autoupdate);
+		rerere(the_repository, state->allow_rerere_autoupdate);
 		free(their_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
 			goto next;
 	}
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 
 	do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8ffd42681bb..3a4b94ad623 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,
 
 	git_test_write_commit_graph_or_die(the_repository);
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 	run_auto_maintenance(the_repository, quiet);
 	run_commit_hook(use_editor, repo_get_index_file(the_repository),
 			NULL, "post-commit", NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index d7bf209114f..089e36e8575 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
-	repo_rerere(the_repository, allow_rerere_auto);
+	rerere(the_repository, allow_rerere_auto);
 	printf(_("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n"));
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2c17f02f56d..a499e7b9151 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -83,7 +83,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return repo_rerere(the_repository, flags);
+		return rerere(the_repository, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
diff --git a/builtin/stash.c b/builtin/stash.c
index e1a3a76bd04..91870a255fd 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
 		ret = error(_("could not write index"));
 
 	if (ret) {
-		repo_rerere(the_repository, 0);
+		rerere(the_repository, 0);
 
 		if (index)
 			fprintf_ln(stderr, _("Index was not unstashed."));
diff --git a/rerere.c b/rerere.c
index e0897612085..47a4a325bf5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-/*
- * The main entry point that is called internally from codepaths that
- * perform mergy operations, possibly leaving conflicted index entries
- * and working tree files.
- */
-int repo_rerere(struct repository *r, int flags)
+int rerere(struct repository *r, int flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
diff --git a/rerere.h b/rerere.h
index d3cbd10e13f..dd9da03d6db 100644
--- a/rerere.h
+++ b/rerere.h
@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,
 		       int flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int repo_rerere(struct repository *, int);
+/*
+ * The main entry point that is called internally from codepaths that
+ * perform mergy operations, possibly leaving conflicted index entries
+ * and working tree files. It records (and optionally updates) resolved
+ * conflicts and reuses recorded resolutions for unresolved conflicts.
+ */
+int rerere(struct repository *r, int flags);
+
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
diff --git a/sequencer.c b/sequencer.c
index 508ec717920..ace1cfac1cb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,
 		      : _("could not apply %s... %s"),
 		      short_commit_name(r, commit), msg.subject);
 		print_advice(r, res == 1, opts);
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 		goto leave;
 	}
 
@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,
 
 	rollback_lock_file(&lock);
 	if (ret)
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 	else
 		/*
 		 * In case of problems, we now want to return a positive
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 02/12] rerere: convert flags into an enum

Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly and document them.

While at it, detect the case where both `RERERE_AUTOUPDATE` and `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot of sense, and it's not obvious which of those flags takes precedence (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of those flags, but let's be safe rather than sorry and `BUG()` in case both are passed.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 rerere.c |  9 ++++++---
 rerere.h | 36 +++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 12 deletions(-)
Show changes to 2 files +33 −12

rerere.c, rerere.h

diff --git a/rerere.c b/rerere.c
index 47a4a325bf5..47d9077eeca 100644
--- a/rerere.c
+++ b/rerere.c
@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags)
+		       enum rerere_flags flags)
 {
 	int lock_timeout_ms = 1000;
 	int fd;
@@ -922,6 +922,8 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	repo_config_get_bool(r, "rerere.autoupdate", &cache->autoupdate);
 	repo_config_get_int(r, "rerere.locktimeout", &lock_timeout_ms);
 
+	if ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))
+		BUG("RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE");
 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
 		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);
 	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
@@ -951,7 +953,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-int rerere(struct repository *r, int flags)
+int rerere(struct repository *r, enum rerere_flags flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
@@ -1336,7 +1338,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr, int flags)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_flags flags)
 {
 	struct rerere_cache cache;
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
diff --git a/rerere.h b/rerere.h
index dd9da03d6db..10b25018c0e 100644
--- a/rerere.h
+++ b/rerere.h
@@ -9,12 +9,6 @@
 struct pathspec;
 struct repository;
 
-#define RERERE_AUTOUPDATE   01
-#define RERERE_NOAUTOUPDATE 02
-#define RERERE_READONLY     04
-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
-#define RERERE_NOWAIT       010
-
 /*
  * Marks paths that have been hand-resolved and added to the
  * index. Set in the util field of such paths after calling
@@ -39,10 +33,33 @@ struct rerere_id {
 	int variant;
 };
 
+enum rerere_flags {
+	/*
+	 * Auto-update the index with previously recorded resolutions. This can
+	 * be used to explicitly override "rerere.autoUpdate".
+	 */
+	RERERE_AUTOUPDATE = (1 << 0),
+
+	/*
+	 * 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
+	 * invalid to pass both flags at the same time.
+	 */
+	RERERE_NOAUTOUPDATE = (1 << 1),
+
+	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
+	RERERE_READONLY = (1 << 2),
+
+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
+	RERERE_NOWAIT = (1 << 3),
+};
+
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags);
+		       enum rerere_flags flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
 /*
@@ -51,7 +68,7 @@ void rerere_cache_release(struct rerere_cache *cache);
  * and working tree files. It records (and optionally updates) resolved
  * conflicts and reuses recorded resolutions for unresolved conflicts.
  */
-int rerere(struct repository *r, int flags);
+int rerere(struct repository *r, enum rerere_flags flags);
 
 /*
  * Given the conflict ID and the name of a "file" used for replaying
@@ -65,7 +82,8 @@ const char *rerere_path(struct repository *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *, int);
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 03/12] builtin/rerere: drop `the_repository`

There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Show changes to builtin/rerere.c +11 −13
diff --git a/builtin/rerere.c b/builtin/rerere.c
index a499e7b9151..83fb3783c61 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int autoupdate = -1, skip_locked = 0, flags = 0;
@@ -75,7 +73,7 @@ int cmd_rerere(int argc,
 	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
 		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
 
-	repo_config(the_repository, git_xmerge_config, NULL);
+	repo_config(repo, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
 		flags = RERERE_AUTOUPDATE;
@@ -83,7 +81,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return rerere(the_repository, flags);
+		return rerere(repo, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
@@ -94,21 +92,21 @@ int cmd_rerere(int argc,
 		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
 			       prefix, argv + 1);
 
-		ret = rerere_forget(the_repository, &pathspec);
+		ret = rerere_forget(repo, &pathspec);
 
 		clear_pathspec(&pathspec);
 		return ret;
 	}
 
 	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(the_repository, &merge_rr);
+		rerere_clear(repo, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr,
+		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				       flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
@@ -116,7 +114,7 @@ int cmd_rerere(int argc,
 
 		rerere_cache_release(&cache);
 	} else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(the_repository, &merge_rr);
+		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
 				printf("%s\n", merge_rr.items[i].string);
@@ -129,16 +127,16 @@ int cmd_rerere(int argc,
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				      flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
 			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
+			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
 				     path, path, path))
 				die(_("unable to generate diff for '%s'"),
-				    rerere_path(the_repository, &buf, id, NULL));
+				    rerere_path(repo, &buf, id, NULL));
 		}
 
 		rerere_cache_release(&cache);
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 04/12] builtin/rerere: stop passing flags to subcommands that ignore them

The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`.

This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/rerere.c +2 −2
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 83fb3783c61..405276cc94b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -107,7 +107,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
 			printf("%s\n", merge_rr.items[i].string);
@@ -128,7 +128,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				      flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 05/12] builtin/rerere: turn "forget" into a proper subcommand

The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work:

  - Options from other subcommands apply to each other.
  - We don't have proper usage strings.
  - Running `git rerere <subcmd> -h` doesn't print the options that are
    supported by that subcommand, but instead it just prints the help of
    git-rerere(1) itself.

A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Show changes to builtin/rerere.c +24 −14
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 405276cc94b..5d2ae154ff8 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_forget(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct pathspec pathspec;
+	int ret;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (!argc)
+		warning(_("'git rerere forget' without paths is deprecated"));
+	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+
+	ret = rerere_forget(repo, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -83,20 +105,8 @@ int cmd_rerere(int argc,
 	if (argc < 1)
 		return rerere(repo, flags);
 
-	if (!strcmp(argv[0], "forget")) {
-		struct pathspec pathspec;
-		int ret;
-
-		if (argc < 2)
-			warning(_("'git rerere forget' without paths is deprecated"));
-		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
-			       prefix, argv + 1);
-
-		ret = rerere_forget(repo, &pathspec);
-
-		clear_pathspec(&pathspec);
-		return ret;
-	}
+	if (!strcmp(argv[0], "forget"))
+		return cmd_rerere_forget(argc, argv, prefix, repo);
 
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(repo, &merge_rr);
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 06/12] builtin/rerere: turn "clear" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Show changes to builtin/rerere.c +22 −3
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 5d2ae154ff8..62f69b488b0 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_clear(int argc,
+			    const char **argv,
+			    const char *prefix,
+			    struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_clear(repo, &merge_rr);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -107,9 +127,8 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-
-	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(repo, &merge_rr);
+	else if (!strcmp(argv[0], "clear")) {
+		return cmd_rerere_clear(argc, argv, prefix, repo);
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 07/12] builtin/rerere: turn "status" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +29 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 62f69b488b0..2bcd270a1f1 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_status(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+	for (size_t i = 0; i < merge_rr.nr; i++)
+		printf("%s\n", merge_rr.items[i].string);
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	return 0;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -132,17 +158,9 @@ int cmd_rerere(int argc,
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-	else if (!strcmp(argv[0], "status")) {
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++)
-			printf("%s\n", merge_rr.items[i].string);
-
-		rerere_cache_release(&cache);
-	} else if (!strcmp(argv[0], "remaining")) {
+	else if (!strcmp(argv[0], "status"))
+		return cmd_rerere_status(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "remaining")) {
 		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 08/12] builtin/rerere: turn "remaining" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +31 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2bcd270a1f1..3f82bcbeb10 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_remaining(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_remaining(repo, &merge_rr);
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		if (merge_rr.items[i].util != RERERE_RESOLVED)
+			printf("%s\n", merge_rr.items[i].string);
+		else
+			/* prepare for later call to
+			 * string_list_clear() */
+			merge_rr.items[i].util = NULL;
+	}
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_status(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -160,17 +188,9 @@ int cmd_rerere(int argc,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(repo, &merge_rr);
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			if (merge_rr.items[i].util != RERERE_RESOLVED)
-				printf("%s\n", merge_rr.items[i].string);
-			else
-				/* prepare for later call to
-				 * string_list_clear() */
-				merge_rr.items[i].util = NULL;
-		}
-	} else if (!strcmp(argv[0], "diff")) {
+	else if (!strcmp(argv[0], "remaining"))
+		return cmd_rerere_remaining(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "diff")) {
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-- 
2.56.0.611.g1030f0b940.dirty
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 09/12] builtin/rerere: turn "diff" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
Show changes to builtin/rerere.c +37 −19
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3f82bcbeb10..40bae5cb9cc 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,
 	return 0;
 }
 
+static int cmd_rerere_diff(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct strbuf buf = STRBUF_INIT;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		const char *path = merge_rr.items[i].string;
+		const struct rerere_id *id = merge_rr.items[i].util;
+		if (diff_two(rerere_path(repo, &buf, id, "preimage"), path, path, path))
+			die(_("unable to generate diff for '%s'"),
+			    rerere_path(repo, &buf, id, NULL));
+	}
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	strbuf_release(&buf);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -190,25 +224,9 @@ int cmd_rerere(int argc,
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
 		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff")) {
-		struct strbuf buf = STRBUF_INIT;
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			const char *path = merge_rr.items[i].string;
-			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
-				     path, path, path))
-				die(_("unable to generate diff for '%s'"),
-				    rerere_path(repo, &buf, id, NULL));
-		}
-
-		rerere_cache_release(&cache);
-		strbuf_release(&buf);
-	} else
+	else if (!strcmp(argv[0], "diff"))
+		return cmd_rerere_diff(argc, argv, prefix, repo);
+	else
 		usage_with_options(rerere_usage, options);
 
 	string_list_clear(&merge_rr, 1);
-- 
2.56.0.611.g1030f0b940.dirty
Junio C Hamano· Nov 17, 2026, 01:37 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 09/12] builtin/rerere: turn "diff" into a proper subcommand

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> +static int cmd_rerere_diff(int argc,
> +			   const char **argv,
> +			   const char *prefix,
> +			   struct repository *repo)
> +{
> +	struct option options[] = {
> +		OPT_END(),
> +	};
> +	struct string_list merge_rr = STRING_LIST_INIT_DUP;
> +	struct strbuf buf = STRBUF_INIT;
> +	struct rerere_cache cache;
> +
> +	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
> +	if (argc)
> +		usage(_("too many arguments"));

We will make a mental note that "rerere diff" does not take any extra arguments.

This matters when we look at the documentation patch later.
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 10/12] builtin/rerere: turn "gc" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
 t/t4200-rerere.sh |  5 -----
 2 files changed, 30 insertions(+), 18 deletions(-)
Show changes to 2 files +30 −18

builtin/rerere.c, t/t4200-rerere.sh

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 40bae5cb9cc..3162b074ec6 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_gc(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo)
+{
+	int skip_locked = 0;
+	struct option options[] = {
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+				N_("skip gc while another process holds the lock")),
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_gc(repo, &merge_rr,
+		  skip_locked ? RERERE_NOWAIT : 0);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -187,21 +211,16 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, skip_locked = 0, flags = 0;
+	int autoupdate = -1, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
-		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
-			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
-
-	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
-		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+	argc = parse_options(argc, argv, prefix, options, rerere_usage,
+			     PARSE_OPT_KEEP_UNKNOWN_OPT);
 
 	repo_config(repo, git_xmerge_config, NULL);
 
@@ -215,11 +234,10 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear")) {
+	else if (!strcmp(argv[0], "clear"))
 		return cmd_rerere_clear(argc, argv, prefix, repo);
-	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(repo, &merge_rr,
-			  skip_locked ? RERERE_NOWAIT : 0);
+	else if (!strcmp(argv[0], "gc"))
+		return cmd_rerere_gc(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
@@ -229,6 +247,5 @@ int cmd_rerere(int argc,
 	else
 		usage_with_options(rerere_usage, options);
 
-	string_list_clear(&merge_rr, 1);
 	return 0;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ab412ecc6e8..0d4cbf5114a 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
 	test_path_is_missing $rr2/preimage
 '
 
-test_expect_success '--skip-locked is only accepted by gc' '
-	test_must_fail git rerere --skip-locked clear 2>err &&
-	test_grep "option .--skip-locked. requires .gc." err
-'
-
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
-- 
2.56.0.611.g1030f0b940.dirty
Junio C Hamano· Nov 17, 2026, 01:21 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 10/12] builtin/rerere: turn "gc" into a proper subcommand

Patrick Steinhardt <ps@pks.im> writes:
> As explained in a preceding commit, a subsequent commit will introduce
> proper subcommands as supported by our parse-options subsystem. Refactor
> the "gc" subcommand to use parse-options as a preparatory step.

Even though the cover letter may have mentioned it, this should also describe the deliberate UI regression to help future readers of "git log". When they see a bug report on the mailing list and bisect leads to this commit, it makes a huge difference if you tell them that the change in behavior was deliberate, with a clear reason explained in the log message. Otherwise they would say "the UI regressed with this commit without explaining why it was thought to be a good idea. The commit unceremoniously drops a test that points out this exact regression".

Show 5 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
>  t/t4200-rerere.sh |  5 -----
>  2 files changed, 30 insertions(+), 18 deletions(-)
Show 16 quoted lines
> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
> index ab412ecc6e8..0d4cbf5114a 100755
> --- a/t/t4200-rerere.sh
> +++ b/t/t4200-rerere.sh
> @@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
>  	test_path_is_missing $rr2/preimage
>  '
>  
> -test_expect_success '--skip-locked is only accepted by gc' '
> -	test_must_fail git rerere --skip-locked clear 2>err &&
> -	test_grep "option .--skip-locked. requires .gc." err
> -'
> -
>  test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
>  	git reset --hard &&
>  	rm -rf $rr &&
Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

In git-rerere(1) we have our own custom logic to parse subcommands. In preceding commits we have refactored all of those subcommands so that they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use these so that we get rid of our custom subcommand parsing.

Unfortunately this means that we have a backwards-incompatible change because we no longer accept the "--[no-]rerere-autoupdate" flag for all subcommands. But this was arguably broken and misleading as we ignore this flag for any other subcommand aynway. So we cheat a bit and simply call it a bug that those flags were accepted in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 28 deletions(-)
Show changes to builtin/rerere.c +56 −28
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3162b074ec6..97c791e420b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -5,6 +5,7 @@
 #include "rerere.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "strvec.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
 	return 0;
 }
 
+static int cmd_rerere_perform(int argc,
+			      const char **argv,
+			      const char *prefix,
+			      struct repository *repo)
+{
+	int autoupdate = -1;
+	struct option options[] = {
+		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+			N_("register clean resolutions in index"), 1),
+		OPT_END(),
+	};
+	enum rerere_flags flags = 0;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (autoupdate == 1)
+		flags = RERERE_AUTOUPDATE;
+	if (autoupdate == 0)
+		flags = RERERE_NOAUTOUPDATE;
+
+	return rerere(repo, flags);
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -211,41 +237,43 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	int autoupdate = -1, flags = 0;
-
+	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
-			N_("register clean resolutions in index"), 1),
+		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
+		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
+		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
+		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
+		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
+		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
-			     PARSE_OPT_KEEP_UNKNOWN_OPT);
-
+			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
 	repo_config(repo, git_xmerge_config, NULL);
 
-	if (autoupdate == 1)
-		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);
-
-	if (!strcmp(argv[0], "forget"))
-		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear"))
-		return cmd_rerere_clear(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "gc"))
-		return cmd_rerere_gc(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "status"))
-		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining"))
-		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff"))
-		return cmd_rerere_diff(argc, argv, prefix, repo);
-	else
-		usage_with_options(rerere_usage, options);
+		strvec_push(&args, "perform");
+		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);
+		COPY_ARRAY(args_copy, args.v, args.nr);
+
+		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
+
+		strvec_clear(&args);
+		free(args_copy);
+		return ret;
+	}
+
+	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.0.611.g1030f0b940.dirty
Junio C Hamano· Nov 17, 2026, 01:28 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> In git-rerere(1) we have our own custom logic to parse subcommands. In
> preceding commits we have refactored all of those subcommands so that
> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use
> these so that we get rid of our custom subcommand parsing.
>
> Unfortunately this means that we have a backwards-incompatible change
> because we no longer accept the "--[no-]rerere-autoupdate" flag for all
> subcommands. But this was arguably broken and misleading as we ignore
> this flag for any other subcommand aynway. So we cheat a bit and simply
> call it a bug that those flags were accepted in the first place.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 56 insertions(+), 28 deletions(-)
I already mentioned

$ rungit master rerere unknown usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]

    --[no-]rerere-autoupdate
                          register clean resolutions in index
vs

$ rungit seen rerere unknown usage: too many arguments

and it is this step that may be responsible for some of it.
Show 33 quoted lines
> @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
>  	       const char *prefix,
>  	       struct repository *repo)
>  {
> +	parse_opt_subcommand_fn *fn = NULL;
> +		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
> +		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
> +		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
> +		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
> +		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
> +		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
>  		OPT_END(),
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, options, rerere_usage,
> +			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
>  	repo_config(repo, git_xmerge_config, NULL);
>  
> +	if (!fn) {
> +		struct strvec args = STRVEC_INIT;
> +		const char **args_copy;
> +		int ret;
>  
> +		strvec_push(&args, "perform");
> +		strvec_pushv(&args, argv);
>  
> +		/*
> +		 * 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);
> +		COPY_ARRAY(args_copy, args.v, args.nr);

Does args.nr count the terminating NULL pointer? We mimic the familiar (ac, av) convention of the C language; av[ac] being NULL is also part of the convention, so if CALLOC_ARRAY() is not allocating an entry for the terminating NULL and COPY_ARRAY() is not copying args together with the NULL, this may want to be corrected.

Show 9 quoted lines
> +		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
> +
> +		strvec_clear(&args);
> +		free(args_copy);
> +		return ret;
> +	}
> +
> +	return fn(argc, argv, prefix, repo);
>  }
Patrick Steinhardt· Nov 18, 2026, 14:09 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

On Mon, Nov 16, 2026 at 05:28:32PM -0800, Junio C Hamano wrote:
Show 32 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > In git-rerere(1) we have our own custom logic to parse subcommands. In
> > preceding commits we have refactored all of those subcommands so that
> > they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use
> > these so that we get rid of our custom subcommand parsing.
> >
> > Unfortunately this means that we have a backwards-incompatible change
> > because we no longer accept the "--[no-]rerere-autoupdate" flag for all
> > subcommands. But this was arguably broken and misleading as we ignore
> > this flag for any other subcommand aynway. So we cheat a bit and simply
> > call it a bug that those flags were accepted in the first place.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> >  builtin/rerere.c | 84 +++++++++++++++++++++++++++++++++++++-------------------
> >  1 file changed, 56 insertions(+), 28 deletions(-)
> 
> I already mentioned
> 
> $ rungit master rerere unknown
> usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
> 
>     --[no-]rerere-autoupdate
>                           register clean resolutions in index
> 
> vs
> 
> $ rungit seen rerere unknown
> usage: too many arguments
> 
> and it is this step that may be responsible for some of it.

Right, but isn't this actually an improvement? It's exactly the same way that other commands with optional subcommands behave, e.g.:

    $ git submodule
    -855827c583bc30645ba427885caa40c5b81764d2 sha1collisiondetection
    $ git submodule unknown
    usage: git submodule [--quiet] [--cached]
       or: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]

Ooh, no, it's the exact _other_ way round. We used to print the synopsis, now we print "too many arguments". That's annoying and a regression indeed. Will fix.

Show 39 quoted lines
> > @@ -211,41 +237,43 @@ int cmd_rerere(int argc,
> >  	       const char *prefix,
> >  	       struct repository *repo)
> >  {
> > +	parse_opt_subcommand_fn *fn = NULL;
> > +		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
> > +		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
> > +		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
> > +		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
> > +		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
> > +		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
> >  		OPT_END(),
> >  	};
> >  
> >  	argc = parse_options(argc, argv, prefix, options, rerere_usage,
> > +			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
> >  	repo_config(repo, git_xmerge_config, NULL);
> >  
> > +	if (!fn) {
> > +		struct strvec args = STRVEC_INIT;
> > +		const char **args_copy;
> > +		int ret;
> >  
> > +		strvec_push(&args, "perform");
> > +		strvec_pushv(&args, argv);
> >  
> > +		/*
> > +		 * 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);
> > +		COPY_ARRAY(args_copy, args.v, args.nr);
> 
> Does args.nr count the terminating NULL pointer?  We mimic the
> familiar (ac, av) convention of the C language; av[ac] being NULL is
> also part of the convention, so if CALLOC_ARRAY() is not allocating
> an entry for the terminating NULL and COPY_ARRAY() is not copying
> args together with the NULL, this may want to be corrected.

That's a good point indeed. It likely doesn't matter, but better be safe than sorry. Will adapt.

Patrick
Junio C Hamano· Nov 18, 2026, 17:02 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 11/12] builtin/rerere: use `OPT_SUBCOMMAND()`

Patrick Steinhardt <ps@pks.im> writes:
Show 11 quoted lines
>> > +		CALLOC_ARRAY(args_copy, args.nr);
>> > +		COPY_ARRAY(args_copy, args.v, args.nr);
>> 
>> Does args.nr count the terminating NULL pointer?  We mimic the
>> familiar (ac, av) convention of the C language; av[ac] being NULL is
>> also part of the convention, so if CALLOC_ARRAY() is not allocating
>> an entry for the terminating NULL and COPY_ARRAY() is not copying
>> args together with the NULL, this may want to be corrected.
>
> That's a good point indeed. It likely doesn't matter, but better be safe
> than sorry. Will adapt.

The COPY_ARRAY() call can stay as-is. CALLOC_ARRAY() needs to allocate one more element.

Patrick Steinhardt· Nov 11, 2026, 12:18 UTC · re: Patrick Steinhardt · lore

[PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands

Adapt git-rerere(1) to have proper usage strings for each of the subcommands.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc |  8 +++++-
 builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 11 deletions(-)
Show changes to 2 files +58 −11

Documentation/git-rerere.adoc, builtin/rerere.c

diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index 4e6ab9a27c9..e04e9ef3ef8 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
 SYNOPSIS
 --------
 [verse]
-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
+'git rerere' [--[no-]rerere-autoupdate]
+'git rerere' clear
+'git rerere' diff
+'git rerere' forget <pathspec>...
+'git rerere' gc
+'git rerere' remaining
+'git rerere' status
 
 DESCRIPTION
 -----------
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 97c791e420b..051e50838ce 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -10,10 +10,13 @@
 #include "xdiff-interface.h"
 #include "pathspec.h"
 
-static const char * const rerere_usage[] = {
-	N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
-	NULL,
-};
+#define RERERE_USAGE N_("git rerere [--[no-]rerere-autoupdate]")
+#define RERERE_CLEAR_USAGE N_("git rerere clear")
+#define RERERE_DIFF_USAGE N_("git rerere diff")
+#define RERERE_FORGET_USAGE N_("git rerere forget <pathspec>...")
+#define RERERE_GC_USAGE N_("git rerere gc")
+#define RERERE_REMAINING_USAGE N_("git rerere remaining")
+#define RERERE_STATUS_USAGE N_("git rerere status")
 
 static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)
 {
@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_clear_usage[] = {
+		RERERE_CLEAR_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_diff_usage[] = {
+		RERERE_DIFF_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_forget_usage[] = {
+		RERERE_FORGET_USAGE,
+		NULL,
+	};
 	struct pathspec pathspec;
 	int ret;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);
 	if (!argc)
 		warning(_("'git rerere forget' without paths is deprecated"));
 	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,
 				N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
+	const char * const rerere_gc_usage[] = {
+		RERERE_GC_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,
 			N_("register clean resolutions in index"), 1),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		NULL,
+	};
 	enum rerere_flags flags = 0;
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_remaining_usage[] = {
+		RERERE_REMAINING_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_status_usage[] = {
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -247,6 +278,16 @@ int cmd_rerere(int argc,
 		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		RERERE_CLEAR_USAGE,
+		RERERE_DIFF_USAGE,
+		RERERE_FORGET_USAGE,
+		RERERE_GC_USAGE,
+		RERERE_REMAINING_USAGE,
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
-- 
2.56.0.611.g1030f0b940.dirty
Junio C Hamano· Nov 17, 2026, 01:37 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 19 quoted lines
> diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
> index 4e6ab9a27c9..e04e9ef3ef8 100644
> --- a/Documentation/git-rerere.adoc
> +++ b/Documentation/git-rerere.adoc
> @@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
>  SYNOPSIS
>  --------
>  [verse]
> -'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
> +'git rerere' [--[no-]rerere-autoupdate]
> +'git rerere' clear
> +'git rerere' diff
> +'git rerere' forget <pathspec>...
> +'git rerere' gc
> +'git rerere' remaining
> +'git rerere' status
>  
>  DESCRIPTION
>  -----------

The above is consistent with [9/12] where we saw that the command barfs if you say 'git rerere diff blurb'.

Yet, the documentation contradicts with the behaviour.
    'diff'::
    Display diffs for the current state of the resolution.  It is
    useful for tracking what has changed while the user is resolving
    conflicts.  Additional arguments are passed directly to the system
    'diff' command installed in PATH.

We do not take additional arguments. We do not pass anything to the system `diff` command installed in PATH. It was a behaviour change left undocumented ever since 658f365027 (Make git-rerere a builtin, 2006-12-20) was done.

Patrick Steinhardt· Nov 18, 2026, 14:09 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 12/12] builtin/rerere: introduce proper usage strings for subcommands

On Mon, Nov 16, 2026 at 05:37:43PM -0800, Junio C Hamano wrote:
Show 38 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
> > index 4e6ab9a27c9..e04e9ef3ef8 100644
> > --- a/Documentation/git-rerere.adoc
> > +++ b/Documentation/git-rerere.adoc
> > @@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
> >  SYNOPSIS
> >  --------
> >  [verse]
> > -'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
> > +'git rerere' [--[no-]rerere-autoupdate]
> > +'git rerere' clear
> > +'git rerere' diff
> > +'git rerere' forget <pathspec>...
> > +'git rerere' gc
> > +'git rerere' remaining
> > +'git rerere' status
> >  
> >  DESCRIPTION
> >  -----------
> 
> The above is consistent with [9/12] where we saw that the command
> barfs if you say 'git rerere diff blurb'.
> 
> Yet, the documentation contradicts with the behaviour.
> 
>     'diff'::
> 
>     Display diffs for the current state of the resolution.  It is
>     useful for tracking what has changed while the user is resolving
>     conflicts.  Additional arguments are passed directly to the system
>     'diff' command installed in PATH.
> 
> We do not take additional arguments.  We do not pass anything to the
> system `diff` command installed in PATH.  It was a behaviour change
> left undocumented ever since 658f365027 (Make git-rerere a builtin,
> 2006-12-20) was done.

Huh, interesting indeed. I'll include another patch to fix that while we're here already.

Patrick
Karthik Nayak· Nov 12, 2026, 13:41 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> 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 v4:
>   - Some more polishing for `RERERE_{NO,}AUTOUPDATE` documentation.
>   - Die in case both of these flags are passed.
Definitely a welcome improvement!
Show 14 quoted lines
>   - Link to v3: https://patch.msgid.link/20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im
>
> Changes 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
[snip]
Show 41 quoted lines
> Range-diff versus v3:
>
>  1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`
>  2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum
>     @@ Commit message
>          around as enums so that it becomes trivial to see what kind of flags are
>          expected. Adapt the rerere flags accordingly and document them.
>
>     +    While at it, detect the case where both `RERERE_AUTOUPDATE` and
>     +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot
>     +    of sense, and it's not obvious which of those flags takes precedence
>     +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of
>     +    those flags, but let's be safe rather than sorry and `BUG()` in case
>     +    both are passed.
>     +
>          Signed-off-by: Patrick Steinhardt <ps@pks.im>
>
>       ## rerere.c ##
>     @@ rerere.c: static int is_rerere_enabled(struct repository *r)
>       {
>       	int lock_timeout_ms = 1000;
>       	int fd;
>     +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
>     + 	repo_config_get_bool(r, "rerere.autoupdate", &cache->autoupdate);
>     + 	repo_config_get_int(r, "rerere.locktimeout", &lock_timeout_ms);
>     +
>     ++	if ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))
>     ++		BUG("RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE");
>     + 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
>     + 		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);
>     + 	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
>      @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
>       	return fd;
>       }
>     @@ rerere.h: struct rerere_id {
>      +	RERERE_AUTOUPDATE = (1 << 0),
>      +
>      +	/*
>     -+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
>     -+	 * working tree but don't touch the index.
>     ++	 * update the file in the working tree but don't touch the index. This
Nit: s/update/Update
Show 21 quoted lines
>     ++	 * can be used to explicitly override "rerere.autoUpdate".
>     ++	 *
>     ++	 * This flag is essentially the reverse of `RERERE_AUTOUPDATE`. It is
>     ++	 * invalid to pass both flags at the same time.
>      +	 */
>      +	RERERE_NOAUTOUPDATE = (1 << 1),
>      +
>  3:  99faad47068 =  3:  48692c2c88d builtin/rerere: drop `the_repository`
>  4:  f164c482227 =  4:  e76991dd39d builtin/rerere: stop passing flags to subcommands that ignore them
>  5:  0573d2323e8 =  5:  2474dca4713 builtin/rerere: turn "forget" into a proper subcommand
>  6:  2098dedf4fd =  6:  cecdbb1c63b builtin/rerere: turn "clear" into a proper subcommand
>  7:  e8eaa2b4092 =  7:  54fc766f9d2 builtin/rerere: turn "status" into a proper subcommand
>  8:  a5781284b8b =  8:  fa2c839b2cb builtin/rerere: turn "remaining" into a proper subcommand
>  9:  9a4278df0ea =  9:  416b8311ca9 builtin/rerere: turn "diff" into a proper subcommand
> 10:  e63b9be0d74 = 10:  adb2b68f833 builtin/rerere: turn "gc" into a proper subcommand
> 11:  47889896ecb = 11:  a12e19cb2e8 builtin/rerere: use `OPT_SUBCOMMAND()`
> 12:  5e16a247b49 = 12:  4b1b6170ba3 builtin/rerere: introduce proper usage strings for subcommands
>
> ---
> base-commit: 710910c03a22ac663885049213b9fef5853ea8e0
> change-id: 20261027-pks-rerere-subcommands-318d41553438
Looks good. Thanks!
Patrick Steinhardt· Nov 13, 2026, 07:20 UTC · re: Karthik Nayak · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

On Thu, Nov 12, 2026 at 05:41:29AM -0800, Karthik Nayak wrote:
Show 44 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > Range-diff versus v3:
> >
> >  1:  e9237465706 =  1:  f669dc6eddf rerere: rename `repo_rerere()`
> >  2:  94d91a0620d !  2:  4fd3f6aa650 rerere: convert flags into an enum
> >     @@ Commit message
> >          around as enums so that it becomes trivial to see what kind of flags are
> >          expected. Adapt the rerere flags accordingly and document them.
> >
> >     +    While at it, detect the case where both `RERERE_AUTOUPDATE` and
> >     +    `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot
> >     +    of sense, and it's not obvious which of those flags takes precedence
> >     +    (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of
> >     +    those flags, but let's be safe rather than sorry and `BUG()` in case
> >     +    both are passed.
> >     +
> >          Signed-off-by: Patrick Steinhardt <ps@pks.im>
> >
> >       ## rerere.c ##
> >     @@ rerere.c: static int is_rerere_enabled(struct repository *r)
> >       {
> >       	int lock_timeout_ms = 1000;
> >       	int fd;
> >     +@@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
> >     + 	repo_config_get_bool(r, "rerere.autoupdate", &cache->autoupdate);
> >     + 	repo_config_get_int(r, "rerere.locktimeout", &lock_timeout_ms);
> >     +
> >     ++	if ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))
> >     ++		BUG("RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE");
> >     + 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
> >     + 		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);
> >     + 	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
> >      @@ rerere.c: int rerere_cache_setup(struct rerere_cache *cache,
> >       	return fd;
> >       }
> >     @@ rerere.h: struct rerere_id {
> >      +	RERERE_AUTOUPDATE = (1 << 0),
> >      +
> >      +	/*
> >     -+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
> >     -+	 * working tree but don't touch the index.
> >     ++	 * update the file in the working tree but don't touch the index. This
> 
> Nit: s/update/Update

Oops, good catch. I'll refrain from sending out another version just to fix this one fix though. Junio, I'd appreciate it if you could fix this up in your tree. Thanks!

Patrick
Junio C Hamano· Nov 13, 2026, 18:09 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 13 quoted lines
>> >     @@ rerere.h: struct rerere_id {
>> >      +	RERERE_AUTOUPDATE = (1 << 0),
>> >      +
>> >      +	/*
>> >     -+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
>> >     -+	 * working tree but don't touch the index.
>> >     ++	 * update the file in the working tree but don't touch the index. This
>> 
>> Nit: s/update/Update
>
> Oops, good catch. I'll refrain from sending out another version just to
> fix this one fix though. Junio, I'd appreciate it if you could fix this
> up in your tree. Thanks!
    $ git checkout ps/rerere-subcommands
    $ edit rerere.h
    $ git log --oneline --first-parent master..
    $ git commit -a --fixup HEAD~10
    $ git rebase --autosquash HEAD~11

By the way, I wonder if we can simplify the last three steps in any way?

 * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
 * The last "rebase" does not have to be on HEAD~11; as long as it
   covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
   interested in taking any new development from there, and I do not
   want to worry about what the command would do on the merges the
   topic has as synthetic base.

Perhaps with newer experimental commands it becomes easier to manage?

Tuomas Ahola· Nov 13, 2026, 19:38 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Junio C Hamano <gitster@pobox.com> wrote:
Show 33 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> >> >     @@ rerere.h: struct rerere_id {
> >> >      +	RERERE_AUTOUPDATE = (1 << 0),
> >> >      +
> >> >      +	/*
> >> >     -+	 * Reverse of RERERE_AUTOUPDATE. That is, update the file in the
> >> >     -+	 * working tree but don't touch the index.
> >> >     ++	 * update the file in the working tree but don't touch the index. This
> >> 
> >> Nit: s/update/Update
> >
> > Oops, good catch. I'll refrain from sending out another version just to
> > fix this one fix though. Junio, I'd appreciate it if you could fix this
> > up in your tree. Thanks!
> 
>     $ git checkout ps/rerere-subcommands
>     $ edit rerere.h
>     $ git log --oneline --first-parent master..
>     $ git commit -a --fixup HEAD~10
>     $ git rebase --autosquash HEAD~11
> 
> By the way, I wonder if we can simplify the last three steps in any
> way?
> 
>  * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
> 
>  * The last "rebase" does not have to be on HEAD~11; as long as it
>    covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
>    interested in taking any new development from there, and I do not
>    want to worry about what the command would do on the merges the
>    topic has as synthetic base.
> 
Just for hack's sake :-)
	$ git rebase --autosquash $(git rev-list --min-parents=2 --max-count=1 HEAD)
> Perhaps with newer experimental commands it becomes easier to
> manage?
> 
Phillip Wood· Nov 13, 2026, 19:44 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

On 13/11/2026 18:09, Junio C Hamano wrote:
Show 13 quoted lines
> >      $ git checkout ps/rerere-subcommands
>      $ edit rerere.h
>      $ git log --oneline --first-parent master..
>      $ git commit -a --fixup HEAD~10
>      $ git rebase --autosquash HEAD~11
> > By the way, I wonder if we can simplify the last three steps in any
> way?
> >   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
> >   * The last "rebase" does not have to be on HEAD~11; as long as it
>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
>     interested in taking any new development from there, and I do not
>     want to worry about what the command would do on the merges the
>     topic has as synthetic base.
So long as you've set an upstream branch, you can use "--keep-base" and omit the upstream commit.
Thanks
Phillip
Junio C Hamano· Nov 13, 2026, 21:44 UTC · re: Phillip Wood · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 21 quoted lines
> On 13/11/2026 18:09, Junio C Hamano wrote:
>> 
>>      $ git checkout ps/rerere-subcommands
>>      $ edit rerere.h
>>      $ git log --oneline --first-parent master..
>>      $ git commit -a --fixup HEAD~10
>>      $ git rebase --autosquash HEAD~11
>> 
>> By the way, I wonder if we can simplify the last three steps in any
>> way?
>> 
>>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
>> 
>>   * The last "rebase" does not have to be on HEAD~11; as long as it
>>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
>>     interested in taking any new development from there, and I do not
>>     want to worry about what the command would do on the merges the
>>     topic has as synthetic base.
>
> So long as you've set an upstream branch, you can use "--keep-base" and 
> omit the upstream commit.

I do not think I want to set upstream for ~600 topic branches (among ~100 are still in flight) I keep around. I was hoping that after making fixup changes in my editor and adding them to the index

    $ edit rerere.h
    $ git add -u
A single command that names the target of the added change
    $ git fixup HEAD~10
would automatically do the two "commit && rebase" commands.
Tuomas Ahola· Nov 14, 2026, 07:22 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Junio C Hamano <gitster@pobox.com> wrote:
Show 37 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
> > On 13/11/2026 18:09, Junio C Hamano wrote:
> >> 
> >>      $ git checkout ps/rerere-subcommands
> >>      $ edit rerere.h
> >>      $ git log --oneline --first-parent master..
> >>      $ git commit -a --fixup HEAD~10
> >>      $ git rebase --autosquash HEAD~11
> >> 
> >> By the way, I wonder if we can simplify the last three steps in any
> >> way?
> >> 
> >>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
> >> 
> >>   * The last "rebase" does not have to be on HEAD~11; as long as it
> >>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
> >>     interested in taking any new development from there, and I do not
> >>     want to worry about what the command would do on the merges the
> >>     topic has as synthetic base.
> >
> > So long as you've set an upstream branch, you can use "--keep-base" and 
> > omit the upstream commit.
> 
> I do not think I want to set upstream for ~600 topic branches (among
> ~100 are still in flight) I keep around.  I was hoping that after
> making fixup changes in my editor and adding them to the index
> 
>     $ edit rerere.h
>     $ git add -u
> 
> A single command that names the target of the added change
> 
>     $ git fixup HEAD~10
> 
> would automatically do the two "commit && rebase" commands.
> 
Which is exactly what 'git history fixup HEAD~10' strives to do, isn't it?
Patrick Steinhardt· Nov 16, 2026, 07:46 UTC · re: Tuomas Ahola · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

On Sat, Nov 14, 2026 at 09:22:40AM +0200, Tuomas Ahola wrote:
Show 41 quoted lines
> Junio C Hamano <gitster@pobox.com> wrote:
> 
> > Phillip Wood <phillip.wood123@gmail.com> writes:
> > 
> > > On 13/11/2026 18:09, Junio C Hamano wrote:
> > >> 
> > >>      $ git checkout ps/rerere-subcommands
> > >>      $ edit rerere.h
> > >>      $ git log --oneline --first-parent master..
> > >>      $ git commit -a --fixup HEAD~10
> > >>      $ git rebase --autosquash HEAD~11
> > >> 
> > >> By the way, I wonder if we can simplify the last three steps in any
> > >> way?
> > >> 
> > >>   * We can use 'HEAD^{/^rerere: convert flags}' instead of counting.
> > >> 
> > >>   * The last "rebase" does not have to be on HEAD~11; as long as it
> > >>     covers HEAD~10 it is OK, but we cannot use 'master' as I am *not*
> > >>     interested in taking any new development from there, and I do not
> > >>     want to worry about what the command would do on the merges the
> > >>     topic has as synthetic base.
> > >
> > > So long as you've set an upstream branch, you can use "--keep-base" and 
> > > omit the upstream commit.
> > 
> > I do not think I want to set upstream for ~600 topic branches (among
> > ~100 are still in flight) I keep around.  I was hoping that after
> > making fixup changes in my editor and adding them to the index
> > 
> >     $ edit rerere.h
> >     $ git add -u
> > 
> > A single command that names the target of the added change
> > 
> >     $ git fixup HEAD~10
> > 
> > would automatically do the two "commit && rebase" commands.
> > 
> 
> Which is exactly what 'git history fixup HEAD~10' strives to do, isn't it?

Yup. The only part still missing there to help Junio's case is to replay merge commits. Once it supports that you can say `git history fixup "HEAD^{/^rerere: convert flags}"`.

Patrick
Junio C Hamano· Nov 14, 2026, 12:45 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Does the new syntax introduce a subtle UI regression that does not allow certain options before subcommands? We used to take "git rerere --skip-locked gc", but now it has to be spelled as "git rerere gc --skip-locked", it seems.

I do not particularly care about the '--skip-locked' option itself, and I personally prefer to see options after non-options as a general CLI principle, but it seems that it is now required to give the option after the "gc" subcommand.

I do not know how often people run "git rerere" with these subcommands themselves. This subtle change in the CLI may go unnoticed in a smaller project, but because we probably have more than a few thousand users, I am afraid that somebody will notice.

In the transcript below, "rungit TRACK" is my short-hand to run version of "git" from that integration branch.

$ rungit master rerere --skip-locked gc $ rungit next rerere --skip-locked gc $ rungit seen rerere --skip-locked gc error: unknown option `skip-locked' usage: git rerere [--[no-]rerere-autoupdate]

    --[no-]rerere-autoupdate
                          register clean resolutions in index
$ rungit seen rerere gc --skip-locked
Patrick Steinhardt· Nov 16, 2026, 07:57 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

On Sat, Nov 14, 2026 at 04:45:22AM -0800, Junio C Hamano wrote:
Show 27 quoted lines
> Does the new syntax introduce a subtle UI regression that does not
> allow certain options before subcommands?  We used to take "git
> rerere --skip-locked gc", but now it has to be spelled as "git
> rerere gc --skip-locked", it seems.
> 
> I do not particularly care about the '--skip-locked' option itself,
> and I personally prefer to see options after non-options as a
> general CLI principle, but it seems that it is now required to give
> the option after the "gc" subcommand.
> 
> I do not know how often people run "git rerere" with these
> subcommands themselves.  This subtle change in the CLI may go
> unnoticed in a smaller project, but because we probably have more
> than a few thousand users, I am afraid that somebody will notice.
> 
> In the transcript below, "rungit TRACK" is my short-hand to run
> version of "git" from that integration branch.
> 
> $ rungit master rerere --skip-locked gc
> $ rungit next rerere --skip-locked gc
> $ rungit seen rerere --skip-locked gc
> error: unknown option `skip-locked'
> usage: git rerere [--[no-]rerere-autoupdate]
> 
>     --[no-]rerere-autoupdate
>                           register clean resolutions in index
> $ rungit seen rerere gc --skip-locked
Yes, as documented in "builtin/rerere: use `OPT_SUBCOMMAND()`.
  Unfortunately this means that we have a backwards-incompatible change
  because we no longer accept the "--[no-]rerere-autoupdate" flag for all
  subcommands. But this was arguably broken and misleading as we ignore
  this flag for any other subcommand aynway. So we cheat a bit and simply
  call it a bug that those flags were accepted in the first place.

But yes, the same is true for "--skip-locked". I was expecting more review feedback on that specific part, and was a bit surprised to get none.

As documented in the commit message, I would argue that the current status quo is just plain broken as we accept options in cases where they aren't even being used at all. For "--skip-locked" that shouldn't be much of an issue, as the flag has only just been introduced, so it's very unlikely that there's any users of it out there just yet. So now is the right moment to fix that design wart.

BUt that isn't true for the "--rerere-autoupdate" flag, which has existed for a long time already. So if this backwards-incompatible change is deemed to be too risky, then I'd adapt the code to only allow that one flag in all locations.

Patrick
Junio C Hamano· Nov 16, 2026, 15:43 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
>> $ rungit seen rerere --skip-locked gc
>> error: unknown option `skip-locked'
>> usage: git rerere [--[no-]rerere-autoupdate]
>> 
>>     --[no-]rerere-autoupdate
>>                           register clean resolutions in index
>> $ rungit seen rerere gc --skip-locked
>
> Yes, as documented in "builtin/rerere: use `OPT_SUBCOMMAND()`.
>
>   Unfortunately this means that we have a backwards-incompatible change
>   because we no longer accept the "--[no-]rerere-autoupdate" flag for all
>   subcommands. But this was arguably broken and misleading as we ignore
>   this flag for any other subcommand aynway. So we cheat a bit and simply
>   call it a bug that those flags were accepted in the first place.
Ah, I missed that part.
> But yes, the same is true for "--skip-locked". I was expecting more
> review feedback on that specific part, and was a bit surprised to get
> none.
OK.  Let's break it and have the users fix their scripts.
Junio C Hamano· Nov 17, 2026, 01:16 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

Junio C Hamano <gitster@pobox.com> writes:
Show 25 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
>
>>> $ rungit seen rerere --skip-locked gc
>>> error: unknown option `skip-locked'
>>> usage: git rerere [--[no-]rerere-autoupdate]
>>> 
>>>     --[no-]rerere-autoupdate
>>>                           register clean resolutions in index
>>> $ rungit seen rerere gc --skip-locked
>>
>> Yes, as documented in "builtin/rerere: use `OPT_SUBCOMMAND()`.
>>
>>   Unfortunately this means that we have a backwards-incompatible change
>>   because we no longer accept the "--[no-]rerere-autoupdate" flag for all
>>   subcommands. But this was arguably broken and misleading as we ignore
>>   this flag for any other subcommand aynway. So we cheat a bit and simply
>>   call it a bug that those flags were accepted in the first place.
>
> Ah, I missed that part.
>
>> But yes, the same is true for "--skip-locked". I was expecting more
>> review feedback on that specific part, and was a bit surprised to get
>> none.
>
> OK.  Let's break it and have the users fix their scripts.
Having said that
    $ rungit seen rerere unknown
    usage: too many arguments
    $ rungit master rerere unknown
    usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]

the above might be a regression that is more easily spotted by folks.

Patrick Steinhardt· Nov 18, 2026, 14:09 UTC · re: Junio C Hamano · lore

Re: [PATCH v4 00/12] builtin/rerere: convert to use subcommands

On Mon, Nov 16, 2026 at 05:16:12PM -0800, Junio C Hamano wrote:
Show 37 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> >>> $ rungit seen rerere --skip-locked gc
> >>> error: unknown option `skip-locked'
> >>> usage: git rerere [--[no-]rerere-autoupdate]
> >>> 
> >>>     --[no-]rerere-autoupdate
> >>>                           register clean resolutions in index
> >>> $ rungit seen rerere gc --skip-locked
> >>
> >> Yes, as documented in "builtin/rerere: use `OPT_SUBCOMMAND()`.
> >>
> >>   Unfortunately this means that we have a backwards-incompatible change
> >>   because we no longer accept the "--[no-]rerere-autoupdate" flag for all
> >>   subcommands. But this was arguably broken and misleading as we ignore
> >>   this flag for any other subcommand aynway. So we cheat a bit and simply
> >>   call it a bug that those flags were accepted in the first place.
> >
> > Ah, I missed that part.
> >
> >> But yes, the same is true for "--skip-locked". I was expecting more
> >> review feedback on that specific part, and was a bit surprised to get
> >> none.
> >
> > OK.  Let's break it and have the users fix their scripts.
> 
> Having said that
> 
>     $ rungit seen rerere unknown
>     usage: too many arguments
>     $ rungit master rerere unknown
>     usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
> 
> the above might be a regression that is more easily spotted by
> folks.
True, will fix.
Patrick
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 00/13] builtin/rerere: convert to use subcommands

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.im
Changes 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.im
Changes 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

Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 01/13] rerere: rename `repo_rerere()`

The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix.

Rename the function to just `rerere()`. Move around and extend documentation of this function to better explain what it does.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 apply.c          | 2 +-
 builtin/am.c     | 4 ++--
 builtin/commit.c | 2 +-
 builtin/merge.c  | 2 +-
 builtin/rerere.c | 2 +-
 builtin/stash.c  | 2 +-
 rerere.c         | 7 +------
 rerere.h         | 9 ++++++++-
 sequencer.c      | 4 ++--
 9 files changed, 18 insertions(+), 16 deletions(-)
Show changes to 9 files +18 −16

apply.c, builtin/am.c, builtin/commit.c, builtin/merge.c, builtin/rerere.c, builtin/stash.c, rerere.c, rerere.h, sequencer.c

diff --git a/apply.c b/apply.c
index a0b7119c639..646fabeafa3 100644
--- a/apply.c
+++ b/apply.c
@@ -4866,7 +4866,7 @@ static int write_out_results(struct apply_state *state, struct patch *list)
 		 * tree with conflict markers, but that isn't written with --cached.
 		 */
 		if (!state->cached)
-			repo_rerere(state->repo, 0);
+			rerere(state->repo, 0);
 	}
 
 	return errs;
diff --git a/builtin/am.c b/builtin/am.c
index e9623b83077..4a5b37bee00 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1649,7 +1649,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 		o.verbosity = 0;
 
 	if (merge_ort_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
-		repo_rerere(the_repository, state->allow_rerere_autoupdate);
+		rerere(the_repository, state->allow_rerere_autoupdate);
 		free(their_tree_name);
 		return error(_("Failed to merge in the changes."));
 	}
@@ -1979,7 +1979,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
 			goto next;
 	}
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 
 	do_commit(state);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index 8ffd42681bb..3a4b94ad623 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1962,7 +1962,7 @@ int cmd_commit(int argc,
 
 	git_test_write_commit_graph_or_die(the_repository);
 
-	repo_rerere(the_repository, 0);
+	rerere(the_repository, 0);
 	run_auto_maintenance(the_repository, quiet);
 	run_commit_hook(use_editor, repo_get_index_file(the_repository),
 			NULL, "post-commit", NULL);
diff --git a/builtin/merge.c b/builtin/merge.c
index d7bf209114f..089e36e8575 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1061,7 +1061,7 @@ static int suggest_conflicts(void)
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
-	repo_rerere(the_repository, allow_rerere_auto);
+	rerere(the_repository, allow_rerere_auto);
 	printf(_("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n"));
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2c17f02f56d..a499e7b9151 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -83,7 +83,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return repo_rerere(the_repository, flags);
+		return rerere(the_repository, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
diff --git a/builtin/stash.c b/builtin/stash.c
index e1a3a76bd04..91870a255fd 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -688,7 +688,7 @@ static enum stash_apply_result do_apply_stash(const char *prefix,
 		ret = error(_("could not write index"));
 
 	if (ret) {
-		repo_rerere(the_repository, 0);
+		rerere(the_repository, 0);
 
 		if (index)
 			fprintf_ln(stderr, _("Index was not unstashed."));
diff --git a/rerere.c b/rerere.c
index e0897612085..47a4a325bf5 100644
--- a/rerere.c
+++ b/rerere.c
@@ -951,12 +951,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-/*
- * The main entry point that is called internally from codepaths that
- * perform mergy operations, possibly leaving conflicted index entries
- * and working tree files.
- */
-int repo_rerere(struct repository *r, int flags)
+int rerere(struct repository *r, int flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
diff --git a/rerere.h b/rerere.h
index d3cbd10e13f..dd9da03d6db 100644
--- a/rerere.h
+++ b/rerere.h
@@ -45,7 +45,14 @@ int rerere_cache_setup(struct rerere_cache *cache,
 		       int flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
-int repo_rerere(struct repository *, int);
+/*
+ * The main entry point that is called internally from codepaths that
+ * perform mergy operations, possibly leaving conflicted index entries
+ * and working tree files. It records (and optionally updates) resolved
+ * conflicts and reuses recorded resolutions for unresolved conflicts.
+ */
+int rerere(struct repository *r, int flags);
+
 /*
  * Given the conflict ID and the name of a "file" used for replaying
  * the recorded resolution (e.g. "preimage", "postimage"), return the
diff --git a/sequencer.c b/sequencer.c
index 508ec717920..ace1cfac1cb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2556,7 +2556,7 @@ static enum pick_result do_pick_commit(struct repository *r,
 		      : _("could not apply %s... %s"),
 		      short_commit_name(r, commit), msg.subject);
 		print_advice(r, res == 1, opts);
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 		goto leave;
 	}
 
@@ -4488,7 +4488,7 @@ static int do_merge(struct repository *r,
 
 	rollback_lock_file(&lock);
 	if (ret)
-		repo_rerere(r, opts->allow_rerere_auto);
+		rerere(r, opts->allow_rerere_auto);
 	else
 		/*
 		 * In case of problems, we now want to return a positive
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 02/13] rerere: convert flags into an enum

Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly and document them.

While at it, detect the case where both `RERERE_AUTOUPDATE` and `RERERE_NOAUTOUPDATE` are passed. This combination does not make a lot of sense, and it's not obvious which of those flags takes precedence (it's `RERERE_AUTOUPDATE`). All current callers know to only pass one of those flags, but let's be safe rather than sorry and `BUG()` in case both are passed.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 rerere.c |  9 ++++++---
 rerere.h | 36 +++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 12 deletions(-)
Show changes to 2 files +33 −12

rerere.c, rerere.h

diff --git a/rerere.c b/rerere.c
index 47a4a325bf5..47d9077eeca 100644
--- a/rerere.c
+++ b/rerere.c
@@ -908,7 +908,7 @@ static int is_rerere_enabled(struct repository *r)
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags)
+		       enum rerere_flags flags)
 {
 	int lock_timeout_ms = 1000;
 	int fd;
@@ -922,6 +922,8 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	repo_config_get_bool(r, "rerere.autoupdate", &cache->autoupdate);
 	repo_config_get_int(r, "rerere.locktimeout", &lock_timeout_ms);
 
+	if ((flags & RERERE_AUTOUPDATE) && (flags & RERERE_NOAUTOUPDATE))
+		BUG("RERERE_AUTOUPDATE cannot be used with RERERE_NOAUTOUPDATE");
 	if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
 		cache->autoupdate = !!(flags & RERERE_AUTOUPDATE);
 	if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
@@ -951,7 +953,7 @@ int rerere_cache_setup(struct rerere_cache *cache,
 	return fd;
 }
 
-int rerere(struct repository *r, int flags)
+int rerere(struct repository *r, enum rerere_flags flags)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
@@ -1336,7 +1338,8 @@ bool rerere_gc_needed(struct repository *r, size_t limit)
 	return needed;
 }
 
-void rerere_gc(struct repository *r, struct string_list *rr, int flags)
+void rerere_gc(struct repository *r, struct string_list *rr,
+	       enum rerere_flags flags)
 {
 	struct rerere_cache cache;
 	struct string_list to_remove = STRING_LIST_INIT_DUP;
diff --git a/rerere.h b/rerere.h
index dd9da03d6db..239172e969a 100644
--- a/rerere.h
+++ b/rerere.h
@@ -9,12 +9,6 @@
 struct pathspec;
 struct repository;
 
-#define RERERE_AUTOUPDATE   01
-#define RERERE_NOAUTOUPDATE 02
-#define RERERE_READONLY     04
-/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
-#define RERERE_NOWAIT       010
-
 /*
  * Marks paths that have been hand-resolved and added to the
  * index. Set in the util field of such paths after calling
@@ -39,10 +33,33 @@ struct rerere_id {
 	int variant;
 };
 
+enum rerere_flags {
+	/*
+	 * Auto-update the index with previously recorded resolutions. This can
+	 * be used to explicitly override "rerere.autoUpdate".
+	 */
+	RERERE_AUTOUPDATE = (1 << 0),
+
+	/*
+	 * 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
+	 * invalid to pass both flags at the same time.
+	 */
+	RERERE_NOAUTOUPDATE = (1 << 1),
+
+	/* Skip acquiring the MERGE_RR.lock for a read-only operation. */
+	RERERE_READONLY = (1 << 2),
+
+	/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled. */
+	RERERE_NOWAIT = (1 << 3),
+};
+
 int rerere_cache_setup(struct rerere_cache *cache,
 		       struct repository *r,
 		       struct string_list *merge_rr,
-		       int flags);
+		       enum rerere_flags flags);
 void rerere_cache_release(struct rerere_cache *cache);
 
 /*
@@ -51,7 +68,7 @@ void rerere_cache_release(struct rerere_cache *cache);
  * and working tree files. It records (and optionally updates) resolved
  * conflicts and reuses recorded resolutions for unresolved conflicts.
  */
-int rerere(struct repository *r, int flags);
+int rerere(struct repository *r, enum rerere_flags flags);
 
 /*
  * Given the conflict ID and the name of a "file" used for replaying
@@ -65,7 +82,8 @@ const char *rerere_path(struct repository *,
 int rerere_forget(struct repository *, struct pathspec *);
 int rerere_remaining(struct repository *, struct string_list *);
 void rerere_clear(struct repository *, struct string_list *);
-void rerere_gc(struct repository *, struct string_list *, int);
+void rerere_gc(struct repository *, struct string_list *,
+	       enum rerere_flags flags);
 
 /*
  * Check whether garbage collection for rerere entries is needed, which is
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 03/13] builtin/rerere: drop `the_repository`

There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
Show changes to builtin/rerere.c +11 −13
diff --git a/builtin/rerere.c b/builtin/rerere.c
index a499e7b9151..83fb3783c61 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -57,7 +55,7 @@ static int diff_two(const char *file1, const char *label1,
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
-	       struct repository *repo UNUSED)
+	       struct repository *repo)
 {
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	int autoupdate = -1, skip_locked = 0, flags = 0;
@@ -75,7 +73,7 @@ int cmd_rerere(int argc,
 	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
 		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
 
-	repo_config(the_repository, git_xmerge_config, NULL);
+	repo_config(repo, git_xmerge_config, NULL);
 
 	if (autoupdate == 1)
 		flags = RERERE_AUTOUPDATE;
@@ -83,7 +81,7 @@ int cmd_rerere(int argc,
 		flags = RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
-		return rerere(the_repository, flags);
+		return rerere(repo, flags);
 
 	if (!strcmp(argv[0], "forget")) {
 		struct pathspec pathspec;
@@ -94,21 +92,21 @@ int cmd_rerere(int argc,
 		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
 			       prefix, argv + 1);
 
-		ret = rerere_forget(the_repository, &pathspec);
+		ret = rerere_forget(repo, &pathspec);
 
 		clear_pathspec(&pathspec);
 		return ret;
 	}
 
 	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(the_repository, &merge_rr);
+		rerere_clear(repo, &merge_rr);
 	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(the_repository, &merge_rr,
+		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status")) {
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				       flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
@@ -116,7 +114,7 @@ int cmd_rerere(int argc,
 
 		rerere_cache_release(&cache);
 	} else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(the_repository, &merge_rr);
+		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
 				printf("%s\n", merge_rr.items[i].string);
@@ -129,16 +127,16 @@ int cmd_rerere(int argc,
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-		if (rerere_cache_setup(&cache, the_repository, &merge_rr,
+		if (rerere_cache_setup(&cache, repo, &merge_rr,
 				      flags | RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
 			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(the_repository, &buf, id, "preimage"),
+			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
 				     path, path, path))
 				die(_("unable to generate diff for '%s'"),
-				    rerere_path(the_repository, &buf, id, NULL));
+				    rerere_path(repo, &buf, id, NULL));
 		}
 
 		rerere_cache_release(&cache);
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 04/13] builtin/rerere: stop passing flags to subcommands that ignore them

The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`.

This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/rerere.c +2 −2
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 83fb3783c61..405276cc94b 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -107,7 +107,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++)
 			printf("%s\n", merge_rr.items[i].string);
@@ -128,7 +128,7 @@ int cmd_rerere(int argc,
 		struct rerere_cache cache;
 
 		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				      flags | RERERE_READONLY) < 0)
+				       RERERE_READONLY) < 0)
 			return 0;
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			const char *path = merge_rr.items[i].string;
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 05/13] builtin/rerere: turn "forget" into a proper subcommand

The git-rerere(1) command has its own, home-grown implementation of subcommands. Of course this implementation is inconsistent with how subcommands typically work:

  - Options from other subcommands apply to each other.
  - We don't have proper usage strings.
  - Running `git rerere <subcmd> -h` doesn't print the options that are
    supported by that subcommand, but instead it just prints the help of
    git-rerere(1) itself.

A subsequent commit will thus introduce proper subcommands as supported by our parse-options subsystem. Refactor the "forget" subcommand to use parse-options as a preparatory step. The other commands will follow in subsequent commits until all of them have been converted, and then we switch over to `OPT_SUBCOMMAND()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Show changes to builtin/rerere.c +24 −14
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 405276cc94b..5d2ae154ff8 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,28 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_forget(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct pathspec pathspec;
+	int ret;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (!argc)
+		warning(_("'git rerere forget' without paths is deprecated"));
+	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+
+	ret = rerere_forget(repo, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -83,20 +105,8 @@ int cmd_rerere(int argc,
 	if (argc < 1)
 		return rerere(repo, flags);
 
-	if (!strcmp(argv[0], "forget")) {
-		struct pathspec pathspec;
-		int ret;
-
-		if (argc < 2)
-			warning(_("'git rerere forget' without paths is deprecated"));
-		parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
-			       prefix, argv + 1);
-
-		ret = rerere_forget(repo, &pathspec);
-
-		clear_pathspec(&pathspec);
-		return ret;
-	}
+	if (!strcmp(argv[0], "forget"))
+		return cmd_rerere_forget(argc, argv, prefix, repo);
 
 	if (!strcmp(argv[0], "clear")) {
 		rerere_clear(repo, &merge_rr);
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 06/13] builtin/rerere: turn "clear" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Show changes to builtin/rerere.c +22 −3
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 5d2ae154ff8..62f69b488b0 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -52,6 +52,26 @@ static int diff_two(const char *file1, const char *label1,
 	return ret;
 }
 
+static int cmd_rerere_clear(int argc,
+			    const char **argv,
+			    const char *prefix,
+			    struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_clear(repo, &merge_rr);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -107,9 +127,8 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-
-	if (!strcmp(argv[0], "clear")) {
-		rerere_clear(repo, &merge_rr);
+	else if (!strcmp(argv[0], "clear")) {
+		return cmd_rerere_clear(argc, argv, prefix, repo);
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 07/13] builtin/rerere: turn "status" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +29 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 62f69b488b0..2bcd270a1f1 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,32 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_status(int argc,
+			     const char **argv,
+			     const char *prefix,
+			     struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+	for (size_t i = 0; i < merge_rr.nr; i++)
+		printf("%s\n", merge_rr.items[i].string);
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	return 0;
+}
+
 int cmd_rerere(int argc,
 	       const char **argv,
 	       const char *prefix,
@@ -132,17 +158,9 @@ int cmd_rerere(int argc,
 	} else if (!strcmp(argv[0], "gc"))
 		rerere_gc(repo, &merge_rr,
 			  skip_locked ? RERERE_NOWAIT : 0);
-	else if (!strcmp(argv[0], "status")) {
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++)
-			printf("%s\n", merge_rr.items[i].string);
-
-		rerere_cache_release(&cache);
-	} else if (!strcmp(argv[0], "remaining")) {
+	else if (!strcmp(argv[0], "status"))
+		return cmd_rerere_status(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "remaining")) {
 		rerere_remaining(repo, &merge_rr);
 		for (size_t i = 0; i < merge_rr.nr; i++) {
 			if (merge_rr.items[i].util != RERERE_RESOLVED)
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 08/13] builtin/rerere: turn "remaining" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)
Show changes to builtin/rerere.c +31 −11
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 2bcd270a1f1..3f82bcbeb10 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -94,6 +94,34 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_remaining(int argc,
+				const char **argv,
+				const char *prefix,
+				struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_remaining(repo, &merge_rr);
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		if (merge_rr.items[i].util != RERERE_RESOLVED)
+			printf("%s\n", merge_rr.items[i].string);
+		else
+			/* prepare for later call to
+			 * string_list_clear() */
+			merge_rr.items[i].util = NULL;
+	}
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_status(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -160,17 +188,9 @@ int cmd_rerere(int argc,
 			  skip_locked ? RERERE_NOWAIT : 0);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining")) {
-		rerere_remaining(repo, &merge_rr);
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			if (merge_rr.items[i].util != RERERE_RESOLVED)
-				printf("%s\n", merge_rr.items[i].string);
-			else
-				/* prepare for later call to
-				 * string_list_clear() */
-				merge_rr.items[i].util = NULL;
-		}
-	} else if (!strcmp(argv[0], "diff")) {
+	else if (!strcmp(argv[0], "remaining"))
+		return cmd_rerere_remaining(argc, argv, prefix, repo);
+	else if (!strcmp(argv[0], "diff")) {
 		struct strbuf buf = STRBUF_INIT;
 		struct rerere_cache cache;
 
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 09/13] builtin/rerere: turn "diff" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
Show changes to builtin/rerere.c +37 −19
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3f82bcbeb10..40bae5cb9cc 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -72,6 +72,40 @@ static int cmd_rerere_clear(int argc,
 	return 0;
 }
 
+static int cmd_rerere_diff(int argc,
+			   const char **argv,
+			   const char *prefix,
+			   struct repository *repo)
+{
+	struct option options[] = {
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	struct strbuf buf = STRBUF_INIT;
+	struct rerere_cache cache;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (rerere_cache_setup(&cache, repo, &merge_rr,
+			       RERERE_READONLY) < 0)
+		return 0;
+
+	for (size_t i = 0; i < merge_rr.nr; i++) {
+		const char *path = merge_rr.items[i].string;
+		const struct rerere_id *id = merge_rr.items[i].util;
+		if (diff_two(rerere_path(repo, &buf, id, "preimage"), path, path, path))
+			die(_("unable to generate diff for '%s'"),
+			    rerere_path(repo, &buf, id, NULL));
+	}
+
+	string_list_clear(&merge_rr, 1);
+	rerere_cache_release(&cache);
+	strbuf_release(&buf);
+	return 0;
+}
+
 static int cmd_rerere_forget(int argc,
 			     const char **argv,
 			     const char *prefix,
@@ -190,25 +224,9 @@ int cmd_rerere(int argc,
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
 		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff")) {
-		struct strbuf buf = STRBUF_INIT;
-		struct rerere_cache cache;
-
-		if (rerere_cache_setup(&cache, repo, &merge_rr,
-				       RERERE_READONLY) < 0)
-			return 0;
-		for (size_t i = 0; i < merge_rr.nr; i++) {
-			const char *path = merge_rr.items[i].string;
-			const struct rerere_id *id = merge_rr.items[i].util;
-			if (diff_two(rerere_path(repo, &buf, id, "preimage"),
-				     path, path, path))
-				die(_("unable to generate diff for '%s'"),
-				    rerere_path(repo, &buf, id, NULL));
-		}
-
-		rerere_cache_release(&cache);
-		strbuf_release(&buf);
-	} else
+	else if (!strcmp(argv[0], "diff"))
+		return cmd_rerere_diff(argc, argv, prefix, repo);
+	else
 		usage_with_options(rerere_usage, options);
 
 	string_list_clear(&merge_rr, 1);
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 10/13] builtin/rerere: turn "gc" into a proper subcommand

As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "gc" subcommand to use parse-options as a preparatory step.

Note that this results in an intentional change in behaviour, as we previously accepted the "--skip-lock" flag both before the subcommand and after the subcommand name, whereas after this change we only allow it after the subcommand name. But that flag has only recently been introduced via 5f6b6aa3ab4 (rerere: add "gc --skip-locked" for auto maintenance, 2026-10-13), which is not yet part of any release, so it's unlikely that anybody will complain about this change.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c  | 43 ++++++++++++++++++++++++++++++-------------
 t/t4200-rerere.sh |  5 -----
 2 files changed, 30 insertions(+), 18 deletions(-)
Show changes to 2 files +30 −18

builtin/rerere.c, t/t4200-rerere.sh

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 40bae5cb9cc..3162b074ec6 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -128,6 +128,30 @@ static int cmd_rerere_forget(int argc,
 	return ret;
 }
 
+static int cmd_rerere_gc(int argc,
+			 const char **argv,
+			 const char *prefix,
+			 struct repository *repo)
+{
+	int skip_locked = 0;
+	struct option options[] = {
+		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
+				N_("skip gc while another process holds the lock")),
+		OPT_END(),
+	};
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	rerere_gc(repo, &merge_rr,
+		  skip_locked ? RERERE_NOWAIT : 0);
+
+	string_list_clear(&merge_rr, 1);
+	return 0;
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -187,21 +211,16 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	struct string_list merge_rr = STRING_LIST_INIT_DUP;
-	int autoupdate = -1, skip_locked = 0, flags = 0;
+	int autoupdate = -1, flags = 0;
 
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			N_("register clean resolutions in index"), 1),
-		OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
-			N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
-
-	if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
-		die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
+	argc = parse_options(argc, argv, prefix, options, rerere_usage,
+			     PARSE_OPT_KEEP_UNKNOWN_OPT);
 
 	repo_config(repo, git_xmerge_config, NULL);
 
@@ -215,11 +234,10 @@ int cmd_rerere(int argc,
 
 	if (!strcmp(argv[0], "forget"))
 		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear")) {
+	else if (!strcmp(argv[0], "clear"))
 		return cmd_rerere_clear(argc, argv, prefix, repo);
-	} else if (!strcmp(argv[0], "gc"))
-		rerere_gc(repo, &merge_rr,
-			  skip_locked ? RERERE_NOWAIT : 0);
+	else if (!strcmp(argv[0], "gc"))
+		return cmd_rerere_gc(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "status"))
 		return cmd_rerere_status(argc, argv, prefix, repo);
 	else if (!strcmp(argv[0], "remaining"))
@@ -229,6 +247,5 @@ int cmd_rerere(int argc,
 	else
 		usage_with_options(rerere_usage, options);
 
-	string_list_clear(&merge_rr, 1);
 	return 0;
 }
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index ab412ecc6e8..0d4cbf5114a 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -263,11 +263,6 @@ test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
 	test_path_is_missing $rr2/preimage
 '
 
-test_expect_success '--skip-locked is only accepted by gc' '
-	test_must_fail git rerere --skip-locked clear 2>err &&
-	test_grep "option .--skip-locked. requires .gc." err
-'
-
 test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
 	git reset --hard &&
 	rm -rf $rr &&
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 11/13] builtin/rerere: use `OPT_SUBCOMMAND()`

In git-rerere(1) we have our own custom logic to parse subcommands. In preceding commits we have refactored all of those subcommands so that they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use these so that we get rid of our custom subcommand parsing.

Unfortunately this means that we have a backwards-incompatible change because we no longer accept the "--[no-]rerere-autoupdate" flag for all subcommands. But this was arguably broken and misleading as we ignore this flag for any other subcommand aynway. So we cheat a bit and simply call it a bug that those flags were accepted in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rerere.c | 95 +++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 29 deletions(-)
Show changes to builtin/rerere.c +66 −29
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 3162b074ec6..8707c65560d 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -5,6 +5,7 @@
 #include "rerere.h"
 #include "strbuf.h"
 #include "string-list.h"
+#include "strvec.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "pathspec.h"
@@ -152,6 +153,31 @@ static int cmd_rerere_gc(int argc,
 	return 0;
 }
 
+static int cmd_rerere_perform(int argc,
+			      const char **argv,
+			      const char *prefix,
+			      struct repository *repo)
+{
+	int autoupdate = -1;
+	struct option options[] = {
+		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+			N_("register clean resolutions in index"), 1),
+		OPT_END(),
+	};
+	enum rerere_flags flags = 0;
+
+	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	if (argc)
+		usage(_("too many arguments"));
+
+	if (autoupdate == 1)
+		flags = RERERE_AUTOUPDATE;
+	if (autoupdate == 0)
+		flags = RERERE_NOAUTOUPDATE;
+
+	return rerere(repo, flags);
+}
+
 static int cmd_rerere_remaining(int argc,
 				const char **argv,
 				const char *prefix,
@@ -211,41 +237,52 @@ int cmd_rerere(int argc,
 	       const char *prefix,
 	       struct repository *repo)
 {
-	int autoupdate = -1, flags = 0;
-
+	parse_opt_subcommand_fn *fn = NULL;
 	struct option options[] = {
-		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
-			N_("register clean resolutions in index"), 1),
+		OPT_SUBCOMMAND("clear", &fn, cmd_rerere_clear),
+		OPT_SUBCOMMAND("diff", &fn, cmd_rerere_diff),
+		OPT_SUBCOMMAND("forget", &fn, cmd_rerere_forget),
+		OPT_SUBCOMMAND("gc", &fn, cmd_rerere_gc),
+		OPT_SUBCOMMAND("remaining", &fn, cmd_rerere_remaining),
+		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
-			     PARSE_OPT_KEEP_UNKNOWN_OPT);
-
+			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
 	repo_config(repo, git_xmerge_config, NULL);
 
-	if (autoupdate == 1)
-		flags = RERERE_AUTOUPDATE;
-	if (autoupdate == 0)
-		flags = RERERE_NOAUTOUPDATE;
-
-	if (argc < 1)
-		return rerere(repo, flags);
-
-	if (!strcmp(argv[0], "forget"))
-		return cmd_rerere_forget(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "clear"))
-		return cmd_rerere_clear(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "gc"))
-		return cmd_rerere_gc(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "status"))
-		return cmd_rerere_status(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "remaining"))
-		return cmd_rerere_remaining(argc, argv, prefix, repo);
-	else if (!strcmp(argv[0], "diff"))
-		return cmd_rerere_diff(argc, argv, prefix, repo);
-	else
-		usage_with_options(rerere_usage, options);
+	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);
+
+		/*
+		 * 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 + 1);
+		COPY_ARRAY(args_copy, args.v, args.nr);
+
+		ret = cmd_rerere_perform(args.nr, args_copy, prefix, repo);
+
+		strvec_clear(&args);
+		free(args_copy);
+		return ret;
+	}
 
-	return 0;
+	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.1.831.g720f3f5937.dirty
Junio C Hamano· Nov 19, 2026, 22:43 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v5 11/13] builtin/rerere: use `OPT_SUBCOMMAND()`

Patrick Steinhardt <ps@pks.im> writes:
Show 10 quoted lines
> In git-rerere(1) we have our own custom logic to parse subcommands. In
> preceding commits we have refactored all of those subcommands so that
> they are ready to be used as `OPT_SUBCOMMAND()`s. Switch over to use
> these so that we get rid of our custom subcommand parsing.
>
> Unfortunately this means that we have a backwards-incompatible change
> because we no longer accept the "--[no-]rerere-autoupdate" flag for all
> subcommands. But this was arguably broken and misleading as we ignore
> this flag for any other subcommand aynway. So we cheat a bit and simply
> call it a bug that those flags were accepted in the first place.
Aynway.
Show 12 quoted lines
> +static int cmd_rerere_perform(int argc,
> +			      const char **argv,
> +			      const char *prefix,
> +			      struct repository *repo)
> +{
> +	int autoupdate = -1;
> +	struct option options[] = {
> +		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
> +			N_("register clean resolutions in index"), 1),
> +		OPT_END(),
> +	};
> +	enum rerere_flags flags = 0;
The "register clean resolutions in index" text used to be given for "-h"
    $ rungit master rerere -h
    usage: git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
        --[no-]rerere-autoupdate
                              register clean resolutions in index
but we moved it to this subcommand.

It was a bug that "git rerere diff --no-rerere-autoupdate" did not complain. Because this option only appears here, those subcommands would now complain when they see the --no-rerere-autoupdate option.

Which is very good.

What is a bit sad is that it has become very hard to actually see this help text.

    $ rungit seen rerere -h
    usage: git rerere [--[no-]rerere-autoupdate]
       or: git rerere clear
       or: git rerere diff
       or: git rerere forget <pathspec>...
       or: git rerere gc
       or: git rerere remaining
       or: git rerere status

Because the primary subcommand (i.e., record and replay after you got a conflict in the working tree) does not have a subcommand verb, "git rerere -h" would trigger the help for the top-level command, and the help is shown from there without using the options[] array in this subcommand.

I said "very hard", not impossible, because there is an awkward way to see this.

    $ rungit seen rerere -- -h
    $ rungit seen rerere --rerere-autoupdate -h
Both of which would give you
    usage: git rerere [--[no-]rerere-autoupdate]
        --[no-]rerere-autoupdate
                              register clean resolutions in index
but it probably is not what users will ever use.

I think it is OK to stop here and leave the above as-is. The only people who use this option are those who already know and are used to it. Everybody else I would imagine would rather use

	git -c rerere.autoupdate=no rerere
instead.
It might have fallouts on --git-completion-helper, too.
    $ rungit master rerere --git-completion-helper
    --rerere-autoupdate --no-rerere-autoupdate
    $ rungit seen rerere --git-completion-helper
    clear diff forget gc remaining status

Arguably, the updated choices are better, but I do not know offhand how the bash completion script uses this (specifically, the old output was so bad that it may have workaround that we will no longer need with your improvements).

Thanks.
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 12/13] builtin/rerere: introduce proper usage strings for subcommands

Adapt git-rerere(1) to have proper usage strings for each of the subcommands.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc |  8 +++++-
 builtin/rerere.c              | 61 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 58 insertions(+), 11 deletions(-)
Show changes to 2 files +58 −11

Documentation/git-rerere.adoc, builtin/rerere.c

diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index 4e6ab9a27c9..e04e9ef3ef8 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -8,7 +8,13 @@ git-rerere - Reuse recorded resolution of conflicted merges
 SYNOPSIS
 --------
 [verse]
-'git rerere' [clear | forget <pathspec>... | diff | status | remaining | gc]
+'git rerere' [--[no-]rerere-autoupdate]
+'git rerere' clear
+'git rerere' diff
+'git rerere' forget <pathspec>...
+'git rerere' gc
+'git rerere' remaining
+'git rerere' status
 
 DESCRIPTION
 -----------
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 8707c65560d..5f1c0f31f6a 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -10,10 +10,13 @@
 #include "xdiff-interface.h"
 #include "pathspec.h"
 
-static const char * const rerere_usage[] = {
-	N_("git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]"),
-	NULL,
-};
+#define RERERE_USAGE N_("git rerere [--[no-]rerere-autoupdate]")
+#define RERERE_CLEAR_USAGE N_("git rerere clear")
+#define RERERE_DIFF_USAGE N_("git rerere diff")
+#define RERERE_FORGET_USAGE N_("git rerere forget <pathspec>...")
+#define RERERE_GC_USAGE N_("git rerere gc")
+#define RERERE_REMAINING_USAGE N_("git rerere remaining")
+#define RERERE_STATUS_USAGE N_("git rerere status")
 
 static int outf(void *dummy UNUSED, mmfile_t *ptr, int nbuf)
 {
@@ -61,9 +64,13 @@ static int cmd_rerere_clear(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_clear_usage[] = {
+		RERERE_CLEAR_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_clear_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -81,11 +88,15 @@ static int cmd_rerere_diff(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_diff_usage[] = {
+		RERERE_DIFF_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_diff_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -115,10 +126,14 @@ static int cmd_rerere_forget(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_forget_usage[] = {
+		RERERE_FORGET_USAGE,
+		NULL,
+	};
 	struct pathspec pathspec;
 	int ret;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_forget_usage, 0);
 	if (!argc)
 		warning(_("'git rerere forget' without paths is deprecated"));
 	parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
@@ -140,9 +155,13 @@ static int cmd_rerere_gc(int argc,
 				N_("skip gc while another process holds the lock")),
 		OPT_END(),
 	};
+	const char * const rerere_gc_usage[] = {
+		RERERE_GC_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_gc_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -164,6 +183,10 @@ static int cmd_rerere_perform(int argc,
 			N_("register clean resolutions in index"), 1),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		NULL,
+	};
 	enum rerere_flags flags = 0;
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
@@ -186,9 +209,13 @@ static int cmd_rerere_remaining(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_remaining_usage[] = {
+		RERERE_REMAINING_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_remaining_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -214,10 +241,14 @@ static int cmd_rerere_status(int argc,
 	struct option options[] = {
 		OPT_END(),
 	};
+	const char * const rerere_status_usage[] = {
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 	struct string_list merge_rr = STRING_LIST_INIT_DUP;
 	struct rerere_cache cache;
 
-	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, rerere_status_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
@@ -247,6 +278,16 @@ int cmd_rerere(int argc,
 		OPT_SUBCOMMAND("status", &fn, cmd_rerere_status),
 		OPT_END(),
 	};
+	const char * const rerere_usage[] = {
+		RERERE_USAGE,
+		RERERE_CLEAR_USAGE,
+		RERERE_DIFF_USAGE,
+		RERERE_FORGET_USAGE,
+		RERERE_GC_USAGE,
+		RERERE_REMAINING_USAGE,
+		RERERE_STATUS_USAGE,
+		NULL,
+	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage,
 			     PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_SUBCOMMAND_OPTIONAL);
-- 
2.56.1.831.g720f3f5937.dirty
Patrick Steinhardt· Nov 19, 2026, 11:47 UTC · re: Patrick Steinhardt · lore

[PATCH v5 13/13] Documentation/git-rerere: drop claim that we pass args to diff(1)

Back in the old days, `git rerere diff` accepted arbitrary arguments that would be passed on to the system `diff` command. This has changed in 658f3650273 (Make git-rerere a builtin, 2006-12-20), even though that change seems to have been unintentional. And in fact, our documentation still claims that arbitrary arguments are accepted.

While the original change was unintended, nobody has complained in the last two decades, so it's rather unlikely that anybody cares about this regression nowadays. Adapt the documentation to match current behaviour.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rerere.adoc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to Documentation/git-rerere.adoc +1 −2
diff --git a/Documentation/git-rerere.adoc b/Documentation/git-rerere.adoc
index e04e9ef3ef8..2a5b443610a 100644
--- a/Documentation/git-rerere.adoc
+++ b/Documentation/git-rerere.adoc
@@ -56,8 +56,7 @@ conflicts in paths that match <pathspec>.
 
 Display diffs for the current state of the resolution.  It is
 useful for tracking what has changed while the user is resolving
-conflicts.  Additional arguments are passed directly to the system
-'diff' command installed in PATH.
+conflicts.
 
 'status'::
 
-- 
2.56.1.831.g720f3f5937.dirty

← back to recent threads