All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Derrick Stolee <stolee@gmail.com>
Cc: David Lin <davidzylin@gmail.com>,
	 git@vger.kernel.org,  ps@pks.im, David Lin <davidlin@stripe.com>
Subject: Re: [PATCH] cache-tree: fix inverted object existence check in cache_tree_fully_valid
Date: Mon, 06 Apr 2026 11:49:08 -0700	[thread overview]
Message-ID: <xmqqcy0bc4bf.fsf@gitster.g> (raw)
In-Reply-To: <b0ee86fb-2fb8-4c7f-904d-66140b58164d@gmail.com> (Derrick Stolee's message of "Mon, 6 Apr 2026 14:10:16 -0400")

Derrick Stolee <stolee@gmail.com> writes:

> On 4/6/2026 11:14 AM, David Lin wrote:
>> 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.
>
> It looks like this negation occurred two refactors ago in
> 062b914c84 (treewide: convert users of `repo_has_object_file()` to
> `has_object()`, 2025-04-29) which had this diff:
>
> diff --git a/cache-tree.c b/cache-tree.c
> index c0e1e9ee1d..fa3858e282 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -238,7 +238,9 @@ int cache_tree_fully_valid(struct cache_tree *it)
>         int i;
>         if (!it)
>                 return 0;
> -       if (it->entry_count < 0 || !repo_has_object_file(the_repository, &it->oid))
> +       if (it->entry_count < 0 ||
> +           has_object(the_repository, &it->oid,
> +                      HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
>                 return 0;
>         for (i = 0; i < it->subtree_nr; i++) {
>                 if (!cache_tree_fully_valid(it->down[i]->cache_tree))
>  
> This was one hunk among many, so it is easy to miss that the ! was
> lost as the function was renamed and moved to another line.

Thanks for archaeology.  It deserves to be recorded in the proposed
log message.  David, would you mind updating the message and repost
a v2 of the patch?

I wonder what the practical effect of this breakage was.  The added
test only checks what happens in the trace, but what was the effect
externally observable?   We did not rebuild the cache-tree when we
should have, causing "write-tree" to record a set of tree objects
that do not match what is in the index?


>>  	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;
>
> This fix (respecting the has_object to odb_has_object refactor)
> is the correct one.
>
>> +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
>
> nit: I think this would be better as "test_grep ! ..."
>
> Thanks,
> -Stolee

  reply	other threads:[~2026-04-06 18:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 15:14 [PATCH] cache-tree: fix inverted object existence check in cache_tree_fully_valid David Lin
2026-04-06 18:10 ` Derrick Stolee
2026-04-06 18:49   ` Junio C Hamano [this message]
2026-04-06 19:27     ` [PATCH v2] " David Lin
2026-04-07  5:15       ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqcy0bc4bf.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=davidlin@stripe.com \
    --cc=davidzylin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.