From: Taylor Blau <me@ttaylorr.com>
To: Elijah Newren <newren@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jeff King <peff@peff.net>, Patrick Steinhardt <ps@pks.im>,
SURA <surak8806@gmail.com>
Subject: Re: [PATCH v2 2/2] refs.c: stop matching non-directory prefixes in exclude patterns
Date: Fri, 7 Mar 2025 18:46:58 -0500 [thread overview]
Message-ID: <Z8uFcvHRcBExhjNS@nand.local> (raw)
In-Reply-To: <CABPp-BFn0wht71rM1bE1ABpa6Rn6QRrcVrbN0fhcwprbm+T39Q@mail.gmail.com>
On Fri, Mar 07, 2025 at 01:31:31PM -0800, Elijah Newren wrote:
> > diff --git a/refs.c b/refs.c
> > index 17d3840aff..2d9a1b51f4 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -1708,7 +1708,11 @@ struct ref_iterator *refs_ref_iterator_begin(
> > if (!len)
> > continue;
> >
> > - strvec_push(&normalized_exclude_patterns, pattern);
> > + if (pattern[len - 1] == '/')
> > + strvec_push(&normalized_exclude_patterns, pattern);
> > + else
> > + strvec_pushf(&normalized_exclude_patterns, "%s/",
> > + pattern);
>
> Doesn't this mean that if the user requested to exclude
> "refs/heads/bar" and "refs/heads/bar" exists, that we won't exclude it
> because it doesn't have a trailing slash?
>
> >From reading other comments in this thread, I guess that ends up being
> okay, because we only promise to filter out what we can cheaply
> filter, and we rely on our caller to double-check everything and do
> the real filtering.
>
> ...but it gives me some ugly dir.c vibes, reminding me of 95c11ecc73f2
> (Fix error-prone fill_directory() API; make it only return matches,
> 2020-04-01) and a slew of related bugs preceding it. Granted, dir.c
> had this tri-state to deal with (tracked, untracked-but-ignored,
> untracked-and-not-ignored) and simplifying of whole directories, which
> don't apply here, so maybe the similarity of
> "fast-filtering-only-and-rely-on-caller" won't be a problem since the
> upper level filtering is so much more straightforward.
>
> Should this at least be called out in the commit message, though?
Yeah, I think that we don't have a tri-state here to deal with as was
the case in 95c11ecc732 makes this a little easier to reason about.
And you're right: if we have a pattern like "refs/heads/bar" and we see
a leaf in our reference hierarchy called "refs/heads/bar", the packed
backend will not exclude it.
This is OK because the exclude pattern stuff is all considered
"best-effort" and callers are expected to do their own filtering. Note
that the exclude patterns (at least in the packed backend) don't know
how to handle meta-characters (there's a big comment in
refs/packed-backend.c explaining why). So we can't guarantee the absence
of false positives without performing the same post-processing as the
caller would.
Even prior to this commit, a literal match in the excluded patterns
would result in a region whose start- and end-points are the same, and
we'd throw it out before it made its way into the jump list.
Thanks,
Taylor
prev parent reply other threads:[~2025-03-07 23:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 1:19 [PATCH 0/2] refs: a couple of --exclude fixes Taylor Blau
2025-03-06 1:19 ` [PATCH 1/2] refs.c: remove empty '--exclude' patterns Taylor Blau
2025-03-06 1:19 ` [PATCH 2/2] refs.c: unify '--exclude' behavior between files and packed backends Taylor Blau
2025-03-06 8:47 ` Patrick Steinhardt
2025-03-06 14:54 ` Taylor Blau
2025-03-06 15:34 ` [PATCH v2 0/2] refs: a couple of --exclude fixes Taylor Blau
2025-03-06 15:34 ` [PATCH v2 1/2] refs.c: remove empty '--exclude' patterns Taylor Blau
2025-03-07 21:32 ` Elijah Newren
2025-03-07 23:37 ` Taylor Blau
2025-03-07 23:58 ` Elijah Newren
2025-03-06 15:34 ` [PATCH v2 2/2] refs.c: stop matching non-directory prefixes in exclude patterns Taylor Blau
2025-03-06 17:27 ` Junio C Hamano
2025-03-07 9:35 ` Patrick Steinhardt
2025-03-07 17:31 ` Junio C Hamano
2025-03-07 23:42 ` Taylor Blau
2025-03-07 21:31 ` Elijah Newren
2025-03-07 23:46 ` Taylor Blau [this message]
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=Z8uFcvHRcBExhjNS@nand.local \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=surak8806@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.