merge-recursive: take advantage of hardcoded empty tree
When this code was first written (v1.4.3-rc1~174^2~4, merge-recur: if there is no common ancestor, fake empty one, 2006-08-09), everyone needing a fake empty tree had to make her own, but ever since v1.5.5-rc0~180^2~1 (2008-02-13), the object lookup machinery provides a ready-made one. Use it. This is just a simplification, though it also fixes a small leak (since the tree in the virtual common ancestor commit is never freed). Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 16, 2011 at 13:27 UTC
03f622c81fed05bb571519beacb0eeaf595c65f4
1 file changed
+3
-5
merge-recursive.c
+3
-5
@@ -1309,12 +1309,10 @@ int merge_recursive(struct merge_options *o,
1309
1310
merged_common_ancestors = pop_commit(&ca);
1311
if (merged_common_ancestors == NULL) {
1312
- /* if there is no common ancestor, make an empty tree */
1313
- struct tree *tree = xcalloc(1, sizeof(struct tree));
1312
+ /* if there is no common ancestor, use an empty tree */
1313
+ struct tree *tree;
1314
1315
- tree->object.parsed = 1;
1316
- tree->object.type = OBJ_TREE;
1317
- pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
1315
+ tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
1316
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
1317
}
1318