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

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

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 19, 2026, 11:47 UTC
Message-ID
<20261119-pks-rerere-subcommands-v5-0-0c1092b88958@pks.im>
In-Reply-To
<20261027-pks-rerere-subcommands-v1-0-d836c36ce0c5@pks.im>
Hi,

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

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

Changes in v5:
  - Explicitly docmuent the change in behaviour for the "--skip-lock"
    flag.
  - Add another patch to fix our documentation of `git rerere diff`,
    which has been stale for the last two decades.
  - Fix a regression where we didn't print the synopsis anymore when an
    unknown subcommand is being passed.
  - NULL-terminate argv.
  - Link to v4: https://patch.msgid.link/20261111-pks-rerere-subcommands-v4-0-df0c8bf79e16@pks.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

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 94 of 107 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
  94. 00/13 builtin/rerere: convert to use subcommandsPatrick Steinhardt, Nov 19, 2026
  95. 01/13 rerere: rename `repo_rerere()`Patrick Steinhardt, Nov 19, 2026
  96. 02/13 rerere: convert flags into an enumPatrick Steinhardt, Nov 19, 2026
  97. 03/13 builtin/rerere: drop `the_repository`Patrick Steinhardt, Nov 19, 2026
  98. 04/13 builtin/rerere: stop passing flags to subcommands that ignore themPatrick Steinhardt, Nov 19, 2026
  99. 05/13 builtin/rerere: turn "forget" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  100. 06/13 builtin/rerere: turn "clear" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  101. 07/13 builtin/rerere: turn "status" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  102. 08/13 builtin/rerere: turn "remaining" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  103. 09/13 builtin/rerere: turn "diff" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  104. 10/13 builtin/rerere: turn "gc" into a proper subcommandPatrick Steinhardt, Nov 19, 2026
  105. 11/13 builtin/rerere: use `OPT_SUBCOMMAND()`Patrick Steinhardt, Nov 19, 2026
  106. 12/13 builtin/rerere: introduce proper usage strings for subcommandsPatrick Steinhardt, Nov 19, 2026
  107. 13/13 Documentation/git-rerere: drop claim that we pass args to diff(1)Patrick Steinhardt, Nov 19, 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.