Commit 36cf1db2 by Sven Strickroth

Support empty values for git_config_get_mapped and git_config_lookup_map_value

Signed-off-by: Sven Strickroth <email@cs-ware.de>
parent 86d04918
...@@ -1227,9 +1227,6 @@ int git_config_lookup_map_value( ...@@ -1227,9 +1227,6 @@ int git_config_lookup_map_value(
{ {
size_t i; size_t i;
if (!value)
goto fail_parse;
for (i = 0; i < map_n; ++i) { for (i = 0; i < map_n; ++i) {
const git_configmap *m = maps + i; const git_configmap *m = maps + i;
...@@ -1252,7 +1249,7 @@ int git_config_lookup_map_value( ...@@ -1252,7 +1249,7 @@ int git_config_lookup_map_value(
break; break;
case GIT_CONFIGMAP_STRING: case GIT_CONFIGMAP_STRING:
if (strcasecmp(value, m->str_match) == 0) { if (value && strcasecmp(value, m->str_match) == 0) {
*out = m->map_value; *out = m->map_value;
return 0; return 0;
} }
...@@ -1260,7 +1257,6 @@ int git_config_lookup_map_value( ...@@ -1260,7 +1257,6 @@ int git_config_lookup_map_value(
} }
} }
fail_parse:
git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value); git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value);
return -1; return -1;
} }
......
...@@ -955,11 +955,13 @@ void test_config_read__get_mapped(void) ...@@ -955,11 +955,13 @@ void test_config_read__get_mapped(void)
cl_git_mkfile("./testconfig", "[header]\n key1 = 1\n key2 = true\n key3\n key4 = always\n key5 = false\n key6 = 0\n key7 = never\n"); cl_git_mkfile("./testconfig", "[header]\n key1 = 1\n key2 = true\n key3\n key4 = always\n key5 = false\n key6 = 0\n key7 = never\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
// check aprsing bool and string // check parsing bool and string
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key1", _test_map1, ARRAY_SIZE(_test_map1))); cl_git_pass(git_config_get_mapped(&val, cfg, "header.key1", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE); cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key2", _test_map1, ARRAY_SIZE(_test_map1))); cl_git_pass(git_config_get_mapped(&val, cfg, "header.key2", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE); cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key3", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key4", _test_map1, ARRAY_SIZE(_test_map1))); cl_git_pass(git_config_get_mapped(&val, cfg, "header.key4", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_ALWAYS); cl_assert_equal_i(val, MAP_ALWAYS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment