Skip to content

Commit a7d3667

Browse files
vdyedscho
authored andcommitted
sparse-index.c: fix use of index hashes in expand_index
In ac8acb4 (sparse-index: complete partial expansion, 2022-05-23), 'expand_index()' was updated to expand the index to a given pathspec. However, the 'path_matches_pattern_list()' method used to facilitate this has the side effect of initializing or updating the index hash variables ('name_hash', 'dir_hash', and 'name_hash_initialized'). This operation is performed on 'istate', though, not 'full'; as a result, the initialized hashes are later overwritten when copied from 'full'. To ensure the correct hashes are in 'istate' after the index expansion, change the arg used in 'path_matches_pattern_list()' from 'istate' to 'full'. Note that this does not fully solve the problem. If 'istate' does not have an initialized 'name_hash' when its contents are copied to 'full', initialized hashes will be copied back into 'istate' but 'name_hash_initialized' will be 0. Therefore, we also need to copy 'full->name_hash_initialized' back to 'istate' after the index expansion is complete. Signed-off-by: Victoria Dye <[email protected]>
1 parent e212079 commit a7d3667

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sparse-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
405405
if (pl &&
406406
path_matches_pattern_list(ce->name, ce->ce_namelen,
407407
NULL, &dtype,
408-
pl, istate) == NOT_MATCHED) {
408+
pl, full) == NOT_MATCHED) {
409409
set_index_entry(full, full->cache_nr++, ce);
410410
continue;
411411
}
@@ -433,6 +433,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
433433
}
434434

435435
/* Copy back into original index. */
436+
istate->name_hash_initialized = full->name_hash_initialized;
436437
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
437438
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
438439
istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED;

0 commit comments

Comments
 (0)