Merge pull request #3703 from libgit2/cmn/multivar-set-locked config: don't special-case multivars that don't exist yet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/src/config_file.c b/src/config_file.c
index 584b9fa..02bb2f7 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -561,31 +561,15 @@ static int config_set_multivar(
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{
diskfile_backend *b = (diskfile_backend *)cfg;
- refcounted_strmap *map;
- git_strmap *values;
char *key;
regex_t preg;
int result;
- khiter_t pos;
assert(regexp);
if ((result = git_config__normalize_name(name, &key)) < 0)
return result;
- if ((map = refcounted_strmap_take(&b->header)) == NULL)
- return -1;
- values = b->header.values->values;
-
- pos = git_strmap_lookup_index(values, key);
- if (!git_strmap_valid_index(values, pos)) {
- /* If we don't have it, behave like a normal set */
- result = config_set(cfg, name, value);
- refcounted_strmap_free(map);
- git__free(key);
- return result;
- }
-
result = regcomp(&preg, regexp, REG_EXTENDED);
if (result != 0) {
giterr_set_regex(&preg, result);
@@ -600,7 +584,6 @@ static int config_set_multivar(
result = config_refresh(cfg);
out:
- refcounted_strmap_free(map);
git__free(key);
regfree(&preg);
diff --git a/tests/config/multivar.c b/tests/config/multivar.c
index 0150089..d1b8c4c 100644
--- a/tests/config/multivar.c
+++ b/tests/config/multivar.c
@@ -163,7 +163,7 @@ void test_config_multivar__add_new(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
- cl_git_pass(git_config_set_multivar(cfg, var, "", "variable"));
+ cl_git_pass(git_config_set_multivar(cfg, var, "$^", "variable"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, var, NULL, cb, &n));
cl_assert_equal_i(n, 1);