Skip to content

Commit 5b830a8

Browse files
committed
Merge branch 'mb/fast-import-delete-root' into maint
An attempt to remove the entire tree in the "git fast-import" input stream caused it to misbehave. * mb/fast-import-delete-root: fast-import: fix segfault in store_tree() t9300: test filedelete command
2 parents 46092eb + 2668d69 commit 5b830a8

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

fast-import.c

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

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

14301430
if (!is_null_sha1(root->versions[1].sha1))
14311431
return;
14321432

1433+
if (!root->tree)
1434+
load_tree(root);
1435+
t = root->tree;
1436+
14331437
for (i = 0; i < t->entry_count; i++) {
14341438
if (t->entries[i]->tree)
14351439
store_tree(t->entries[i]);

t/t9300-fast-import.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,4 +3017,108 @@ test_expect_success 'T: empty reset doesnt delete branch' '
30173017
git rev-parse --verify refs/heads/not-to-delete
30183018
'
30193019

3020+
###
3021+
### series U (filedelete)
3022+
###
3023+
3024+
cat >input <<INPUT_END
3025+
commit refs/heads/U
3026+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3027+
data <<COMMIT
3028+
test setup
3029+
COMMIT
3030+
M 100644 inline hello.c
3031+
data <<BLOB
3032+
blob 1
3033+
BLOB
3034+
M 100644 inline good/night.txt
3035+
data <<BLOB
3036+
sleep well
3037+
BLOB
3038+
M 100644 inline good/bye.txt
3039+
data <<BLOB
3040+
au revoir
3041+
BLOB
3042+
3043+
INPUT_END
3044+
3045+
test_expect_success 'U: initialize for U tests' '
3046+
git fast-import <input
3047+
'
3048+
3049+
cat >input <<INPUT_END
3050+
commit refs/heads/U
3051+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3052+
data <<COMMIT
3053+
delete good/night.txt
3054+
COMMIT
3055+
from refs/heads/U^0
3056+
D good/night.txt
3057+
3058+
INPUT_END
3059+
3060+
test_expect_success 'U: filedelete file succeeds' '
3061+
git fast-import <input
3062+
'
3063+
3064+
cat >expect <<EOF
3065+
:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3066+
EOF
3067+
3068+
git diff-tree -M -r U^1 U >actual
3069+
3070+
test_expect_success 'U: validate file delete result' '
3071+
compare_diff_raw expect actual
3072+
'
3073+
3074+
cat >input <<INPUT_END
3075+
commit refs/heads/U
3076+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3077+
data <<COMMIT
3078+
delete good dir
3079+
COMMIT
3080+
from refs/heads/U^0
3081+
D good
3082+
3083+
INPUT_END
3084+
3085+
test_expect_success 'U: filedelete directory succeeds' '
3086+
git fast-import <input
3087+
'
3088+
3089+
cat >expect <<EOF
3090+
:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3091+
EOF
3092+
3093+
git diff-tree -M -r U^1 U >actual
3094+
3095+
test_expect_success 'U: validate directory delete result' '
3096+
compare_diff_raw expect actual
3097+
'
3098+
3099+
cat >input <<INPUT_END
3100+
commit refs/heads/U
3101+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3102+
data <<COMMIT
3103+
must succeed
3104+
COMMIT
3105+
from refs/heads/U^0
3106+
D ""
3107+
3108+
INPUT_END
3109+
3110+
test_expect_success 'U: filedelete root succeeds' '
3111+
git fast-import <input
3112+
'
3113+
3114+
cat >expect <<EOF
3115+
:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3116+
EOF
3117+
3118+
git diff-tree -M -r U^1 U >actual
3119+
3120+
test_expect_success 'U: validate root delete result' '
3121+
compare_diff_raw expect actual
3122+
'
3123+
30203124
test_done

0 commit comments

Comments
 (0)