Skip to content

Commit 4589bca

Browse files
derrickstoleegitster
authored andcommitted
name-hash: use expand_to_path()
A sparse-index loads the name-hash data for its entries, including the sparse-directory entries. If a caller asks for a path that is contained within a sparse-directory entry, we need to expand to a full index and recalculate the name hash table before returning the result. Insert calls to expand_to_path() to protect against this case. Signed-off-by: Derrick Stolee <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71f82d0 commit 4589bca

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

name-hash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cache.h"
99
#include "thread-utils.h"
1010
#include "trace2.h"
11+
#include "sparse-index.h"
1112

1213
struct dir_entry {
1314
struct hashmap_entry ent;
@@ -683,6 +684,7 @@ int index_dir_exists(struct index_state *istate, const char *name, int namelen)
683684
struct dir_entry *dir;
684685

685686
lazy_init_name_hash(istate);
687+
expand_to_path(istate, name, namelen, 0);
686688
dir = find_dir_entry(istate, name, namelen);
687689
return dir && dir->nr;
688690
}
@@ -693,6 +695,7 @@ void adjust_dirname_case(struct index_state *istate, char *name)
693695
const char *ptr = startPtr;
694696

695697
lazy_init_name_hash(istate);
698+
expand_to_path(istate, name, strlen(name), 0);
696699
while (*ptr) {
697700
while (*ptr && *ptr != '/')
698701
ptr++;
@@ -716,6 +719,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
716719
unsigned int hash = memihash(name, namelen);
717720

718721
lazy_init_name_hash(istate);
722+
expand_to_path(istate, name, namelen, icase);
719723

720724
ce = hashmap_get_entry_from_hash(&istate->name_hash, hash, NULL,
721725
struct cache_entry, ent);

0 commit comments

Comments
 (0)