Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c86a65b

Browse files
carlosmnEdward Thomson
authored and
Edward Thomson
committed
config: don't special-case multivars that don't exist yet
This special-casing ignores that we might have a locked file, so the hashtable does not represent the contents of the file we want to write. This causes multivar writes to overwrite entries instead of add to them when under lock. There is no need for this as the normal code-path will write to the file just fine, so simply get rid of it.
1 parent a1cf264 commit c86a65b

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

src/config_file.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -553,30 +553,15 @@ static int config_set_multivar(
553553
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
554554
{
555555
diskfile_backend *b = (diskfile_backend *)cfg;
556-
refcounted_strmap *map;
557-
git_strmap *values;
558556
char *key;
559557
regex_t preg;
560558
int result;
561-
khiter_t pos;
562559

563560
assert(regexp);
564561

565562
if ((result = git_config__normalize_name(name, &key)) < 0)
566563
return result;
567564

568-
map = refcounted_strmap_take(&b->header);
569-
values = b->header.values->values;
570-
571-
pos = git_strmap_lookup_index(values, key);
572-
if (!git_strmap_valid_index(values, pos)) {
573-
/* If we don't have it, behave like a normal set */
574-
result = config_set(cfg, name, value);
575-
refcounted_strmap_free(map);
576-
git__free(key);
577-
return result;
578-
}
579-
580565
result = regcomp(&preg, regexp, REG_EXTENDED);
581566
if (result != 0) {
582567
giterr_set_regex(&preg, result);
@@ -591,7 +576,6 @@ static int config_set_multivar(
591576
result = config_refresh(cfg);
592577

593578
out:
594-
refcounted_strmap_free(map);
595579
git__free(key);
596580
regfree(&preg);
597581

tests/config/multivar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void test_config_multivar__add_new(void)
163163

164164
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
165165

166-
cl_git_pass(git_config_set_multivar(cfg, var, "", "variable"));
166+
cl_git_pass(git_config_set_multivar(cfg, var, "$^", "variable"));
167167
n = 0;
168168
cl_git_pass(git_config_get_multivar_foreach(cfg, var, NULL, cb, &n));
169169
cl_assert_equal_i(n, 1);

0 commit comments

Comments
 (0)