Skip to content

Commit b6902f1

Browse files
committed
sparse-index: do not copy hashtables during expansion
Signed-off-by: Derrick Stolee <[email protected]>
1 parent c24d3f7 commit b6902f1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sparse-index.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
369369
full = xcalloc(1, sizeof(struct index_state));
370370
memcpy(full, istate, sizeof(struct index_state));
371371

372+
full->name_hash_initialized = 0;
373+
memset(&full->name_hash, 0, sizeof(full->name_hash));
374+
memset(&full->dir_hash, 0, sizeof(full->dir_hash));
375+
372376
/*
373377
* This slightly-misnamed 'full' index might still be sparse if we
374378
* are only modifying the list of sparse directories. This hinges
@@ -427,9 +431,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
427431
}
428432

429433
/* Copy back into original index. */
434+
if (istate->name_hash_initialized) {
435+
hashmap_clear(&istate->name_hash);
436+
hashmap_clear(&istate->dir_hash);
437+
}
438+
430439
istate->name_hash_initialized = full->name_hash_initialized;
431440
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
432441
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
442+
433443
istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED;
434444
free(istate->cache);
435445
istate->cache = full->cache;

0 commit comments

Comments
 (0)