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
This commit is contained in:
commit
06e9e726d4
1
config.h
1
config.h
@ -56,6 +56,7 @@ struct git_config_source {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum config_origin_type {
|
enum config_origin_type {
|
||||||
|
CONFIG_ORIGIN_UNKNOWN = 0,
|
||||||
CONFIG_ORIGIN_BLOB,
|
CONFIG_ORIGIN_BLOB,
|
||||||
CONFIG_ORIGIN_FILE,
|
CONFIG_ORIGIN_FILE,
|
||||||
CONFIG_ORIGIN_STDIN,
|
CONFIG_ORIGIN_STDIN,
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
* iterate -> iterate over all values using git_config(), and print some
|
* iterate -> iterate over all values using git_config(), and print some
|
||||||
* data for each
|
* 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:
|
* Examples:
|
||||||
*
|
*
|
||||||
* To print the value with highest priority for key "foo.bAr Baz.rock":
|
* 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;
|
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)
|
static int early_config_cb(const char *var, const char *value, void *vdata)
|
||||||
{
|
{
|
||||||
const char *key = vdata;
|
const char *key = vdata;
|
||||||
@ -196,6 +210,9 @@ int cmd__config(int argc, const char **argv)
|
|||||||
} else if (!strcmp(argv[1], "iterate")) {
|
} else if (!strcmp(argv[1], "iterate")) {
|
||||||
git_config(iterate_cb, NULL);
|
git_config(iterate_cb, NULL);
|
||||||
goto exit0;
|
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]);
|
die("%s: Please check the syntax and the function name", argv[0]);
|
||||||
|
@ -161,6 +161,10 @@ test_expect_success 'find integer value for a key' '
|
|||||||
check_config get_int lamb.chop 65
|
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' '
|
test_expect_success 'find string value for a key' '
|
||||||
check_config get_string case.baz hask &&
|
check_config get_string case.baz hask &&
|
||||||
check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\""
|
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
|
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' '
|
test_expect_success 'find bool value for the entered key' '
|
||||||
check_config get_bool goat.head 1 &&
|
check_config get_bool goat.head 1 &&
|
||||||
check_config get_bool goat.skin 0 &&
|
check_config get_bool goat.skin 0 &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user