@@ -377,6 +377,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
377377 full = xcalloc (1 , sizeof (struct index_state ));
378378 memcpy (full , istate , sizeof (struct index_state ));
379379
380+ full -> name_hash_initialized = 0 ;
381+ memset (& full -> name_hash , 0 , sizeof (full -> name_hash ));
382+ memset (& full -> dir_hash , 0 , sizeof (full -> dir_hash ));
383+
380384 /*
381385 * This slightly-misnamed 'full' index might still be sparse if we
382386 * are only modifying the list of sparse directories. This hinges
@@ -435,9 +439,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
435439 }
436440
437441 /* Copy back into original index. */
442+ if (istate -> name_hash_initialized ) {
443+ hashmap_clear (& istate -> name_hash );
444+ hashmap_clear (& istate -> dir_hash );
445+ }
446+
438447 istate -> name_hash_initialized = full -> name_hash_initialized ;
439448 memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
440449 memcpy (& istate -> dir_hash , & full -> dir_hash , sizeof (full -> dir_hash ));
450+
441451 istate -> sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED ;
442452 free (istate -> cache );
443453 istate -> cache = full -> cache ;
0 commit comments