git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1] Fix bugs preventing adding updated cache entries to the name hash

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 15, 2018, 17:58 UTC
Message-ID
<xmqqfu515ihj.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180315152520.23264-1-benpeart@microsoft.com>
Ben Peart <benpeart@microsoft.com> writes:
> 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()
OK.  
Show 12 quoted lines
> diff --git a/read-cache.c b/read-cache.c
> index 977921d90c..bdfa552861 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -62,6 +62,7 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
>  	replace_index_entry_in_base(istate, old, ce);
>  	remove_name_hash(istate, old);
>  	free(old);
> +	ce->ce_flags &= ~CE_HASHED;
>  	set_index_entry(istate, nr, ce);
>  	ce->ce_flags |= CE_UPDATE_IN_BASE;
>  	mark_fsmonitor_invalid(istate, ce);

As we are removing "old" that is not "ce", an earlier call to remove_name_hash() that clears the CE_HASHED bit from the cache entry does not help us at all. We need to clear the bit from "ce" ourselves before calling set_index_entry() on it, otherwise the call would become a no-op wrt the name hash. Makes sense.

Makes me wonder why "ce" which is a replacement for what is in the index already has the hashed bit, though. Is that the failure to use copy_cache_entry() in the caller the other part of this patch fixes? To me it looks like copy_cache_entry() is designed for copying an entry's data to another one that has a different name, but in the refresh codepath, we _know_ we are replacing an old entry with an entry with the same name, so it somehow feels a bit strange to use copy_cache_entry(), instead of doing memcpy() (and possibly dropping the HASHED bit from the new copy--but wouldn't that become unnecessary with the fix to replace_index_entry() we saw above?)

Is this fix something we can demonstrate in a new test, by the way?
Thanks.
Previous: Ben PeartNext: Ben Peart
Message 2 of 4 in “Fix bugs preventing adding updated cache entries to the name hash”
  1. Fix bugs preventing adding updated cache entries to the name hashBen Peart, Mar 15, 2018
  2. Junio C HamanoMar 15, 2018
  3. Ben PeartMar 15, 2018
  4. Junio C HamanoMar 15, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.