@@ -372,6 +372,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
372372 full = xcalloc (1 , sizeof (struct index_state ));
373373 memcpy (full , istate , sizeof (struct index_state ));
374374
375+ full -> name_hash_initialized = 0 ;
376+ memset (& full -> name_hash , 0 , sizeof (full -> name_hash ));
377+ memset (& full -> dir_hash , 0 , sizeof (full -> dir_hash ));
378+
375379 /*
376380 * This slightly-misnamed 'full' index might still be sparse if we
377381 * are only modifying the list of sparse directories. This hinges
@@ -430,9 +434,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
430434 }
431435
432436 /* Copy back into original index. */
437+ if (istate -> name_hash_initialized ) {
438+ hashmap_clear (& istate -> name_hash );
439+ hashmap_clear (& istate -> dir_hash );
440+ }
441+
433442 istate -> name_hash_initialized = full -> name_hash_initialized ;
434443 memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
435444 memcpy (& istate -> dir_hash , & full -> dir_hash , sizeof (full -> dir_hash ));
445+
436446 istate -> sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED ;
437447 free (istate -> cache );
438448 istate -> cache = full -> cache ;
0 commit comments