From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] diff-lib: skip paths outside prefix in oneway_diff()
Date: Mon, 27 Jul 2026 05:39:12 -0400 [thread overview]
Message-ID: <20260727093912.GA591426@coredump.intra.peff.net> (raw)
In-Reply-To: <20260726084705.GB3529698@coredump.intra.peff.net>
On Sun, Jul 26, 2026 at 04:47:05AM -0400, Jeff King wrote:
> diff --git a/diff-lib.c b/diff-lib.c
> index 95f920a9a0..9986f5b141 100644
> --- 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).
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.
-Peff
next prev parent reply other threads:[~2026-07-27 9:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 6:05 [PATCH] diff: ignore unmerged paths outside prefix with --relative --cached Jeff King
2026-07-15 15:17 ` Junio C Hamano
2026-07-26 8:45 ` [PATCH 0/2] diff-lib relative-path cleanups Jeff King
2026-07-26 8:46 ` [PATCH 1/2] diff-lib: drop stale comment about advancing o->pos Jeff King
2026-07-26 8:47 ` [PATCH 2/2] diff-lib: skip paths outside prefix in oneway_diff() Jeff King
2026-07-27 9:39 ` Jeff King [this message]
2026-07-28 0:43 ` Junio C Hamano
2026-07-28 15:14 ` [PATCH] diff-lib: add idx/tree sanity check to oneway_diff Jeff King
2026-07-28 16:22 ` Junio C Hamano
2026-07-28 17:12 ` Jeff King
2026-07-26 20:02 ` [PATCH 0/2] diff-lib relative-path cleanups Junio C Hamano
2026-07-24 21:30 ` [PATCH] diff: ignore unmerged paths outside prefix with --relative --cached Junio C Hamano
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=20260727093912.GA591426@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox