diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-04-06 23:38:29 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-06 23:38:29 +0300 |
commit | 06e9e726d463b413d45703b31881de4ed99b3417 (patch) | |
tree | a1cad3c86f333a19f1b4d4fc9123236ad122a1ef /t | |
parent | 0a8c337394c208f584173d1c8c0dca600f9be1fe (diff) | |
parent | 9b4a655302aae41a35752acfb61da1b43b4c7ce7 (diff) |
Merge branch 'gc/config-parsing-cleanup'
Config API clean-up to reduce its dependence on static variables
* gc/config-parsing-cleanup:
config.c: rename "struct config_source cf"
config: report cached filenames in die_bad_number()
config.c: remove current_parsing_scope
config.c: remove current_config_kvi
config.c: plumb the_reader through callbacks
config.c: create config_reader and the_reader
config.c: don't assign to "cf_global" directly
config.c: plumb config_source through static fns
Diffstat (limited to 't')
-rw-r--r-- | t/helper/test-config.c | 17 | ||||
-rwxr-xr-x | t/t1308-config-set.sh | 9 |
2 files changed, 26 insertions, 0 deletions
diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 6dc4c37444..c7d43afa64 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -32,6 +32,9 @@ * iterate -> iterate over all values using git_config(), and print some * data for each * + * git_config_int -> iterate over all values using git_config() and print the + * integer value for the entered key or die + * * Examples: * * To print the value with highest priority for key "foo.bAr Baz.rock": @@ -56,6 +59,17 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED) return 0; } +static int parse_int_cb(const char *var, const char *value, void *data) +{ + const char *key_to_match = data; + + if (!strcmp(key_to_match, var)) { + int parsed = git_config_int(value, value); + printf("%d\n", parsed); + } + return 0; +} + static int early_config_cb(const char *var, const char *value, void *vdata) { const char *key = vdata; @@ -196,6 +210,9 @@ int cmd__config(int argc, const char **argv) } else if (!strcmp(argv[1], "iterate")) { git_config(iterate_cb, NULL); goto exit0; + } else if (argc == 3 && !strcmp(argv[1], "git_config_int")) { + git_config(parse_int_cb, (void *) argv[2]); + goto exit0; } die("%s: Please check the syntax and the function name", argv[0]); diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 7def7053e1..777648722c 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -161,6 +161,10 @@ test_expect_success 'find integer value for a key' ' check_config get_int lamb.chop 65 ' +test_expect_success 'parse integer value during iteration' ' + check_config git_config_int lamb.chop 65 +' + test_expect_success 'find string value for a key' ' check_config get_string case.baz hask && check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\"" @@ -175,6 +179,11 @@ test_expect_success 'find integer if value is non parse-able' ' check_config expect_code 128 get_int lamb.head ' +test_expect_success 'non parse-able integer value during iteration' ' + check_config expect_code 128 git_config_int lamb.head 2>result && + grep "fatal: bad numeric config value .* in file \.git/config" result +' + test_expect_success 'find bool value for the entered key' ' check_config get_bool goat.head 1 && check_config get_bool goat.skin 0 && |