From: Patrick Steinhardt Date: Fri, 06 Nov 2026 15:14:03 GMT Subject: [PATCH v3 09/12] builtin/rerere: turn "diff" into a proper subcommand Message-ID: <20261106-pks-rerere-subcommands-v3-9-4ff164d8fb81@pks.im> In-Reply-To: <20261106-pks-rerere-subcommands-v3-0-4ff164d8fb81@pks.im> 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 --- builtin/rerere.c | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) 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