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

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

From
DLDavid Lin <davidzylin@gmail.com>
Date
Apr 6, 2026, 15:14 UTC
Message-ID
<20260406151456.63620-1-davidlin@stripe.com>

cache_tree_fully_valid() is supposed to return 0 (not valid) when a tree object is missing from the object database. The condition currently returns 0 when odb_has_object() succeeds, which is the opposite of what is intended: the cache tree should be considered invalid when the object does not exist.

Add the missing negation so the function correctly invalidates cache tree nodes whose objects are absent.

Signed-off-by: David Lin <davidlin@stripe.com>
---
 cache-tree.c          | 2 +-
 t/t0090-cache-tree.sh | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
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++) {
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index d901588294..2c6b7a0899 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -278,4 +278,12 @@ test_expect_success 'switching trees does not invalidate shared index' '
 	)
 '
 
+test_expect_success 'cache-tree is used by write-tree when valid' '
+	test_commit use-valid &&
+
+	# write-tree with a valid cache-tree should skip cache_tree_update
+	GIT_TRACE2_PERF="$(pwd)/trace.output" git write-tree &&
+	! grep region_enter.*cache_tree.*update trace.output
+'
+
 test_done

base-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0
-- 
2.52.0.ge17bebe515.stripe
Next: Derrick Stolee
Message 1 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.