Skip to content

Commit

Permalink
sparse-index: do not copy hashtables during expansion
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <stolee@gmail.com>
  • Loading branch information
derrickstolee authored and dscho committed Dec 18, 2024
1 parent a0eb045 commit 2749f0d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
full = xcalloc(1, sizeof(struct index_state));
memcpy(full, istate, sizeof(struct index_state));

full->name_hash_initialized = 0;
memset(&full->name_hash, 0, sizeof(full->name_hash));
memset(&full->dir_hash, 0, sizeof(full->dir_hash));

/*
* This slightly-misnamed 'full' index might still be sparse if we
* are only modifying the list of sparse directories. This hinges
Expand Down Expand Up @@ -432,9 +436,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
}

/* Copy back into original index. */
if (istate->name_hash_initialized) {
hashmap_clear(&istate->name_hash);
hashmap_clear(&istate->dir_hash);
}

istate->name_hash_initialized = full->name_hash_initialized;
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));

istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED;
free(istate->cache);
istate->cache = full->cache;
Expand Down

0 comments on commit 2749f0d

Please sign in to comment.