Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-02-09 14:35:16 +0300
committerPatrick Steinhardt <ps@pks.im>2018-03-26 12:15:16 +0300
commit26cf48fcf8cf0ecd2b098a41c8873a75e0186577 (patch)
treea4c25bcb552fe8acae616db6565f50c92b44e275 /src/config_file.c
parentfcb0d841e77b6a7fdfe273c82aaa6568c387d054 (diff)
config_file: move include depth into config entry
In order to reject writes to included configuration entries, we need to keep track of whether an entry was included via another configuration file or not. This information is being stored in the `cvar` structure, which is a rather weird location, as it is only used to create a list structure of config entries. Move the include depth into the structure `git_config_entry` instead. While this fixes the layering issue, it enables users of libgit2 to access the depth, too.
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 4cf322f04..d4e1c0a81 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -26,7 +26,6 @@
typedef struct cvar_t {
struct cvar_t *next;
git_config_entry *entry;
- bool included; /* whether this is part of [include] */
} cvar_t;
typedef struct git_config_file_iter {
@@ -118,7 +117,7 @@ int git_config_file_normalize_section(char *start, char *end)
}
/* Add or append the new config option */
-static int append_entry(git_strmap *values, git_config_entry *entry, bool included)
+static int append_entry(git_strmap *values, git_config_entry *entry)
{
git_strmap_iter pos;
cvar_t *existing, *var;
@@ -127,7 +126,6 @@ static int append_entry(git_strmap *values, git_config_entry *entry, bool includ
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)) {
@@ -444,7 +442,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
goto out;
}
- if (existing->included) {
+ if (existing->entry->include_depth) {
giterr_set(GITERR_CONFIG, "modifying included variable is not supported");
ret = -1;
goto out;
@@ -584,7 +582,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
var = git_strmap_value_at(values, pos);
refcounted_strmap_free(map);
- if (var->included) {
+ if (var->entry->include_depth) {
giterr_set(GITERR_CONFIG, "cannot delete included variable");
return -1;
}
@@ -884,7 +882,7 @@ struct parse_data {
const char *file_path;
git_strmap *values;
git_config_level_t level;
- int depth;
+ unsigned int depth;
};
static int parse_include(git_config_parser *reader,
@@ -1053,8 +1051,9 @@ static int read_on_variable(
entry->name = git_buf_detach(&buf);
entry->value = var_value;
entry->level = parse_data->level;
+ entry->include_depth = parse_data->depth;
- if ((result = append_entry(parse_data->values, entry, !!parse_data->depth)) < 0)
+ if ((result = append_entry(parse_data->values, entry)) < 0)
return result;
result = 0;