Fix bugs preventing adding updated cache entries to the name hash

Update replace_index_entry() to clear the CE_HASHED flag from the new cache entry so that it can add it to the name hash in set_index_entry() Fix refresh_cache_ent() to use the copy_cache_entry() macro instead of memcpy() so that it doesn't incorrectly copy the hash state from the old entry. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Peart committed Mar 15, 2018 at 11:25 UTC 0e267b7a240454538349407c0101cc17168cebcf
1 file changed +3 -1
read-cache.c
+3 -1
@@ -62,6 +62,7 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
62 replace_index_entry_in_base(istate, old, ce);
63 remove_name_hash(istate, old);
64 free(old);
65 + ce->ce_flags &= ~CE_HASHED;
66 set_index_entry(istate, nr, ce);
67 ce->ce_flags |= CE_UPDATE_IN_BASE;
68 mark_fsmonitor_invalid(istate, ce);
@@ -1325,7 +1326,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1326
1327 size = ce_size(ce);
1328 updated = xmalloc(size);
1328 - memcpy(updated, ce, size);
1329 + copy_cache_entry(updated, ce);
1330 + memcpy(updated->name, ce->name, ce->ce_namelen + 1);
1331 fill_stat_cache_info(updated, &st);
1332 /*
1333 * If ignore_valid is not set, we should leave CE_VALID bit