@@ -1568,7 +1568,8 @@ static int tree_content_set(
15681568static int tree_content_remove (
15691569 struct tree_entry * root ,
15701570 const char * p ,
1571- struct tree_entry * backup_leaf )
1571+ struct tree_entry * backup_leaf ,
1572+ int allow_root )
15721573{
15731574 struct tree_content * t ;
15741575 const char * slash1 ;
@@ -1583,6 +1584,12 @@ static int tree_content_remove(
15831584
15841585 if (!root -> tree )
15851586 load_tree (root );
1587+
1588+ if (!* p && allow_root ) {
1589+ e = root ;
1590+ goto del_entry ;
1591+ }
1592+
15861593 t = root -> tree ;
15871594 for (i = 0 ; i < t -> entry_count ; i ++ ) {
15881595 e = t -> entries [i ];
@@ -1599,7 +1606,7 @@ static int tree_content_remove(
15991606 goto del_entry ;
16001607 if (!e -> tree )
16011608 load_tree (e );
1602- if (tree_content_remove (e , slash1 + 1 , backup_leaf )) {
1609+ if (tree_content_remove (e , slash1 + 1 , backup_leaf , 0 )) {
16031610 for (n = 0 ; n < e -> tree -> entry_count ; n ++ ) {
16041611 if (e -> tree -> entries [n ]-> versions [1 ].mode ) {
16051612 hashclr (root -> versions [1 ].sha1 );
@@ -2188,7 +2195,7 @@ static uintmax_t do_change_note_fanout(
21882195 }
21892196
21902197 /* Rename fullpath to realpath */
2191- if (!tree_content_remove (orig_root , fullpath , & leaf ))
2198+ if (!tree_content_remove (orig_root , fullpath , & leaf , 0 ))
21922199 die ("Failed to remove path %s" , fullpath );
21932200 tree_content_set (orig_root , realpath ,
21942201 leaf .versions [1 ].sha1 ,
@@ -2323,7 +2330,7 @@ static void file_change_m(struct branch *b)
23232330
23242331 /* Git does not track empty, non-toplevel directories. */
23252332 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 );
23272334 return ;
23282335 }
23292336
@@ -2384,7 +2391,7 @@ static void file_change_d(struct branch *b)
23842391 die ("Garbage after path in: %s" , command_buf .buf );
23852392 p = uq .buf ;
23862393 }
2387- tree_content_remove (& b -> branch_tree , p , NULL );
2394+ tree_content_remove (& b -> branch_tree , p , NULL , 1 );
23882395}
23892396
23902397static void file_change_cr (struct branch * b , int rename )
@@ -2422,7 +2429,7 @@ static void file_change_cr(struct branch *b, int rename)
24222429
24232430 memset (& leaf , 0 , sizeof (leaf ));
24242431 if (rename )
2425- tree_content_remove (& b -> branch_tree , s , & leaf );
2432+ tree_content_remove (& b -> branch_tree , s , & leaf , 1 );
24262433 else
24272434 tree_content_get (& b -> branch_tree , s , & leaf , 1 );
24282435 if (!leaf .versions [1 ].mode )
@@ -2530,7 +2537,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
25302537 }
25312538
25322539 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 ))
25342541 b -> num_notes -- ;
25352542
25362543 if (is_null_sha1 (sha1 ))
0 commit comments