Subject: Re: [PATCH 2/3] config: values of pathname type can be prefixed with :(optional)

From: Patrick Steinhardt <[email-masked]>
Date: Fri, 2 May 2025 10:52:10 +0200

On Thu, May 01, 2025 at 02:40:56PM -0700, Junio C Hamano wrote:
> Sometimes people want to specify additional configuration data
> as "best effort" basis.  Maybe commit.template configuration file points
> at somewhere in ~/template/ but on a particular system, the file may not
> exist and the user may be OK without using the template in such a case.
> 
> When the value given to a configuration variable whose type is
> pathname wants to signal such an optional file, it can be marked by
> prepending ":(optional)" in front of it.  Such a setting that is
> marked optional would avoid getting the command barf for a missing
> file, as an optional configuration setting that names a missing or
> an empty file is not even seen.
> 
> cf. <[email-masked]>
> 
> Signed-off-by: Junio C Hamano <[email-masked]>
> ---
>  Documentation/config.txt                  |  5 ++++-
>  config.c                                  | 16 ++++++++++++++--
>  t/t7500-commit-template-squash-signoff.sh |  9 +++++++++
>  3 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 8c0b3ed807..199e29ccea 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -358,7 +358,10 @@ compiled without runtime prefix support, the compiled-in prefix will be
>  substituted instead. In the unlikely event that a literal path needs to
>  be specified that should _not_ be expanded, it needs to be prefixed by
>  `./`, like so: `./%(prefix)/bin`.
> -
> ++
> +If prefixed with `:(optional)`, the configuration variable is treated
> +as if it does not exist, if the named path does not exist or names an
> +empty file.

I can see why it may be useful to allow for non-existent paths. But I
wonder whether we really should be skipping over empty files, as well,
as it may be assuming too much about the semantics of a given config
key. In other words, are we reasonably sure that there won't ever be a
usecase where you may want to specify an optional and empty file? And
are there any use cases where an empty file should be ignored?

Patrick