From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Patrick Steinhardt <ps@pks.im>,
Karthik Nayak <karthik.188@gmail.com>,
Jeff King <peff@peff.net>, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 2/5] setup: extract path_allowlist_apply()
Date: Fri, 14 Aug 2026 10:56:21 -0700 [thread overview]
Message-ID: <xmqqecg0oabe.fsf@gitster.g> (raw)
In-Reply-To: <20260813154748.2378747-3-christian.couder@gmail.com> (Christian Couder's message of "Thu, 13 Aug 2026 17:47:45 +0200")
Christian Couder <christian.couder@gmail.com> writes:
> In a following commit we are going to check whether a repository is
> part of an allowlist specified in a config variable.
>
> To prepare for that let's extract existing code from
> safe_directory_cb() into a new path_allowlist_apply() helper that will
> help with such checks.
>
> While at it let's make the helper's code simpler and more generic.
>
> Signed-off-by: Christian Couder <christian.couder@gmail.com>
> ---
> setup.c | 107 +++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 59 insertions(+), 48 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 95909e9603..39dfa1cc5f 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -1339,6 +1339,64 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
> }
> }
>
> +static void path_allowlist_apply(const char *key, const char *value,
> + const char *target_path, int *is_match)
> +{
> + char *allowed = NULL;
> + char *normalized = NULL;
> +
> + if (!value || !*value) {
> + *is_match = 0;
> + return;
> + }
> +
> + if (!strcmp(value, "*")) {
> + *is_match = 1;
> + return;
> + }
> +
> + if (git_config_pathname(&allowed, key, value) || !allowed)
> + return;
The inversion of the polarity from the original here is a nice
touch. We no longer have to look at deeply indented block to tell
immediately that nothing will happen when the configuration variable
is not set.
> + /*
> + * Setting the config variable to a non-absolute path makes
> + * little sense---it won't be relative to the configuration
> + * file the item is defined in. Except for ".", which means
> + * "if we are at the top level of a repository, then it is
> + * OK", which is slightly tighter than "*" that allows
> + * discovery.
> + */
> + if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
> + warning(_("%s '%s' not absolute"), key, allowed);
> + goto end;
> + }
> +
> + /*
> + * A .gitconfig in $HOME may be shared across different
> + * machines and the config variable entries may or may not
> + * exist as paths on all of these machines. In other words,
> + * it is not a warning worthy event when there is no such path
> + * on this machine---the entry may be useful elsewhere.
> + */
> + normalized = real_pathdup(allowed, 0);
> + if (!normalized)
> + goto end;
> +
> + if (ends_with(normalized, "/*")) {
> + size_t len = strlen(normalized);
> + if (!fspathncmp(normalized, target_path, len - 1))
> + *is_match = 1;
> + goto end;
> + }
> +
> + if (!fspathcmp(target_path, normalized))
> + *is_match = 1;
> +
> +end:
> + free(normalized);
> + free(allowed);
> +}
The name "is_match" somehow feels a bit awkward. How about calling
it
*matches = true/false;
instead?
next prev parent reply other threads:[~2026-08-14 17:56 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 8:51 [PATCH 0/3] Introduce a 'fromAccepted' option to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10 8:51 ` [PATCH 1/3] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-07-10 8:51 ` [PATCH 2/3] promisor-remote: introduce enum allow_lazy_fetch Christian Couder
2026-07-10 8:51 ` [PATCH 3/3] promisor-remote: teach 'fromAccepted' to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10 19:50 ` [PATCH 0/3] Introduce a 'fromAccepted' option " brian m. carlson
2026-07-12 9:06 ` Christian Couder
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
2026-08-07 13:55 ` [PATCH 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-08-07 13:58 ` Christian Couder
2026-08-07 13:55 ` [PATCH 2/5] setup: extract path_allowlist_apply() Christian Couder
2026-08-07 13:55 ` [PATCH 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
2026-08-07 13:55 ` [PATCH 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-08-07 13:55 ` [PATCH 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
2026-08-07 18:31 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Junio C Hamano
2026-08-10 8:06 ` Christian Couder
2026-08-11 5:55 ` Junio C Hamano
2026-08-13 15:47 ` [PATCH v2 " Christian Couder
2026-08-13 20:31 ` Junio C Hamano
2026-08-14 16:31 ` Christian Couder
2026-08-14 16:40 ` Junio C Hamano
2026-08-13 15:47 ` [PATCH v2 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-08-14 17:49 ` Junio C Hamano
2026-08-13 15:47 ` [PATCH v2 2/5] setup: extract path_allowlist_apply() Christian Couder
2026-08-14 17:56 ` Junio C Hamano [this message]
2026-08-13 15:47 ` [PATCH v2 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
2026-08-14 18:12 ` Junio C Hamano
2026-08-13 15:47 ` [PATCH v2 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-08-14 18:56 ` Junio C Hamano
2026-08-13 15:47 ` [PATCH v2 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
2026-08-14 19:35 ` 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=xmqqecg0oabe.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/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.