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

Re: [PATCH v2] cache-tree: fix inverted object existence check in cache_tree_fully_valid

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 7, 2026, 05:15 UTC
Message-ID
<adSS4GJyBoB2rY4s@pks.im>
In-Reply-To
<20260406192711.68870-1-davidlin@stripe.com>
On Mon, Apr 06, 2026 at 03:27:11PM -0400, David Lin wrote:
Show 16 quoted lines
> The negation in front of the object existence check in
> cache_tree_fully_valid() was lost in 062b914c84 (treewide: convert
> users of `repo_has_object_file()` to `has_object()`, 2025-04-29),
> turning `!repo_has_object_file(...)` into `has_object(...)` instead
> of `!has_object(...)`.
> 
> This makes cache_tree_fully_valid() always report the cache tree as
> invalid when objects exist (the common case), forcing callers like
> write_index_as_tree() to call cache_tree_update() on every
> invocation.  An odb_has_object() check inside update_one() avoids a
> full tree rebuild, but the unnecessary call still pays the cost of
> opening an ODB transaction and, in partial clones, a promisor remote
> check.
> 
> Restore the missing negation and add a test that verifies write-tree
> takes the cache-tree shortcut when the cache tree is valid.
Oh, indeed, thanks for the fix.

I also checked whether there's any other such case in the commit in question, but didn't spot any.

Show 13 quoted lines
> diff --git a/cache-tree.c b/cache-tree.c
> index 60bcc07c3b..9fe057355c 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -238,7 +238,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
>  	if (!it)
>  		return 0;
>  	if (it->entry_count < 0 ||
> -	    odb_has_object(the_repository->objects, &it->oid,
> +	    !odb_has_object(the_repository->objects, &it->oid,
>  			   HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
>  		return 0;
>  	for (i = 0; i < it->subtree_nr; i++) {
Yup, this looks obviously good to me.
Patrick
Previous: David Lin
Message 5 of 5 in “cache-tree: fix inverted object existence check in cache_tree_fully_valid”
  1. cache-tree: fix inverted object existence check in cache_tree_fully_validDavid Lin, Apr 6, 2026
  2. Derrick StoleeApr 6, 2026
  3. Junio C HamanoApr 6, 2026
  4. cache-tree: fix inverted object existence check in cache_tree_fully_validDavid Lin, Apr 6, 2026
  5. Patrick SteinhardtApr 7, 2026

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.