name-hash: don't add directories to name_hash

Sparse directory entries represent a directory that is outside the sparse-checkout definition. These are not paths to blobs, so should not be added to the name_hash table. Instead, they should be added to the directory hashtable when 'ignore_case' is true. Add a condition to avoid placing sparse directories into the name_hash hashtable. This avoids filling the table with extra entries that will never be queried. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 12, 2021 at 21:08 UTC 5f116695864788d1fe45ff06bfad7a71a8d98d0a
1 file changed +5 -2
name-hash.c
+5 -2
@@ -109,8 +109,11 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
109 if (ce->ce_flags & CE_HASHED)
110 return;
111 ce->ce_flags |= CE_HASHED;
112 - hashmap_entry_init(&ce->ent, memihash(ce->name, ce_namelen(ce)));
113 - hashmap_add(&istate->name_hash, &ce->ent);
112 +
113 + if (!S_ISSPARSEDIR(ce->ce_mode)) {
114 + hashmap_entry_init(&ce->ent, memihash(ce->name, ce_namelen(ce)));
115 + hashmap_add(&istate->name_hash, &ce->ent);
116 + }
117
118 if (ignore_case)
119 add_dir_entry(istate, ce);