Skip to content

Commit

Permalink
fast-import: fix segfault in store_tree()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Maxim Bublis authored and Junio C Hamano committed Aug 29, 2014
1 parent 8d30d8a commit 2668d69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,14 +1419,18 @@ 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;

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]);
Expand Down
4 changes: 2 additions & 2 deletions t/t9300-fast-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand All @@ -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
'

Expand Down

0 comments on commit 2668d69

Please sign in to comment.