From: Siddharth Asthana Date: Wed, 18 Feb 2026 23:42:14 GMT Subject: [PATCH v3 1/2] sequencer: extract revert message formatting into shared function Message-ID: <20260218234215.89326-2-siddharthasthana31@gmail.com> In-Reply-To: <20260218234215.89326-1-siddharthasthana31@gmail.com> The logic for formatting revert commit messages (handling "Revert" and "Reapply" cases) is currently duplicated between sequencer.c and will be needed by builtin/replay.c. Extract this logic into a new sequencer_format_revert_header() function that can be shared. The function handles both regular reverts ("Revert """) and revert-of-revert cases ("Reapply """). When an oid is provided, the function appends the full commit hash and period; otherwise the caller should append the commit reference. Update do_pick_commit() to use the new helper, eliminating code duplication while preserving the special handling for commit_use_reference. Signed-off-by: Siddharth Asthana --- sequencer.c | 47 +++++++++++++++++++++++++++++++---------------- sequencer.h | 11 +++++++++++ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/sequencer.c b/sequencer.c index 1f492f8460..b32347c853 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2356,8 +2356,6 @@ static int do_pick_commit(struct repository *r, */ if (command == TODO_REVERT) { - const char *orig_subject; - base = commit; base_label = msg.label; next = parent; @@ -2365,22 +2363,10 @@ static int do_pick_commit(struct repository *r, if (opts->commit_use_reference) { strbuf_commented_addf(&ctx->message, comment_line_str, "*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***"); - } else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) && - /* - * We don't touch pre-existing repeated reverts, because - * theoretically these can be nested arbitrarily deeply, - * thus requiring excessive complexity to deal with. - */ - !starts_with(orig_subject, "Revert \"")) { - strbuf_addstr(&ctx->message, "Reapply \""); - strbuf_addstr(&ctx->message, orig_subject); - strbuf_addstr(&ctx->message, "\n"); + strbuf_addstr(&ctx->message, "\nThis reverts commit "); } else { - strbuf_addstr(&ctx->message, "Revert \""); - strbuf_addstr(&ctx->message, msg.subject); - strbuf_addstr(&ctx->message, "\"\n"); + sequencer_format_revert_header(&ctx->message, msg.subject, NULL); } - strbuf_addstr(&ctx->message, "\nThis reverts commit "); refer_to_commit(opts, &ctx->message, commit); if (commit->parents && commit->parents->next) { @@ -5572,6 +5558,35 @@ int sequencer_pick_revisions(struct repository *r, return res; } +void sequencer_format_revert_header(struct strbuf *out, + const char *orig_subject, + const struct object_id *oid) +{ + const char *revert_subject; + + if (skip_prefix(orig_subject, "Revert \"", &revert_subject) && + /* + * We don't touch pre-existing repeated reverts, because + * theoretically these can be nested arbitrarily deeply, + * thus requiring excessive complexity to deal with. + */ + !starts_with(revert_subject, "Revert \"")) { + strbuf_addstr(out, "Reapply \""); + strbuf_addstr(out, revert_subject); + strbuf_addch(out, '\n'); + } else { + strbuf_addstr(out, "Revert \""); + strbuf_addstr(out, orig_subject); + strbuf_addstr(out, "\"\n"); + } + + strbuf_addstr(out, "\nThis reverts commit "); + if (oid) { + strbuf_addstr(out, oid_to_hex(oid)); + strbuf_addstr(out, ".\n"); + } +} + void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag) { unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP; diff --git a/sequencer.h b/sequencer.h index 719684c8a9..b7291cc52d 100644 --- a/sequencer.h +++ b/sequencer.h @@ -271,4 +271,15 @@ int sequencer_determine_whence(struct repository *r, enum commit_whence *whence) */ int sequencer_get_update_refs_state(const char *wt_dir, struct string_list *refs); +/* + * Formats a revert commit message following standard Git conventions. + * Handles both regular reverts ("Revert \"\"") and revert of revert + * cases ("Reapply \"\""). Adds "This reverts commit ." if oid + * is provided, otherwise just adds "This reverts commit " and the caller + * should append the commit reference. + */ +void sequencer_format_revert_header(struct strbuf *out, + const char *orig_subject, + const struct object_id *oid); + #endif /* SEQUENCER_H */ -- 2.51.0