fast-import: fix segfault in store_tree()
authorMaxim Bublis <satori@yandex-team.ru>
Fri, 29 Aug 2014 11:53:37 +0000 (15:53 +0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Aug 2014 17:31:14 +0000 (10:31 -0700)
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>
fast-import.c
t/t9300-fast-import.sh
index d73f58cbe3fe4522fa24d47f9086d927b3296c8b..e380804831f7c386e41dee85d7229448b9be30e0 100644 (file)
@@ -1419,7 +1419,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
 
 static void store_tree(struct tree_entry *root)
 {
-       struct tree_content *t = root->tree;
+       struct tree_content *t;
        unsigned int i, j, del;
        struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
        struct object_entry *le = NULL;
@@ -1427,6 +1427,10 @@ static void store_tree(struct tree_entry *root)
        if (!is_null_sha1(root->versions[1].sha1))
                return;
 
+       if (!root->tree)
+               load_tree(root);
+       t = root->tree;
+
        for (i = 0; i < t->entry_count; i++) {
                if (t->entries[i]->tree)
                        store_tree(t->entries[i]);
index 9cf5e45ae79d3d1e01ae112fb7f45cd43b93caaf..d400442a4a8891a6f20e1b764fa19488f803c9c4 100755 (executable)
@@ -3107,7 +3107,7 @@ D ""
 
 INPUT_END
 
-test_expect_failure 'U: filedelete root succeeds' '
+test_expect_success 'U: filedelete root succeeds' '
     git fast-import <input
 '
 
@@ -3117,7 +3117,7 @@ EOF
 
 git diff-tree -M -r U^1 U >actual
 
-test_expect_failure 'U: validate root delete result' '
+test_expect_success 'U: validate root delete result' '
        compare_diff_raw expect actual
 '