{"thread":{"id":"37093","subject":"[PATCH] merge: simplify merge_trivial() by using commit_list_append()","startedAt":"2014-07-10T09:41:40Z","lastAt":"2014-07-10T09:41:40Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"245686","messageId":"53BE5FD4.1050707@web.de","threadId":"37093","inReplyTo":null,"subject":"[PATCH] merge: simplify merge_trivial() by using commit_list_append()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-07-10T09:41:40Z","receivedAt":"2014-07-10T09:41:40Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Build the commit_list of parents by calling commit_list_append() twice\ninstead of allocating and linking the items by hand.  This makes the\ncode shorter and simpler.  Rename the commit_list from parent to parents\n(plural) while at it because there are two of them.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/merge.c | 10 ++++------\n 1 file changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b49c310..f50270e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -843,16 +843,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)\n static int merge_trivial(struct commit *head, struct commit_list *remoteheads)\n {\n \tunsigned char result_tree[20], result_commit[20];\n-\tstruct commit_list *parent = xmalloc(sizeof(*parent));\n+\tstruct commit_list *parents, **pptr = &parents;\n \n \twrite_tree_trivial(result_tree);\n \tprintf(_(\"Wonderful.\\n\"));\n-\tparent->item = head;\n-\tparent->next = xmalloc(sizeof(*parent->next));\n-\tparent->next->item = remoteheads->item;\n-\tparent->next->next = NULL;\n+\tpptr = commit_list_append(head, pptr);\n+\tpptr = commit_list_append(remoteheads->item, pptr);\n \tprepare_to_commit(remoteheads);\n-\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent,\n+\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,\n \t\t\tresult_commit, NULL, sign_commit))\n \t\tdie(_(\"failed to write commit object\"));\n \tfinish(head, remoteheads, result_commit, \"In-index merge\");\n-- \n2.0.0\n"}]}