Merge branch 'jn/plug-empty-tree-leak'

* jn/plug-empty-tree-leak:
  merge-recursive: take advantage of hardcoded empty tree
  revert: plug memory leak in "cherry-pick root commit" codepath
This commit is contained in:
Junio C Hamano 2011-08-25 16:00:29 -07:00
commit 7abd8fb36d
3 changed files with 30 additions and 12 deletions

View File

@ -258,12 +258,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename)
static struct tree *empty_tree(void)
{
struct tree *tree = xcalloc(1, sizeof(struct tree));
tree->object.parsed = 1;
tree->object.type = OBJ_TREE;
pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
return tree;
return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
}
static NORETURN void die_dirty_index(const char *me)

View File

@ -1601,12 +1601,10 @@ int merge_recursive(struct merge_options *o,
merged_common_ancestors = pop_commit(&ca);
if (merged_common_ancestors == NULL) {
/* if there is no common ancestor, make an empty tree */
struct tree *tree = xcalloc(1, sizeof(struct tree));
/* if there is no common ancestor, use an empty tree */
struct tree *tree;
tree->object.parsed = 1;
tree->object.type = OBJ_TREE;
pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
}

View File

@ -16,12 +16,20 @@ test_expect_success setup '
echo second > file2 &&
git add file2 &&
test_tick &&
git commit -m "second"
git commit -m "second" &&
git symbolic-ref HEAD refs/heads/third &&
rm .git/index file2 &&
echo third > file3 &&
git add file3 &&
test_tick &&
git commit -m "third"
'
test_expect_success 'cherry-pick a root commit' '
git checkout second^0 &&
git cherry-pick master &&
echo first >expect &&
test_cmp expect file1
@ -50,4 +58,21 @@ test_expect_success 'revert a root commit with an external strategy' '
'
test_expect_success 'cherry-pick two root commits' '
echo first >expect.file1 &&
echo second >expect.file2 &&
echo third >expect.file3 &&
git checkout second^0 &&
git cherry-pick master third &&
test_cmp expect.file1 file1 &&
test_cmp expect.file2 file2 &&
test_cmp expect.file3 file3 &&
git rev-parse --verify HEAD^^ &&
test_must_fail git rev-parse --verify HEAD^^^
'
test_done