git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] merge: simplify merge_trivial() by using commit_list_append()

From
René Scharfe <l.s.r@web.de>
Date
Jul 10, 2014, 09:41 UTC
Message-ID
<53BE5FD4.1050707@web.de>

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>
---
 builtin/merge.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index b49c310..f50270e 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -843,16 +843,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
 {
 	unsigned char result_tree[20], result_commit[20];
-	struct commit_list *parent = xmalloc(sizeof(*parent));
+	struct commit_list *parents, **pptr = &parents;
 
 	write_tree_trivial(result_tree);
 	printf(_("Wonderful.\n"));
-	parent->item = head;
-	parent->next = xmalloc(sizeof(*parent->next));
-	parent->next->item = remoteheads->item;
-	parent->next->next = NULL;
+	pptr = commit_list_append(head, pptr);
+	pptr = commit_list_append(remoteheads->item, pptr);
 	prepare_to_commit(remoteheads);
-	if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent,
+	if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
 			result_commit, NULL, sign_commit))
 		die(_("failed to write commit object"));
 	finish(head, remoteheads, result_commit, "In-index merge");
-- 
2.0.0
Message 1 of 1 in “merge: simplify merge_trivial() by using commit_list_append()”
  1. merge: simplify merge_trivial() by using commit_list_append()René Scharfe, Jul 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.