]> git.ipfire.org Git - thirdparty/git.git/commitdiff
history: give commit_tree_ext a message template
authorHarald Nordgren <haraldnordgren@gmail.com>
Mon, 20 Jul 2026 08:27:01 +0000 (08:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Jul 2026 17:36:55 +0000 (10:36 -0700)
commit_tree_ext() reuses the message of the commit it is handed. A
caller that folds several commits together wants to seed the message
from more than that single commit, so add an optional message_template
parameter. When NULL, the behavior is unchanged.

Pass NULL from the existing fixup and split callers.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/history.c

index 673744a55a33f1e68199da6e2fb377ccaf97f93e..b592b98393c640db5da7a6cabd21a8c9a14b8823 100644 (file)
@@ -108,6 +108,7 @@ enum commit_tree_flags {
 static int commit_tree_ext(struct repository *repo,
                           const char *action,
                           struct commit *commit_with_message,
+                          const char *message_template,
                           const struct commit_list *parents,
                           const struct object_id *old_tree,
                           const struct object_id *new_tree,
@@ -137,13 +138,16 @@ static int commit_tree_ext(struct repository *repo,
                original_author = xmemdupz(ptr, len);
        find_commit_subject(original_message, &original_body);
 
+       if (!message_template)
+               message_template = original_body;
+
        if (flags & COMMIT_TREE_EDIT_MESSAGE) {
                ret = fill_commit_message(repo, old_tree, new_tree,
-                                         original_body, action, &commit_message);
+                                         message_template, action, &commit_message);
                if (ret < 0)
                        goto out;
        } else {
-               strbuf_addstr(&commit_message, original_body);
+               strbuf_addstr(&commit_message, message_template);
        }
 
        original_extra_headers = read_commit_extra_headers(commit_with_message,
@@ -196,7 +200,7 @@ static int commit_tree_with_edited_message(struct repository *repo,
        if (first_parent_tree_oid(repo, original, &parent_tree_oid) < 0)
                return -1;
 
-       return commit_tree_ext(repo, action, original, original->parents,
+       return commit_tree_ext(repo, action, original, NULL, original->parents,
                               &parent_tree_oid, tree_oid, out, COMMIT_TREE_EDIT_MESSAGE);
 }
 
@@ -675,7 +679,7 @@ static int cmd_history_fixup(int argc,
                goto out;
 
        if (!skip_commit) {
-               ret = commit_tree_ext(repo, "fixup", original, original->parents,
+               ret = commit_tree_ext(repo, "fixup", original, NULL, original->parents,
                                      &original_tree->object.oid, &merge_result.tree->object.oid,
                                      &rewritten, flags);
                if (ret < 0) {
@@ -886,7 +890,7 @@ static int split_commit(struct repository *repo,
         * The first commit is constructed from the split-out tree. The base
         * that shall be diffed against is the parent of the original commit.
         */
-       ret = commit_tree_ext(repo, "split-out", original, original->parents, &parent_tree_oid,
+       ret = commit_tree_ext(repo, "split-out", original, NULL, original->parents, &parent_tree_oid,
                              &split_tree->object.oid, &first_commit, COMMIT_TREE_EDIT_MESSAGE);
        if (ret < 0) {
                ret = error(_("failed writing first commit"));
@@ -903,7 +907,7 @@ static int split_commit(struct repository *repo,
        old_tree_oid = &repo_get_commit_tree(repo, first_commit)->object.oid;
        new_tree_oid = &repo_get_commit_tree(repo, original)->object.oid;
 
-       ret = commit_tree_ext(repo, "split-out", original, parents, old_tree_oid,
+       ret = commit_tree_ext(repo, "split-out", original, NULL, parents, old_tree_oid,
                              new_tree_oid, &second_commit, COMMIT_TREE_EDIT_MESSAGE);
        if (ret < 0) {
                ret = error(_("failed writing second commit"));