summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86c7bb4)
raw | patch | inline | side by side (parent: 86c7bb4)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Sun, 14 Aug 2011 15:22:04 +0000 (10:22 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 16 Aug 2011 17:51:34 +0000 (10:51 -0700) |
The empty tree passed as common ancestor to merge_trees() when
cherry-picking a parentless commit is allocated on the heap and never
freed. Leaking such a small one-time allocation is not a very big
problem, but now that "git cherry-pick" can cherry-pick multiple
commits it can start to add up.
Avoid the leak by storing the fake tree exactly once in the BSS
section (i.e., use a static). While at it, let's add a test to make
sure cherry-picking multiple parentless commits continues to work.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cherry-picking a parentless commit is allocated on the heap and never
freed. Leaking such a small one-time allocation is not a very big
problem, but now that "git cherry-pick" can cherry-pick multiple
commits it can start to add up.
Avoid the leak by storing the fake tree exactly once in the BSS
section (i.e., use a static). While at it, let's add a test to make
sure cherry-picking multiple parentless commits continues to work.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/revert.c | patch | blob | history | |
t/t3503-cherry-pick-root.sh | patch | blob | history |
diff --git a/builtin/revert.c b/builtin/revert.c
index 853e9e406c7fe258c39fa7e5c53f15f739a935b1..a26a7c93156b8826a92e4f92e5be6d5aee81b6a2 100644 (file)
--- a/builtin/revert.c
+++ b/builtin/revert.c
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)
index b0faa299183df5fe06ccaf383bce47cbb9a0cf89..472e5b80d7ac9b5c90810bd0869510e1e2970f81 100755 (executable)
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 &&
test first = $(cat file1)
'
+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