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_file.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_file.c')
-rw-r--r-- | src/config_file.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/config_file.c b/src/config_file.c index d2238e811..51a3e93e2 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1176,9 +1176,9 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char { char *orig_section = NULL, *section = NULL, *orig_name, *name, *ldot; git_buf buf = GIT_BUF_INIT, contents = GIT_BUF_INIT; + git_config_parser parser = GIT_CONFIG_PARSER_INIT; git_filebuf file = GIT_FILEBUF_INIT; struct write_data write_data; - git_config_parser reader; int error; memset(&write_data, 0, sizeof(write_data)); @@ -1196,8 +1196,8 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char if (error < 0 && error != GIT_ENOTFOUND) goto done; - reader.path = cfg->file.path; - git_parse_ctx_init(&reader.ctx, contents.ptr, contents.size); + if ((git_config_parser_init(&parser, cfg->file.path, contents.ptr, contents.size)) < 0) + goto done; ldot = strrchr(key, '.'); name = ldot + 1; @@ -1217,7 +1217,7 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char write_data.preg = preg; write_data.value = value; - if ((error = git_config_parse(&reader, write_on_section, write_on_variable, + if ((error = git_config_parse(&parser, write_on_section, write_on_variable, write_on_comment, write_on_eof, &write_data)) < 0) goto done; @@ -1243,7 +1243,7 @@ done: git_buf_dispose(&buf); git_buf_dispose(&contents); git_filebuf_cleanup(&file); - git_parse_ctx_clear(&reader.ctx); + git_config_parser_dispose(&parser); return error; } |