git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv3 7/9] config parsing options: allow one flag multiple times

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2013, 18:52 UTC
Message-ID
<7vk3k0j7gi.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1375530686-2309-8-git-send-email-stefanbeller@googlemail.com>
Stefan Beller <stefanbeller@googlemail.com> writes:
Show 16 quoted lines
> This task emerged from b04ba2bb (parse-options: deprecate OPT_BOOLEAN,
> 2011-09-27).
>
> This commit introduces a change for the users, after this patch
> you can pass one of the config level flags multiple times:
> Before:
> 	$ git config --global --global --list
> 	error: only one config file at a time.
> 	usage: ...
>
> Afterwards this will work. This is due to the following check in the code:
> 	if (use_global_config + use_system_config + use_local_config +
> 	    !!given_config_file + !!given_config_blob > 1) {
> 		error("only one config file at a time.");
> 		usage_with_options(builtin_config_usage, builtin_config_options);
> 	}

Of course, you could further lose that "at most one of them" logic by using CMDMODE. That will involve updating the logic that currently looks at these three variables to look at one enum that can have 4 states (nothing specified, and one of these three specified), which will be more involved change, but the resulting code may become simpler (I didn't try---I am just speculating).

Thanks.
Show 8 quoted lines
>
> With OPT_BOOL instead of OPT_BOOLEAN the variables use_global_config,
> use_system_config, use_local_config will only have the value 0 if the
> command line option was not passed or 1 no matter how often the
> respective command line option was passed.
>
> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
> ---
Show 20 quoted lines
>  builtin/config.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/config.c b/builtin/config.c
> index da12fdb..4ab9e9a 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -50,9 +50,9 @@ static int respect_includes = -1;
>  
>  static struct option builtin_config_options[] = {
>  	OPT_GROUP(N_("Config file location")),
> -	OPT_BOOLEAN(0, "global", &use_global_config, N_("use global config file")),
> -	OPT_BOOLEAN(0, "system", &use_system_config, N_("use system config file")),
> -	OPT_BOOLEAN(0, "local", &use_local_config, N_("use repository config file")),
> +	OPT_BOOL(0, "global", &use_global_config, N_("use global config file")),
> +	OPT_BOOL(0, "system", &use_system_config, N_("use system config file")),
> +	OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")),
>  	OPT_STRING('f', "file", &given_config_file, N_("file"), N_("use given config file")),
>  	OPT_STRING(0, "blob", &given_config_blob, N_("blob-id"), N_("read config from given blob object")),
>  	OPT_GROUP(N_("Action")),
Previous: Stefan BellerNext: Stefan Beller
Message 10 of 27 in “[PATCHv3 0/9] Removing deprecated parsing macros”
  1. Stefan BellerAug 3, 2013
  2. 1/9 Remove deprecated OPTION_BOOLEAN for parsing argumentsStefan Beller, Aug 3, 2013
  3. 2/9 Replace deprecated OPT_BOOLEAN by OPT_BOOLStefan Beller, Aug 3, 2013
  4. 3/9 log, format-patch: parsing uses OPT__QUIETStefan Beller, Aug 3, 2013
  5. 4/9 checkout: remove superfluous local variableStefan Beller, Aug 3, 2013
  6. 5/9 branch, commit, name-rev: ease up boolean conditionsStefan Beller, Aug 3, 2013
  7. 6/9 hash-object: Replace stdin parsing OPT_BOOLEAN by OPT_COUNTUPStefan Beller, Aug 3, 2013
  8. Junio C HamanoAug 5, 2013
  9. 7/9 config parsing options: allow one flag multiple timesStefan Beller, Aug 3, 2013
  10. Junio C HamanoAug 5, 2013
  11. 8/9 checkout-index: Fix negations of even numbers of -nStefan Beller, Aug 3, 2013
  12. 9/9 revert: use the OPT_CMDMODE for parsing, reducing codeStefan Beller, Aug 3, 2013
  13. Stefan BellerAug 3, 2013
  14. Junio C HamanoAug 6, 2013
  15. Stefan BellerAug 6, 2013
  16. branch, commit, name-rev: ease up boolean conditionsStefan Beller, Aug 6, 2013
  17. Eric SunshineAug 6, 2013
  18. Stefan BellerAug 6, 2013
  19. branch, commit, name-rev: ease up boolean conditionsStefan Beller, Aug 6, 2013
  20. Junio C HamanoAug 6, 2013
  21. 0/4 Update built-in parseopt macrosJunio C Hamano, Aug 6, 2013
  22. 1/4 OPT__QUIET(): switch from count-up to true boolJunio C Hamano, Aug 6, 2013
  23. 2/4 OPT__VERBOSE(): clarify its expected use by using OPT_COUNTUPJunio C Hamano, Aug 6, 2013
  24. 3/4 OPT__DRY_RUN(): use OPT_BOOL, not OPT_BOOLEANJunio C Hamano, Aug 6, 2013
  25. 4/4 OPT__FORCE(): clarify its expected use by using OPT_COUNTUPJunio C Hamano, Aug 6, 2013
  26. Stefan BellerAug 7, 2013
  27. Junio C HamanoAug 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.