Skip to content

Commit bb19962

Browse files
derrickstoleedscho
authored andcommitted
sparse-index: do not copy hashtables during expansion
Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent cd253da commit bb19962

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
@@ -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

Comments
 (0)