From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422524908BE for ; Fri, 14 Aug 2026 17:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786730185; cv=none; b=K4EAf+LADCawh7927RshCKpUIft2xSBjfWfihu2+HdX4gAPtrvwX1qwuctawCIarIYKjdkDvA831MsQQ+VvZV07l0tWMRk1AY3H92B2h8iuUscxSpFKNL8dOGBcwQShHeac1k6v5P5ZpuNY8dP1BtcDsid3L5nKlbaNxvb59V9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786730185; c=relaxed/simple; bh=ZM8KajEM/hvDsX/apbIA+D3HditY3K3G9WSNYQV/6G4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=npIa+qMrONhKivGCnixH6zYvgYf7FDqqqmKKTlotIZMGZ5FQOh2ZLf/pFIcF1VY7lS5a4JygULCL2CNkOgC2QBhlK1J7G7GFYRynleG8YIOJIhCx2cs1ihuT3FZoBVhT3av2v7pf2NhTsbsSuO5O8i1pxujCnOJSaz6DZRJzipk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=J/9TwELe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HfWJmsnz; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="J/9TwELe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HfWJmsnz" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 442EB14000F3; Fri, 14 Aug 2026 13:56:23 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-06.internal (MEProxy); Fri, 14 Aug 2026 13:56:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1786730183; x=1786816583; bh=IMZQ9Rw92k 3xpjtskBwFcVvwkT+lCpH6i4NxdkVyWhQ=; b=J/9TwELemA5kcHVG96UboYDKM1 L2m1hiR7/AOEYEsIdsiqvRUMRGoLTnZUJchIxG9DbxcqFVOMsewkYnYPOheD3crd Bl+Wa99kMTFWN6mJGE37h9a3mhEI8cic+zcm84eQO1ICiPTd1QPjDNW6hEkbKKJT 6b1IkMz54LrpW5vKSUh350AK30Y7bnmgZdLN8IJbllV/jkxVcgR4zLNI0mIonK2u 6STlTMYKuAL+T9OoYv5i60se/gDHNMOUUHsW5CXmOoIxHMPi/2l5YBCQ2XZvdeLp opzFL+4++F8EioN0ddN8fJlSPEI5c0f276fCDAf6Q57OlJTXhzE5lOPXkK5w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1786730183; x=1786816583; bh=IMZQ9Rw92k3xpjtskBwFcVvwkT+lCpH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vxw0TndKchhOMA X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Aug 2026 13:56:22 -0400 (EDT) From: Junio C Hamano To: Christian Couder Cc: git@vger.kernel.org, "brian m . carlson" , Patrick Steinhardt , Karthik Nayak , Jeff King , Elijah Newren Subject: Re: [PATCH v2 2/5] setup: extract path_allowlist_apply() In-Reply-To: <20260813154748.2378747-3-christian.couder@gmail.com> (Christian Couder's message of "Thu, 13 Aug 2026 17:47:45 +0200") References: <20260807135511.1818458-1-christian.couder@gmail.com> <20260813154748.2378747-3-christian.couder@gmail.com> Date: Fri, 14 Aug 2026 10:56:21 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Christian Couder 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 > --- > 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?