git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 29, 2026, 09:57 UTC
Message-ID
<20261029-pks-rerere-subcommands-v2-0-07d5ba18e882@pks.im>
In-Reply-To
<20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im>
Hi,

while reviewing some patch series around git-rerere(1) recently I was a bit appalled by our custom subcommand parsing that we do here. This patch series here thus cleans up and modernizes that part a bit so that git-rerere(1) behaves like every other Git command that happens to have subcommands.

This series is based on 37b3475fb53 (The 9th batch, 2026-10-25) with ps/rerere-remove-global-state at b948c10c8b3 (rerere: get rid of global rerere cache state, 2026-10-23) merged into it.

Changes in 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

Previous: Junio C HamanoNext: Patrick Steinhardt
Message 23 of 93 in “builtin/rerere: convert to use subcommands”
  1. 00/12 builtin/rerere: convert to use subcommandsPatrick Steinhardt, Oct 27, 2026
  2. 01/12 rerere: rename `repo_rerere()`Patrick Steinhardt, Oct 27, 2026
  3. Junio C HamanoOct 27, 2026
  4. Patrick SteinhardtOct 28, 2026
  5. Junio C HamanoOct 28, 2026
  6. 02/12 rerere: convert flags into an enumPatrick Steinhardt, Oct 27, 2026
  7. Mark C. Chu-CarrollOct 27, 2026
  8. Junio C HamanoOct 27, 2026
  9. Patrick SteinhardtOct 28, 2026
  10. Mark C. Chu-CarrollOct 28, 2026
  11. Junio C HamanoOct 28, 2026
  12. 03/12 builtin/rerere: drop `the_repository`Patrick Steinhardt, Oct 27, 2026
  13. 04/12 builtin/rerere: stop passing flags to subcommands that ignore themPatrick Steinhardt, Oct 27, 2026
  14. 05/12 builtin/rerere: turn "forget" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  15. 06/12 builtin/rerere: turn "clear" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  16. 07/12 builtin/rerere: turn "status" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  17. 08/12 builtin/rerere: turn "remaining" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  18. 09/12 builtin/rerere: turn "diff" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  19. 10/12 builtin/rerere: turn "gc" into a proper subcommandPatrick Steinhardt, Oct 27, 2026
  20. 11/12 builtin/rerere: use `OPT_SUBCOMMAND()`Patrick Steinhardt, Oct 27, 2026
  21. 12/12 builtin/rerere: introduce proper usage strings for subcommandsPatrick Steinhardt, Oct 27, 2026
  22. Junio C HamanoOct 27, 2026
  23. 00/12 builtin/rerere: convert to use subcommandsPatrick Steinhardt, Oct 29, 2026
  24. 01/12 rerere: rename `repo_rerere()`Patrick Steinhardt, Oct 29, 2026
  25. 02/12 rerere: convert flags into an enumPatrick Steinhardt, Oct 29, 2026
  26. Karthik NayakNov 6, 2026
  27. Patrick SteinhardtNov 6, 2026
  28. Karthik NayakNov 6, 2026
  29. 03/12 builtin/rerere: drop `the_repository`Patrick Steinhardt, Oct 29, 2026
  30. 04/12 builtin/rerere: stop passing flags to subcommands that ignore themPatrick Steinhardt, Oct 29, 2026
  31. 05/12 builtin/rerere: turn "forget" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  32. 06/12 builtin/rerere: turn "clear" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  33. 07/12 builtin/rerere: turn "status" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  34. 08/12 builtin/rerere: turn "remaining" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  35. 09/12 builtin/rerere: turn "diff" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  36. 10/12 builtin/rerere: turn "gc" into a proper subcommandPatrick Steinhardt, Oct 29, 2026
  37. Karthik NayakNov 6, 2026
  38. 11/12 builtin/rerere: use `OPT_SUBCOMMAND()`Patrick Steinhardt, Oct 29, 2026
  39. Karthik NayakNov 6, 2026
  40. Patrick SteinhardtNov 6, 2026
  41. 12/12 builtin/rerere: introduce proper usage strings for subcommandsPatrick Steinhardt, Oct 29, 2026
  42. Karthik NayakNov 6, 2026
  43. 00/12 builtin/rerere: convert to use subcommandsPatrick Steinhardt, Nov 6, 2026
  44. 01/12 rerere: rename `repo_rerere()`Patrick Steinhardt, Nov 6, 2026
  45. 02/12 rerere: convert flags into an enumPatrick Steinhardt, Nov 6, 2026
  46. Junio C HamanoNov 6, 2026
  47. Patrick SteinhardtNov 9, 2026
  48. Junio C HamanoNov 9, 2026
  49. Junio C HamanoNov 9, 2026
  50. Patrick SteinhardtNov 11, 2026
  51. 03/12 builtin/rerere: drop `the_repository`Patrick Steinhardt, Nov 6, 2026
  52. 04/12 builtin/rerere: stop passing flags to subcommands that ignore themPatrick Steinhardt, Nov 6, 2026
  53. 05/12 builtin/rerere: turn "forget" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  54. 06/12 builtin/rerere: turn "clear" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  55. 07/12 builtin/rerere: turn "status" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  56. 08/12 builtin/rerere: turn "remaining" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  57. 09/12 builtin/rerere: turn "diff" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  58. 10/12 builtin/rerere: turn "gc" into a proper subcommandPatrick Steinhardt, Nov 6, 2026
  59. 11/12 builtin/rerere: use `OPT_SUBCOMMAND()`Patrick Steinhardt, Nov 6, 2026
  60. 12/12 builtin/rerere: introduce proper usage strings for subcommandsPatrick Steinhardt, Nov 6, 2026
  61. 00/12 builtin/rerere: convert to use subcommandsPatrick Steinhardt, Nov 11, 2026
  62. 01/12 rerere: rename `repo_rerere()`Patrick Steinhardt, Nov 11, 2026
  63. 02/12 rerere: convert flags into an enumPatrick Steinhardt, Nov 11, 2026
  64. 03/12 builtin/rerere: drop `the_repository`Patrick Steinhardt, Nov 11, 2026
  65. 04/12 builtin/rerere: stop passing flags to subcommands that ignore themPatrick Steinhardt, Nov 11, 2026
  66. 05/12 builtin/rerere: turn "forget" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  67. 06/12 builtin/rerere: turn "clear" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  68. 07/12 builtin/rerere: turn "status" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  69. 08/12 builtin/rerere: turn "remaining" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  70. 09/12 builtin/rerere: turn "diff" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  71. Junio C HamanoNov 17, 2026
  72. 10/12 builtin/rerere: turn "gc" into a proper subcommandPatrick Steinhardt, Nov 11, 2026
  73. Junio C HamanoNov 17, 2026
  74. 11/12 builtin/rerere: use `OPT_SUBCOMMAND()`Patrick Steinhardt, Nov 11, 2026
  75. Junio C HamanoNov 17, 2026
  76. Patrick SteinhardtNov 18, 2026
  77. Junio C HamanoNov 18, 2026
  78. 12/12 builtin/rerere: introduce proper usage strings for subcommandsPatrick Steinhardt, Nov 11, 2026
  79. Junio C HamanoNov 17, 2026
  80. Patrick SteinhardtNov 18, 2026
  81. Karthik NayakNov 12, 2026
  82. Patrick SteinhardtNov 13, 2026
  83. Junio C HamanoNov 13, 2026
  84. Tuomas AholaNov 13, 2026
  85. Phillip WoodNov 13, 2026
  86. Junio C HamanoNov 13, 2026
  87. Tuomas AholaNov 14, 2026
  88. Patrick SteinhardtNov 16, 2026
  89. Junio C HamanoNov 14, 2026
  90. Patrick SteinhardtNov 16, 2026
  91. Junio C HamanoNov 16, 2026
  92. Junio C HamanoNov 17, 2026
  93. Patrick SteinhardtNov 18, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.