@@ -375,6 +375,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
375375 full = xcalloc (1 , sizeof (struct index_state ));
376376 memcpy (full , istate , sizeof (struct index_state ));
377377
378+ full -> name_hash_initialized = 0 ;
379+ memset (& full -> name_hash , 0 , sizeof (full -> name_hash ));
380+ memset (& full -> dir_hash , 0 , sizeof (full -> dir_hash ));
381+
378382 /*
379383 * This slightly-misnamed 'full' index might still be sparse if we
380384 * are only modifying the list of sparse directories. This hinges
@@ -433,9 +437,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
433437 }
434438
435439 /* Copy back into original index. */
440+ if (istate -> name_hash_initialized ) {
441+ hashmap_clear (& istate -> name_hash );
442+ hashmap_clear (& istate -> dir_hash );
443+ }
444+
436445 istate -> name_hash_initialized = full -> name_hash_initialized ;
437446 memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
438447 memcpy (& istate -> dir_hash , & full -> dir_hash , sizeof (full -> dir_hash ));
448+
439449 istate -> sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED ;
440450 free (istate -> cache );
441451 istate -> cache = full -> cache ;
0 commit comments