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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 10, 2014 at 11:41 UTC 910a09a7350a556f7f367680294fca8d05ddc5f5
1 file changed +4 -6
builtin/merge.c
+4 -6
@@ -843,16 +843,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)
843 static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
844 {
845 unsigned char result_tree[20], result_commit[20];
846 - struct commit_list *parent = xmalloc(sizeof(*parent));
846 + struct commit_list *parents, **pptr = &parents;
847
848 write_tree_trivial(result_tree);
849 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);
852 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,
854 result_commit, NULL, sign_commit))
855 die(_("failed to write commit object"));
856 finish(head, remoteheads, result_commit, "In-index merge");