summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-02-09 11:19:47 +0000
committerPatrick Steinhardt <ps@pks.im>2018-03-26 10:15:16 +0100
commitfcb0d841e77b6a7fdfe273c82aaa6568c387d054 (patch)
tree891b36c0cd94feeea88cbbf38bca34e2cfc436cb /src/config_file.c
parentdfcd923c9f7e96f99d34a1a5e8d23c7bff6098b6 (diff)
downloadlibgit2-fcb0d841e77b6a7fdfe273c82aaa6568c387d054.tar.gz
config_file: move cvar handling into `append_entry`
The code appending new configuration entries to our current list first allocates the `cvar` structure and then passes it to `append_entry`. As we want to extend `append_entry` to store configuration entries in a map as well as in a list for ordered iteration, we will have to create two `cvar` structures, though. As such, the future change will become much easier when allocation of the `cvar` structure is doen in `append_entry` itself.
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 6890af65c..4cf322f04 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -118,15 +118,20 @@ int git_config_file_normalize_section(char *start, char *end)
}
/* Add or append the new config option */
-static int append_entry(git_strmap *values, cvar_t *var)
+static int append_entry(git_strmap *values, git_config_entry *entry, bool included)
{
git_strmap_iter pos;
- cvar_t *existing;
+ cvar_t *existing, *var;
int error = 0;
- pos = git_strmap_lookup_index(values, var->entry->name);
+ var = git__calloc(1, sizeof(cvar_t));
+ GITERR_CHECK_ALLOC(var);
+ var->entry = entry;
+ var->included = included;
+
+ pos = git_strmap_lookup_index(values, entry->name);
if (!git_strmap_valid_index(values, pos)) {
- git_strmap_insert(values, var->entry->name, var, &error);
+ git_strmap_insert(values, entry->name, var, &error);
} else {
existing = git_strmap_value_at(values, pos);
while (existing->next != NULL) {
@@ -1028,7 +1033,7 @@ static int read_on_variable(
{
struct parse_data *parse_data = (struct parse_data *)data;
git_buf buf = GIT_BUF_INIT;
- cvar_t *var;
+ git_config_entry *entry;
int result = 0;
GIT_UNUSED(line);
@@ -1043,28 +1048,24 @@ static int read_on_variable(
return -1;
}
- var = git__calloc(1, sizeof(cvar_t));
- GITERR_CHECK_ALLOC(var);
- var->entry = git__calloc(1, sizeof(git_config_entry));
- GITERR_CHECK_ALLOC(var->entry);
-
- var->entry->name = git_buf_detach(&buf);
- var->entry->value = var_value;
- var->entry->level = parse_data->level;
- var->included = !!parse_data->depth;
+ entry = git__calloc(1, sizeof(git_config_entry));
+ GITERR_CHECK_ALLOC(entry);
+ entry->name = git_buf_detach(&buf);
+ entry->value = var_value;
+ entry->level = parse_data->level;
- if ((result = append_entry(parse_data->values, var)) < 0)
+ if ((result = append_entry(parse_data->values, entry, !!parse_data->depth)) < 0)
return result;
result = 0;
/* Add or append the new config option */
- if (!git__strcmp(var->entry->name, "include.path"))
- result = parse_include(reader, parse_data, var->entry->value);
- else if (!git__prefixcmp(var->entry->name, "includeif.") &&
- !git__suffixcmp(var->entry->name, ".path"))
+ if (!git__strcmp(entry->name, "include.path"))
+ result = parse_include(reader, parse_data, entry->value);
+ else if (!git__prefixcmp(entry->name, "includeif.") &&
+ !git__suffixcmp(entry->name, ".path"))
result = parse_conditional_include(reader, parse_data,
- var->entry->name, var->entry->value);
+ entry->name, entry->value);
return result;