@@ -376,6 +376,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
376376 full = xcalloc (1 , sizeof (struct index_state ));
377377 memcpy (full , istate , sizeof (struct index_state ));
378378
379+ full -> name_hash_initialized = 0 ;
380+ memset (& full -> name_hash , 0 , sizeof (full -> name_hash ));
381+ memset (& full -> dir_hash , 0 , sizeof (full -> dir_hash ));
382+
379383 /*
380384 * This slightly-misnamed 'full' index might still be sparse if we
381385 * are only modifying the list of sparse directories. This hinges
@@ -434,9 +438,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
434438 }
435439
436440 /* Copy back into original index. */
441+ if (istate -> name_hash_initialized ) {
442+ hashmap_clear (& istate -> name_hash );
443+ hashmap_clear (& istate -> dir_hash );
444+ }
445+
437446 istate -> name_hash_initialized = full -> name_hash_initialized ;
438447 memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
439448 memcpy (& istate -> dir_hash , & full -> dir_hash , sizeof (full -> dir_hash ));
449+
440450 istate -> sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED ;
441451 free (istate -> cache );
442452 istate -> cache = full -> cache ;
0 commit comments