fast-import: fix segfault in store_tree()

Branch tree is NULLified by filedelete command if we are trying to delete root tree. Add sanity check and use load_tree() in that case. Signed-off-by: Maxim Bublis <satori@yandex-team.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Maxim Bublis committed Aug 29, 2014 at 15:53 UTC 2668d692eb1af63097628447f2e0c783b1a45e2e
2 files changed +7 -3
fast-import.c
+5 -1
@@ -1419,7 +1419,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
1419
1420 static void store_tree(struct tree_entry *root)
1421 {
1422 - struct tree_content *t = root->tree;
1422 + struct tree_content *t;
1423 unsigned int i, j, del;
1424 struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
1425 struct object_entry *le = NULL;
@@ -1427,6 +1427,10 @@ static void store_tree(struct tree_entry *root)
1427 if (!is_null_sha1(root->versions[1].sha1))
1428 return;
1429
1430 + if (!root->tree)
1431 + load_tree(root);
1432 + t = root->tree;
1433 +
1434 for (i = 0; i < t->entry_count; i++) {
1435 if (t->entries[i]->tree)
1436 store_tree(t->entries[i]);
t/t9300-fast-import.sh
+2 -2
@@ -3107,7 +3107,7 @@ D ""
3107
3108 INPUT_END
3109
3110 -test_expect_failure 'U: filedelete root succeeds' '
3110 +test_expect_success 'U: filedelete root succeeds' '
3111 git fast-import <input
3112 '
3113
@@ -3117,7 +3117,7 @@ EOF
3117
3118 git diff-tree -M -r U^1 U >actual
3119
3120 -test_expect_failure 'U: validate root delete result' '
3120 +test_expect_success 'U: validate root delete result' '
3121 compare_diff_raw expect actual
3122 '
3123