Skip to content

Commit 2668d69

Browse files
satorigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d30d8a commit 2668d69

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

fast-import.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,14 +1419,18 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
14191419

14201420
static void store_tree(struct tree_entry *root)
14211421
{
1422-
struct tree_content *t = root->tree;
1422+
struct tree_content *t;
14231423
unsigned int i, j, del;
14241424
struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 };
14251425
struct object_entry *le = NULL;
14261426

14271427
if (!is_null_sha1(root->versions[1].sha1))
14281428
return;
14291429

1430+
if (!root->tree)
1431+
load_tree(root);
1432+
t = root->tree;
1433+
14301434
for (i = 0; i < t->entry_count; i++) {
14311435
if (t->entries[i]->tree)
14321436
store_tree(t->entries[i]);

t/t9300-fast-import.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ D ""
31073107
31083108
INPUT_END
31093109

3110-
test_expect_failure 'U: filedelete root succeeds' '
3110+
test_expect_success 'U: filedelete root succeeds' '
31113111
git fast-import <input
31123112
'
31133113

@@ -3117,7 +3117,7 @@ EOF
31173117

31183118
git diff-tree -M -r U^1 U >actual
31193119

3120-
test_expect_failure 'U: validate root delete result' '
3120+
test_expect_success 'U: validate root delete result' '
31213121
compare_diff_raw expect actual
31223122
'
31233123

0 commit comments

Comments
 (0)