diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-07-11 10:56:05 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-07-11 11:10:04 +0200 |
| commit | dbeadf8a9e9cb66f65b894e4dfd1fb23f9f31d5b (patch) | |
| tree | 5b60f577ce6de9f6e371684f707b1ef095f55529 /src/config_mem.c | |
| parent | 3215752653885cbd33abb22ae9c356434d9f9dce (diff) | |
| download | libgit2-dbeadf8a9e9cb66f65b894e4dfd1fb23f9f31d5b.tar.gz | |
config_parse: provide parser init and dispose functions
Right now, all configuration file backends are expected to
directly mess with the configuration parser's internals in order
to set it up. Let's avoid doing that by implementing both a
`git_config_parser_init` and `git_config_parser_dispose` function
to clearly define the interface between configuration backends
and the parser.
Ideally, we would make the `git_config_parser` structure
definition private to its implementation. But as that would
require an additional memory allocation that was not required
before we just live with it being visible to others.
Diffstat (limited to 'src/config_mem.c')
| -rw-r--r-- | src/config_mem.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/config_mem.c b/src/config_mem.c index b563a972e..e4006db32 100644 --- a/src/config_mem.c +++ b/src/config_mem.c @@ -78,20 +78,24 @@ static int read_variable_cb( static int config_memory_open(git_config_backend *backend, git_config_level_t level, const git_repository *repo) { config_memory_backend *memory_backend = (config_memory_backend *) backend; + git_config_parser parser = GIT_PARSE_CTX_INIT; config_memory_parse_data parse_data; - git_config_parser reader; + int error; GIT_UNUSED(repo); - if (memory_backend->cfg.size == 0) - return 0; - - git_parse_ctx_init(&reader.ctx, memory_backend->cfg.ptr, memory_backend->cfg.size); - reader.path = "in-memory"; + if ((error = git_config_parser_init(&parser, "in-memory", memory_backend->cfg.ptr, + memory_backend->cfg.size)) < 0) + goto out; parse_data.entries = memory_backend->entries; parse_data.level = level; - return git_config_parse(&reader, NULL, read_variable_cb, NULL, NULL, &parse_data); + if ((error = git_config_parse(&parser, NULL, read_variable_cb, NULL, NULL, &parse_data)) < 0) + goto out; + +out: + git_config_parser_dispose(&parser); + return error; } static int config_memory_get(git_config_backend *backend, const char *key, git_config_entry **out) |
