history: give commit_tree_ext a message template
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>
Harald Nordgren committed
Aug 1, 2026 at 06:53 UTC
67b248e248dfa61fe4e9f7d4285e4c6429bf650f
1 file changed
+10
-6
builtin/history.c
+10
-6
@@ -108,6 +108,7 @@ enum commit_tree_flags {
108
static int commit_tree_ext(struct repository *repo,
109
const char *action,
110
struct commit *commit_with_message,
111
+ const char *message_template,
112
const struct commit_list *parents,
113
const struct object_id *old_tree,
114
const struct object_id *new_tree,
@@ -137,13 +138,16 @@ static int commit_tree_ext(struct repository *repo,
138
original_author = xmemdupz(ptr, len);
139
find_commit_subject(original_message, &original_body);
140
141
+ if (!message_template)
142
+ message_template = original_body;
143
+
144
if (flags & COMMIT_TREE_EDIT_MESSAGE) {
145
ret = fill_commit_message(repo, old_tree, new_tree,
142
- original_body, action, &commit_message);
146
+ message_template, action, &commit_message);
147
if (ret < 0)
148
goto out;
149
} else {
146
- strbuf_addstr(&commit_message, original_body);
150
+ strbuf_addstr(&commit_message, message_template);
151
}
152
153
original_extra_headers = read_commit_extra_headers(commit_with_message,
@@ -196,7 +200,7 @@ static int commit_tree_with_edited_message(struct repository *repo,
200
if (first_parent_tree_oid(repo, original, &parent_tree_oid) < 0)
201
return -1;
202
199
- return commit_tree_ext(repo, action, original, original->parents,
203
+ return commit_tree_ext(repo, action, original, NULL, original->parents,
204
&parent_tree_oid, tree_oid, out, COMMIT_TREE_EDIT_MESSAGE);
205
}
206
@@ -675,7 +679,7 @@ static int cmd_history_fixup(int argc,
679
goto out;
680
681
if (!skip_commit) {
678
- ret = commit_tree_ext(repo, "fixup", original, original->parents,
682
+ ret = commit_tree_ext(repo, "fixup", original, NULL, original->parents,
683
&original_tree->object.oid, &merge_result.tree->object.oid,
684
&rewritten, flags);
685
if (ret < 0) {
@@ -886,7 +890,7 @@ static int split_commit(struct repository *repo,
890
* The first commit is constructed from the split-out tree. The base
891
* that shall be diffed against is the parent of the original commit.
892
*/
889
- ret = commit_tree_ext(repo, "split-out", original, original->parents, &parent_tree_oid,
893
+ ret = commit_tree_ext(repo, "split-out", original, NULL, original->parents, &parent_tree_oid,
894
&split_tree->object.oid, &first_commit, COMMIT_TREE_EDIT_MESSAGE);
895
if (ret < 0) {
896
ret = error(_("failed writing first commit"));
@@ -903,7 +907,7 @@ static int split_commit(struct repository *repo,
907
old_tree_oid = &repo_get_commit_tree(repo, first_commit)->object.oid;
908
new_tree_oid = &repo_get_commit_tree(repo, original)->object.oid;
909
906
- ret = commit_tree_ext(repo, "split-out", original, parents, old_tree_oid,
910
+ ret = commit_tree_ext(repo, "split-out", original, NULL, parents, old_tree_oid,
911
new_tree_oid, &second_commit, COMMIT_TREE_EDIT_MESSAGE);
912
if (ret < 0) {
913
ret = error(_("failed writing second commit"));