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

Re: [PATCH 2/2] diff-lib: skip paths outside prefix in oneway_diff()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 28, 2026, 00:43 UTC
Message-ID
<xmqq4ihkgd06.fsf@gitster.g>
In-Reply-To
<20260727093912.GA591426@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 27 quoted lines
>> --- a/diff-lib.c
>> +++ b/diff-lib.c
>> @@ -528,6 +528,11 @@ static int oneway_diff(const struct cache_entry * const *src,
>>  	if (tree == o->df_conflict_entry)
>>  		tree = NULL;
>>  
>> +	if (revs->diffopt.prefix &&
>> +	    strncmp((idx ? idx : tree)->name, revs->diffopt.prefix,
>> +		    revs->diffopt.prefix_length))
>> +		return 0;
>> +
>
> BTW, Coverity complains here that "tree" could be NULL (because we set
> it that way in the lines above due to a D/F conflict).
>
> I _think_ it is fine. We only look at "tree" if idx is NULL, and I think
> idx is only NULL when we have a deletion. So that implies either:
>
>   1. unpack_trees() passed us both entries as NULL, which doesn't make
>      sense. There was no entry to delete!
>
>   2. We set tree to NULL due to a D/F conflict. But a conflict with
>      what? There is nothing at the path in the index to conflict.
>
> So AFAICT this is OK and it's just a false positive from Coverity
> (though an understandable one; the semantics of the relationship between
> "idx" and "tree" are not represented in the code).
Yeah, I agree with all of the above.
Show 7 quoted lines
> Possibly adding:
>
>   if (!idx && !tree)
> 	BUG("oneway diff with no endpoints");
>
> would help static analysis, but I don't know if that makes things more
> or less clear to a human.

We could help humans that the BUG is not expected to fire and only to help static analysis by a crafted message, perhaps?

   if (!idx && !tree)
 	BUG("Hey, Coverity, this does not happen");
?
Previous: Jeff KingNext: Jeff King
Message 7 of 12 in “diff: ignore unmerged paths outside prefix with --relative --cached”
  1. diff: ignore unmerged paths outside prefix with --relative --cachedJeff King, Jul 15, 2026
  2. Junio C HamanoJul 15, 2026
  3. 0/2 diff-lib relative-path cleanupsJeff King, Jul 26, 2026
  4. 1/2 diff-lib: drop stale comment about advancing o->posJeff King, Jul 26, 2026
  5. 2/2 diff-lib: skip paths outside prefix in oneway_diff()Jeff King, Jul 26, 2026
  6. Jeff KingJul 27, 2026
  7. Junio C HamanoJul 28, 2026
  8. diff-lib: add idx/tree sanity check to oneway_diffJeff King, Jul 28, 2026
  9. Junio C HamanoJul 28, 2026
  10. Jeff KingJul 28, 2026
  11. Junio C HamanoJul 26, 2026
  12. Junio C HamanoJul 24, 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.