Skip to content

Commit 910a09a

Browse files
rscharfegitster
authored andcommitted
merge: simplify merge_trivial() by using commit_list_append()
Build the commit_list of parents by calling commit_list_append() twice instead of allocating and linking the items by hand. This makes the code shorter and simpler. Rename the commit_list from parent to parents (plural) while at it because there are two of them. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 294b268 commit 910a09a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

builtin/merge.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)
843843
static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
844844
{
845845
unsigned char result_tree[20], result_commit[20];
846-
struct commit_list *parent = xmalloc(sizeof(*parent));
846+
struct commit_list *parents, **pptr = &parents;
847847

848848
write_tree_trivial(result_tree);
849849
printf(_("Wonderful.\n"));
850-
parent->item = head;
851-
parent->next = xmalloc(sizeof(*parent->next));
852-
parent->next->item = remoteheads->item;
853-
parent->next->next = NULL;
850+
pptr = commit_list_append(head, pptr);
851+
pptr = commit_list_append(remoteheads->item, pptr);
854852
prepare_to_commit(remoteheads);
855-
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent,
853+
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
856854
result_commit, NULL, sign_commit))
857855
die(_("failed to write commit object"));
858856
finish(head, remoteheads, result_commit, "In-index merge");

0 commit comments

Comments
 (0)