@@ -374,6 +374,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
374374 full = xcalloc (1 , sizeof (struct index_state ));
375375 memcpy (full , istate , sizeof (struct index_state ));
376376
377+ full -> name_hash_initialized = 0 ;
378+ memset (& full -> name_hash , 0 , sizeof (full -> name_hash ));
379+ memset (& full -> dir_hash , 0 , sizeof (full -> dir_hash ));
380+
377381 /*
378382 * This slightly-misnamed 'full' index might still be sparse if we
379383 * are only modifying the list of sparse directories. This hinges
@@ -432,9 +436,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
432436 }
433437
434438 /* Copy back into original index. */
439+ if (istate -> name_hash_initialized ) {
440+ hashmap_clear (& istate -> name_hash );
441+ hashmap_clear (& istate -> dir_hash );
442+ }
443+
435444 istate -> name_hash_initialized = full -> name_hash_initialized ;
436445 memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
437446 memcpy (& istate -> dir_hash , & full -> dir_hash , sizeof (full -> dir_hash ));
447+
438448 istate -> sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED ;
439449 free (istate -> cache );
440450 istate -> cache = full -> cache ;
0 commit comments