diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-05-23 11:51:00 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-10-09 11:19:42 +0200 |
commit | 529e873cef18ec98246d32d28c7a0b0e3467fe27 (patch) | |
tree | f810490f62966f39ea9c86e041b8102956d2306f /src/config_file.c | |
parent | d02cf564a012ea8f6d4d4fd70a3102b94058f759 (diff) | |
download | libgit2-529e873cef18ec98246d32d28c7a0b0e3467fe27.tar.gz |
config: pass repository when opening config files
Our current configuration logic is completely oblivious of any
repository, but only cares for actual file paths. Unfortunately, we are
forced to break this assumption by the introduction of conditional
includes, which are evaluated in the context of a repository. Right now,
only one conditional exists with "gitdir:" -- it will only include the
configuration if the current repository's git directory matches the
value passed to "gitdir:".
To support these conditionals, we have to break our API and make the
repository available when opening a configuration file. This commit
extends the `open` call of configuration backends to include another
repository and adjusts existing code to have it available. This includes
the user-visible functions `git_config_add_file_ondisk` and
`git_config_add_backend`.
Diffstat (limited to 'src/config_file.c')
-rw-r--r-- | src/config_file.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/config_file.c b/src/config_file.c index 00d6d9e13..4146bd8b2 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -105,6 +105,7 @@ typedef struct { diskfile_header header; git_config_level_t level; + const git_repository *repo; bool locked; git_filebuf locked_buf; @@ -281,12 +282,13 @@ static void config_file_clear(struct config_file *file) git__free(file->path); } -static int config_open(git_config_backend *cfg, git_config_level_t level) +static int config_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo) { int res; diskfile_backend *b = (diskfile_backend *)cfg; b->level = level; + b->repo = repo; if ((res = refcounted_strmap_alloc(&b->header.values)) < 0) return res; @@ -439,7 +441,7 @@ static int config_iterator_new( if ((error = config_snapshot(&snapshot, backend)) < 0) return error; - if ((error = snapshot->open(snapshot, b->level)) < 0) + if ((error = snapshot->open(snapshot, b->level, b->repo)) < 0) return error; it = git__calloc(1, sizeof(git_config_file_iter)); @@ -831,7 +833,7 @@ static void backend_readonly_free(git_config_backend *_backend) git__free(backend); } -static int config_readonly_open(git_config_backend *cfg, git_config_level_t level) +static int config_readonly_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo) { diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg; diskfile_backend *src = b->snapshot_from; @@ -842,8 +844,9 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve if (!src_header->parent.readonly && (error = config_refresh(&src_header->parent)) < 0) return error; - /* We're just copying data, don't care about the level */ + /* We're just copying data, don't care about the level or repo*/ GIT_UNUSED(level); + GIT_UNUSED(repo); if ((src_map = refcounted_strmap_take(src_header)) == NULL) return -1; |