From: Junio C Hamano <gitster@pobox.com>
To: "VALERI Yoann via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Yoann Valeri <yoann.valeri@cea.fr>
Subject: Re: [PATCH v3 3/3] branch: add '--no-name-prefix' option
Date: Fri, 06 Mar 2026 13:38:56 -0800 [thread overview]
Message-ID: <xmqqzf4ky6xb.fsf@gitster.g> (raw)
In-Reply-To: <8f45374007fddfa4cc81e536ae6e095b0d67d5e6.1772802872.git.gitgitgadget@gmail.com> (VALERI Yoann via GitGitGadget's message of "Fri, 06 Mar 2026 13:14:32 +0000")
"VALERI Yoann via GitGitGadget" <gitgitgadget@gmail.com> writes:
> - OPT_STRING(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create")),
> + OPT_STRING_F(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create"), PARSE_OPT_NONEG),
> + OPT_BOOL(0, "no-name-prefix", &no_name_prefix, N_("do not use any prefix for the branch to create")),
You do not want a separate "no-*" entry in the options[] table.
If we look at parse-options.c to see how OPTION_STRING is handled,
we find:
case OPTION_STRING:
if (unset)
*(const char **)opt->value = NULL;
else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
*(const char **)opt->value = (const char *)opt->defval;
else
return get_arg(p, opt, flags, (const char **)opt->value);
return 0;
which tells us
* "--no-name-prefix" is caught by "if (unset)" and causes the
name_prefix variable set to NULL.
* if we give OPT_OPTARG, we can allow "--name-prefix" (with no
parameter) to default to opt->defval value; this feature is not
very useful in our application.
* Otherwise we get the string after "--name-prefix=".
So you do not need to do anything strange. To correctly implement
the order of handling configuration and command line, you would do:
* initialize name_prefix to NULL. By default no name_prefix is
used.
* early in the cmd_branch() before you call parse_options(),
consult the configuration and pick up branch.nameprefix
and set it to name_prefix variable.
* then you call parse_options(). If the command line has
"--no-name-prefix", "if (unset)" kicks in and clears the
name_prefix variable pointed at by the opt->value. If the
command line has "--name-prefix=blah", the name_prefix variable,
which may have obtained a value from the configuration, is
overwritten with "blah". If the command line does not do
anything, then the name_prefix variable will retain whatever
value it got from the configuration.
next prev parent reply other threads:[~2026-03-06 21:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 8:07 [PATCH] branch: add 'branch.addCurrentBranchAsPrefix' config param Yoann Valeri via GitGitGadget
2026-02-20 15:59 ` Junio C Hamano
2026-02-20 16:08 ` Junio C Hamano
2026-02-27 15:48 ` [PATCH v2 0/2] " Yoann Valeri via GitGitGadget
2026-02-27 15:48 ` [PATCH v2 1/2] " VALERI Yoann via GitGitGadget
2026-02-27 15:48 ` [PATCH v2 2/2] branch: add a no-prefix option VALERI Yoann via GitGitGadget
2026-02-27 17:07 ` Junio C Hamano
2026-03-06 13:14 ` [PATCH v3 0/3] branch: add prefixes to new branch names Yoann Valeri via GitGitGadget
2026-03-06 13:14 ` [PATCH v3 1/3] branch: add '--name-prefix' option VALERI Yoann via GitGitGadget
2026-03-07 7:06 ` Eric Sunshine
2026-03-08 7:06 ` Junio C Hamano
2026-03-06 13:14 ` [PATCH v3 2/3] branch: add 'branch.namePrefix' config param VALERI Yoann via GitGitGadget
2026-03-07 7:07 ` Eric Sunshine
2026-03-06 13:14 ` [PATCH v3 3/3] branch: add '--no-name-prefix' option VALERI Yoann via GitGitGadget
2026-03-06 21:38 ` Junio C Hamano [this message]
2026-03-06 21:01 ` [PATCH v3 0/3] branch: add prefixes to new branch names Junio C Hamano
2026-03-07 7:05 ` Eric Sunshine
2026-03-08 6:48 ` 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=xmqqzf4ky6xb.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=ps@pks.im \
--cc=yoann.valeri@cea.fr \
/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