Skip to content

Commit 8c0b071

Browse files
committed
config_file: pass complete entry structure into append_entry
Currently, we only parse the entry map into `append_entry` to append new configuration entries to it. Instead, though, we can just pass the complete `diskfile_entries` structure into it. This allows us to easily extend `diskfile_entries` by another singly linked list of configuration entries.
1 parent eafb840 commit 8c0b071

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/config_file.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ typedef struct {
7272
typedef struct {
7373
const git_repository *repo;
7474
const char *file_path;
75-
git_strmap *values;
75+
diskfile_entries *entries;
7676
git_config_level_t level;
7777
unsigned int depth;
7878
} diskfile_parse_state;
7979

80-
static int config_read(git_strmap *values, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth);
80+
static int config_read(diskfile_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth);
8181
static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const regex_t *preg, const char *value);
8282
static char *escape_value(const char *ptr);
8383

@@ -130,7 +130,7 @@ int git_config_file_normalize_section(char *start, char *end)
130130
}
131131

132132
/* Add or append the new config option */
133-
static int append_entry(git_strmap *values, git_config_entry *entry)
133+
static int diskfile_entries_append(diskfile_entries *entries, git_config_entry *entry)
134134
{
135135
git_strmap_iter pos;
136136
config_entry_list *existing, *var;
@@ -140,11 +140,11 @@ static int append_entry(git_strmap *values, git_config_entry *entry)
140140
GITERR_CHECK_ALLOC(var);
141141
var->entry = entry;
142142

143-
pos = git_strmap_lookup_index(values, entry->name);
144-
if (!git_strmap_valid_index(values, pos)) {
145-
git_strmap_insert(values, entry->name, var, &error);
143+
pos = git_strmap_lookup_index(entries->map, entry->name);
144+
if (!git_strmap_valid_index(entries->map, pos)) {
145+
git_strmap_insert(entries->map, entry->name, var, &error);
146146
} else {
147-
existing = git_strmap_value_at(values, pos);
147+
existing = git_strmap_value_at(entries->map, pos);
148148
while (existing->next != NULL) {
149149
existing = existing->next;
150150
}
@@ -242,7 +242,7 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
242242
if (!git_path_exists(b->file.path))
243243
return 0;
244244

245-
if (res < 0 || (res = config_read(b->header.entries->map, repo, &b->file, level, 0)) < 0) {
245+
if (res < 0 || (res = config_read(b->header.entries, repo, &b->file, level, 0)) < 0) {
246246
diskfile_entries_free(b->header.entries);
247247
b->header.entries = NULL;
248248
}
@@ -309,7 +309,7 @@ static int config_refresh(git_config_backend *cfg)
309309
}
310310
git_array_clear(b->file.includes);
311311

312-
if ((error = config_read(entries->map, b->header.repo, &b->file, b->header.level, 0)) < 0)
312+
if ((error = config_read(entries, b->header.repo, &b->file, b->header.level, 0)) < 0)
313313
goto out;
314314

315315
if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) {
@@ -900,7 +900,7 @@ static int parse_include(git_config_parser *reader,
900900
git_array_init(include->includes);
901901
include->path = git_buf_detach(&path);
902902

903-
result = config_read(parse_data->values, parse_data->repo,
903+
result = config_read(parse_data->entries, parse_data->repo,
904904
include, parse_data->level, parse_data->depth+1);
905905

906906
if (result == GIT_ENOTFOUND) {
@@ -1045,7 +1045,7 @@ static int read_on_variable(
10451045
entry->level = parse_data->level;
10461046
entry->include_depth = parse_data->depth;
10471047

1048-
if ((result = append_entry(parse_data->values, entry)) < 0)
1048+
if ((result = diskfile_entries_append(parse_data->entries, entry)) < 0)
10491049
return result;
10501050

10511051
result = 0;
@@ -1063,7 +1063,7 @@ static int read_on_variable(
10631063
}
10641064

10651065
static int config_read(
1066-
git_strmap *values,
1066+
diskfile_entries *entries,
10671067
const git_repository *repo,
10681068
git_config_file *file,
10691069
git_config_level_t level,
@@ -1097,7 +1097,7 @@ static int config_read(
10971097

10981098
parse_data.repo = repo;
10991099
parse_data.file_path = file->path;
1100-
parse_data.values = values;
1100+
parse_data.entries = entries;
11011101
parse_data.level = level;
11021102
parse_data.depth = depth;
11031103

0 commit comments

Comments
 (0)