From: Junio C Hamano <gitster@pobox.com>
To: Lidong Yan <yldhome2d2@gmail.com>
Cc: git@vger.kernel.org, stolee@gmail.com, ttaylorr@github.com
Subject: Re: [PATCH v3] bloom: enable bloom filter with wildcard pathspec in revision traversal
Date: Sat, 09 Aug 2025 16:51:42 -0700 [thread overview]
Message-ID: <xmqqpld45a0h.fsf@gitster.g> (raw)
In-Reply-To: <20250809021642.22195-1-yldhome2d2@gmail.com> (Lidong Yan's message of "Sat, 9 Aug 2025 10:16:42 +0800")
Lidong Yan <yldhome2d2@gmail.com> writes:
> [jc: avoid allocating zero length path in
> convert_pathspec_to_bloom_keyvec()]
This is different from what I did, though.
> @@ -693,19 +698,31 @@ static int convert_pathspec_to_bloom_keyvec(struct bloom_keyvec **out,
> size_t len;
> int res = 0;
>
> + len = pi->nowildcard_len;
> + if (len != pi->len) {
> + /*
> + * for path like "dir/file*", nowildcard part would be
> + * "dir/file", but only "dir" should be used for the
> + * bloom filter
> + */
A missing full-stop.
> + while (len > 0 && pi->match[len - 1] != '/')
> + len--;
> + }
> /* remove single trailing slash from path, if needed */
> - if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
> - path_alloc = xmemdupz(pi->match, pi->len - 1);
> - path = path_alloc;
> - } else
> - path = pi->match;
> + if (len > 0 && pi->match[len - 1] == '/')
> + len--;
>
> - len = strlen(path);
> if (!len) {
> res = -1;
> goto cleanup;
> }
>
> + if (len != pi->len) {
> + path_alloc = xmemdupz(pi->match, len);
> + path = path_alloc;
> + } else
> + path = pi->match;
> +
> *out = bloom_keyvec_new(path, len, settings);
>
> cleanup:
Two comments.
* For a function that finds an error condition in the middle and
jumps to the "cleanup:" label at the end, it is more future-proof
to start pessimistic (i.e. initialize 'res' to error(-1)) and
flip 'res' to success(0) at the very end when everything went
well. It would simplify the change necessary when we need to add
_more_ early error return code paths to the function in the
future.
But this flip from "assume success" to "assume failure" is
something that should be not be done as part of this patch;
perhaps doing it a separate preliminary clean-up patch is a
better way to do so.
* I think the change from v3 (this one) to v4 makes the function
worse; we found that it is a good practice to have a single place
to release any resources we temporarily acquired and arrange
exception handling code to just jump there during the course of
this project.
The current implementation may happen to have only one such early
return (i.e. "len has become 0; we realize that we cannot use the
Bloom filter"), but adding a new early return in the future would
be easier if you kept the original arrangement. The new early
return condition may have to be computed after we have acquired
resources we need to release, so it may need more than a simple
"return -1".
next prev parent reply other threads:[~2025-08-09 23:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 5:12 [PATCH] bloom: enable bloom filter with wildcard pathspec in revision traversal Lidong Yan
2025-08-07 6:49 ` Patrick Steinhardt
2025-08-07 8:59 ` Lidong Yan
2025-08-07 16:15 ` Junio C Hamano
2025-08-08 6:40 ` Lidong Yan
2025-08-08 6:58 ` [PATCH v2] " Lidong Yan
2025-08-08 15:50 ` Junio C Hamano
2025-08-09 2:06 ` Lidong Yan
2025-08-09 2:16 ` [PATCH v3] " Lidong Yan
2025-08-09 4:22 ` [PATCH v4] " Lidong Yan
2025-08-09 7:40 ` Lidong Yan
2025-08-11 6:01 ` [PATCH v5] " Lidong Yan
2025-08-11 15:56 ` Junio C Hamano
2025-08-11 16:08 ` Lidong Yan
2025-08-09 23:51 ` Junio C Hamano [this message]
2025-08-10 1:57 ` [PATCH v3] " Lidong Yan
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=xmqqpld45a0h.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=stolee@gmail.com \
--cc=ttaylorr@github.com \
--cc=yldhome2d2@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).