From: Phillip Wood <phillip.wood123@gmail.com>
To: "D. Ben Knoble" <ben.knoble+github@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Noah Pendleton <noah.pendleton@gmail.com>,
Patrick Steinhardt <ps@pks.im>, Thranur Andul <thranur@gmail.com>,
Michael Grosser <grosser.michael@gmail.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH v2 3/3] parseopt: values of pathname type can be prefixed with :(optional)
Date: Tue, 30 Sep 2025 16:26:45 +0100 [thread overview]
Message-ID: <e8755a04-bd44-4ead-ba44-c603bffcc75e@gmail.com> (raw)
In-Reply-To: <5f7057c236c9af3152bd531eed2e4ad0ac35e291.1759094936.git.ben.knoble+github@gmail.com>
Hi Ben
On 28/09/2025 22:29, D. Ben Knoble wrote:
> From: Junio C Hamano <gitster@pobox.com>
>
> In the previous step, we introduced an optional filename that can be
> given to a configuration variable, and nullify the fact that such a
> configuration setting even existed if the named path is missing or
> empty.
>
> Let's do the same for command line options that name a pathname.
Sounds sensible
> +Magic filename options
I assume we're calling these "magic" to match to pathspec "magic"
options? I wonder if that is a good idea but I don't have a better
suggestion.
> +~~~~~~~~~~~~~~~~~~~~~~
> +Options that take a filename allow a prefix `:(optional)`. For example:
> +
> +----------------------------
> +git commit -F :(optional)COMMIT_EDITMSG
> +# if COMMIT_EDITMSG does not exist, equivalent to
This doesn't quite scan for me, maybe s/, /, it is/ ?
> +git commit
> +----------------------------
> +
> +Like with configuration values, if the named file is missing Git behaves as if
I'd drop "with" here
> +the option was not given at all. See "Values" in linkgit:git-config[1].
> +
> @@ -209,21 +208,31 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
> case OPTION_FILENAME:
> {
> const char *value;
> -
> - FREE_AND_NULL(*(char **)opt->value);
> -
> - err = 0;
> + int is_optional;
This can be a bool as in the last patch.
> if (unset)
> value = NULL;
> else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
> - value = (const char *) opt->defval;
> - else
> - err = get_arg(p, opt, flags, &value);
> + value = (char *)opt->defval;
I'm not sure why we're changing the cast here (or why we need one in the
first place assuming opt->defval is "void*")
> + else {
> + int err = get_arg(p, opt, flags, &value);
> + if (err)
> + return err;
> + }
> + if (!value)
> + return 0;
>
> - if (!err)
> - *(char **)opt->value = fix_filename(p->prefix, value);
> - return err;
> + is_optional = skip_prefix(value, ":(optional)", &value);
> + if (!value)
> + is_optional = 0;
I'm struggling to see how value can be NULL here as we return early if
it NULL before calling skip_prefix()
> + value = fix_filename(p->prefix, value);
> + if (is_optional && is_empty_or_missing_file(value)) {
> + free((char *)value);
I think we want to call is_missing_file() here. If the file is missing
then we do nothing which matches the documentation above - Good.
> + } else {
> + FREE_AND_NULL(*(char **)opt->value);
> + *(const char **)opt->value = value;
If the file isn't optional or it is optional and exists then we behave
as before - Good.
Thanks
Phillip
> + }
> + return 0;
> }
> case OPTION_CALLBACK:
> {
> diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> index 366f7f23b3..c065f12baf 100755
> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -37,6 +37,16 @@ commit_msg_is ()
> )
> '
>
> +test_expect_success 'nonexistent optional template file on command line' '
> + echo changes >> foo &&
> + git add foo &&
> + (
> + GIT_EDITOR="echo hello >\"\$1\"" &&
> + export GIT_EDITOR &&
> + git commit --template ":(optional)$PWD/notexist"
> + )
> +'
> +
> test_expect_success 'nonexistent template file in config should return error' '
> test_config commit.template "$PWD"/notexist &&
> (
next prev parent reply other threads:[~2025-09-30 15:26 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-07 20:27 [PATCH 0/1] blame: Skip missing ignore-revs file Noah Pendleton
2021-08-07 20:58 ` Junio C Hamano
2021-08-07 21:34 ` Noah Pendleton
2021-08-08 5:43 ` Junio C Hamano
2021-08-08 17:50 ` Junio C Hamano
2021-08-08 18:21 ` Noah Pendleton
2021-08-09 15:47 ` Junio C Hamano
2024-10-14 20:44 ` [PATCH 0/3] specifying a file that can optionally exist Junio C Hamano
2024-10-14 20:44 ` [PATCH 1/3] t7500: make each piece more independent Junio C Hamano
2024-10-14 20:44 ` [PATCH 2/3] config: values of pathname type can be prefixed with :(optional) Junio C Hamano
2024-10-14 20:44 ` [PATCH 3/3] parseopt: " Junio C Hamano
2025-05-01 21:40 ` [PATCH 0/3] specifying a file that can optionally exist Junio C Hamano
2025-05-01 21:40 ` [PATCH 1/3] t7500: make each piece more independent Junio C Hamano
2025-05-01 21:40 ` [PATCH 2/3] config: values of pathname type can be prefixed with :(optional) Junio C Hamano
2025-05-02 8:52 ` Patrick Steinhardt
2025-05-02 14:28 ` Phillip Wood
2025-05-02 20:05 ` Junio C Hamano
2025-05-01 21:40 ` [PATCH 3/3] parseopt: " Junio C Hamano
2025-09-28 21:29 ` [PATCH v2 0/3] Support :(optional) filepaths D. Ben Knoble
2025-09-28 21:29 ` [PATCH v2 1/3] t7500: make each piece more independent D. Ben Knoble
2025-09-28 21:29 ` [PATCH v2 2/3] config: values of pathname type can be prefixed with :(optional) D. Ben Knoble
2025-09-30 15:26 ` Phillip Wood
2025-10-06 19:00 ` Junio C Hamano
2025-10-06 19:59 ` Junio C Hamano
2025-10-06 20:21 ` Junio C Hamano
2025-10-06 20:22 ` Junio C Hamano
2025-10-07 12:24 ` Kristoffer Haugsbakk
2025-10-07 17:04 ` Junio C Hamano
2025-09-28 21:29 ` [PATCH v2 3/3] parseopt: " D. Ben Knoble
2025-09-30 15:26 ` Phillip Wood [this message]
2025-09-28 22:40 ` [PATCH v2 0/3] Support :(optional) filepaths Junio C Hamano
2025-09-29 16:42 ` Ben Knoble
2022-03-04 9:51 ` [PATCH 0/1] blame: Skip missing ignore-revs file Thranur Andul
2021-08-08 17:48 ` [PATCH v2] blame: add config `blame.ignoreRevsFileIsOptional` Noah Pendleton
-- strict thread matches above, loose matches on Subject: below --
2025-04-25 18:41 Feature request: automatically read .git-blame-ignore-revs or allow global optional config Michael Grosser
2025-04-25 19:54 ` Eric Sunshine
2025-05-01 18:00 ` D. Ben Knoble
2025-05-01 18:28 ` Eric Sunshine
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=e8755a04-bd44-4ead-ba44-c603bffcc75e@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=ben.knoble+github@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=grosser.michael@gmail.com \
--cc=me@ttaylorr.com \
--cc=noah.pendleton@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=sunshine@sunshineco.com \
--cc=thranur@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).