@@ -1568,7 +1568,8 @@ static int tree_content_set(
1568
1568
static int tree_content_remove (
1569
1569
struct tree_entry * root ,
1570
1570
const char * p ,
1571
- struct tree_entry * backup_leaf )
1571
+ struct tree_entry * backup_leaf ,
1572
+ int allow_root )
1572
1573
{
1573
1574
struct tree_content * t ;
1574
1575
const char * slash1 ;
@@ -1583,6 +1584,12 @@ static int tree_content_remove(
1583
1584
1584
1585
if (!root -> tree )
1585
1586
load_tree (root );
1587
+
1588
+ if (!* p && allow_root ) {
1589
+ e = root ;
1590
+ goto del_entry ;
1591
+ }
1592
+
1586
1593
t = root -> tree ;
1587
1594
for (i = 0 ; i < t -> entry_count ; i ++ ) {
1588
1595
e = t -> entries [i ];
@@ -1599,7 +1606,7 @@ static int tree_content_remove(
1599
1606
goto del_entry ;
1600
1607
if (!e -> tree )
1601
1608
load_tree (e );
1602
- if (tree_content_remove (e , slash1 + 1 , backup_leaf )) {
1609
+ if (tree_content_remove (e , slash1 + 1 , backup_leaf , 0 )) {
1603
1610
for (n = 0 ; n < e -> tree -> entry_count ; n ++ ) {
1604
1611
if (e -> tree -> entries [n ]-> versions [1 ].mode ) {
1605
1612
hashclr (root -> versions [1 ].sha1 );
@@ -2188,7 +2195,7 @@ static uintmax_t do_change_note_fanout(
2188
2195
}
2189
2196
2190
2197
/* Rename fullpath to realpath */
2191
- if (!tree_content_remove (orig_root , fullpath , & leaf ))
2198
+ if (!tree_content_remove (orig_root , fullpath , & leaf , 0 ))
2192
2199
die ("Failed to remove path %s" , fullpath );
2193
2200
tree_content_set (orig_root , realpath ,
2194
2201
leaf .versions [1 ].sha1 ,
@@ -2323,7 +2330,7 @@ static void file_change_m(struct branch *b)
2323
2330
2324
2331
/* Git does not track empty, non-toplevel directories. */
2325
2332
if (S_ISDIR (mode ) && !memcmp (sha1 , EMPTY_TREE_SHA1_BIN , 20 ) && * p ) {
2326
- tree_content_remove (& b -> branch_tree , p , NULL );
2333
+ tree_content_remove (& b -> branch_tree , p , NULL , 0 );
2327
2334
return ;
2328
2335
}
2329
2336
@@ -2384,7 +2391,7 @@ static void file_change_d(struct branch *b)
2384
2391
die ("Garbage after path in: %s" , command_buf .buf );
2385
2392
p = uq .buf ;
2386
2393
}
2387
- tree_content_remove (& b -> branch_tree , p , NULL );
2394
+ tree_content_remove (& b -> branch_tree , p , NULL , 1 );
2388
2395
}
2389
2396
2390
2397
static void file_change_cr (struct branch * b , int rename )
@@ -2422,7 +2429,7 @@ static void file_change_cr(struct branch *b, int rename)
2422
2429
2423
2430
memset (& leaf , 0 , sizeof (leaf ));
2424
2431
if (rename )
2425
- tree_content_remove (& b -> branch_tree , s , & leaf );
2432
+ tree_content_remove (& b -> branch_tree , s , & leaf , 1 );
2426
2433
else
2427
2434
tree_content_get (& b -> branch_tree , s , & leaf , 1 );
2428
2435
if (!leaf .versions [1 ].mode )
@@ -2530,7 +2537,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
2530
2537
}
2531
2538
2532
2539
construct_path_with_fanout (sha1_to_hex (commit_sha1 ), * old_fanout , path );
2533
- if (tree_content_remove (& b -> branch_tree , path , NULL ))
2540
+ if (tree_content_remove (& b -> branch_tree , path , NULL , 0 ))
2534
2541
b -> num_notes -- ;
2535
2542
2536
2543
if (is_null_sha1 (sha1 ))
0 commit comments