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

Re: [PATCH 5/5] config: add --type=bool-or-auto switch

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 8, 2021, 18:36 UTC
Message-ID
<xmqq5z0wtyhw.fsf@gitster.g>
In-Reply-To
<patch-5.6-9f8996a888-20210408T133125Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 9 quoted lines
> Now that we're using git_config_tristate() internally let's expose it
> via "git config" like we do "bool", "int" etc for completeness, and so
> that we can easily test it.
>
> Unlike the --type=bool-or-str option added in dbd8c09bfe (mergetool:
> allow auto-merge for meld to follow the vim-diff behavior, 2020-05-07)
> we don't have or anticipate any in-tree user of this except the tests.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
OK.
Show 10 quoted lines
> @@ -263,6 +267,12 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
>  				strbuf_addstr(buf, value_);
>  			else
>  				strbuf_addstr(buf, v ? "true" : "false");
> +		} else if (type == TYPE_BOOL_OR_AUTO) {
> +			int v = git_config_tristate(key_, value_);
> +			if (v == 2)
> +				strbuf_addstr(buf, "auto");
> +			else
> +				strbuf_addstr(buf, v ? "true" : "false");
Makes sense.
Show 33 quoted lines
> +test_expect_success 'there is no --bool-or-auto, --<type> is deprecated in favor of --type=<type>' '
> +	test_expect_code 129 git config --bool-or-auto
> +'
> +
> +test_expect_success 'get --type=bool-or-auto' '
> +	cat >.git/config <<-\EOF &&
> +	[bool]
> +	true1
> +	true2 = true
> +	false = false
> +	[int]
> +	int1 = 0
> +	int2 = 1
> +	int3 = -1
> +	[string]
> +	string1 = hello
> +	string2 = there you
> +	[auto]
> +	auto1 = auto
> +	auto2 = AUTO
> +	[bad-auto]
> +	bad-auto1 = AUTOMATIC
> +	EOF
> +	cat >expect <<-\EOF &&
> +	true
> +	true
> +	false
> +	false
> +	true
> +	true
> +	auto
> +	auto
> +	EOF

Almost the same comment applies to the expected output as the earlier patch.

Other than that, (and adjusting for 2 that should be turned into symbolic constant in an earlier step in a reroll), this step looks quite sensible.

Thanks.
Show 19 quoted lines
> +	{
> +		git config --type=bool-or-auto bool.true1 &&
> +		git config --type=bool-or-auto bool.true2 &&
> +		git config --type=bool-or-auto bool.false &&
> +		git config --type=bool-or-auto int.int1 &&
> +		git config --type=bool-or-auto int.int2 &&
> +		git config --type=bool-or-auto int.int3 &&
> +		git config --type=bool-or-auto auto.auto1 &&
> +		git config --type=bool-or-auto auto.auto2
> +	} >actual &&
> +	test_cmp expect actual &&
> +
> +	test_must_fail git config --type=bool-or-auto --get bad-auto.bad-auto1 2>err &&
> +	grep "bad tristate config value" err
> +'
> +
>  cat >expect <<\EOF
>  [bool]
>  	true1 = true
Previous: Ævar Arnfjörð Bjarmason
Message 21 of 21 in “config: support --type=bool-or-auto for "tristate" parsing”
  1. 0/5 config: support --type=bool-or-auto for "tristate" parsingÆvar Arnfjörð Bjarmason, Apr 8, 2021
  2. 1/5 config.c: add a comment about why value=NULL is trueÆvar Arnfjörð Bjarmason, Apr 8, 2021
  3. Junio C HamanoApr 8, 2021
  4. 2/5 config tests: test for --bool-or-strÆvar Arnfjörð Bjarmason, Apr 8, 2021
  5. Junio C HamanoApr 8, 2021
  6. Ævar Arnfjörð BjarmasonApr 8, 2021
  7. 3/5 git-config: document --bool-or-str and --type=bool-or-strÆvar Arnfjörð Bjarmason, Apr 8, 2021
  8. Junio C HamanoApr 8, 2021
  9. 4/5 config.c: add a "tristate" helperÆvar Arnfjörð Bjarmason, Apr 8, 2021
  10. Junio C HamanoApr 8, 2021
  11. Ævar Arnfjörð BjarmasonApr 8, 2021
  12. Junio C HamanoApr 8, 2021
  13. Ævar Arnfjörð BjarmasonApr 9, 2021
  14. Junio C HamanoApr 9, 2021
  15. Junio C HamanoApr 8, 2021
  16. Jeff KingApr 9, 2021
  17. Junio C HamanoApr 9, 2021
  18. Jeff KingApr 10, 2021
  19. Junio C HamanoApr 10, 2021
  20. 5/5 config: add --type=bool-or-auto switchÆvar Arnfjörð Bjarmason, Apr 8, 2021
  21. Junio C HamanoApr 8, 2021

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.