[PATCH 8/9] git_config_set: use do_config_from_file() directly
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Mar 29, 2018, 15:19 UTC
- Message-ID
- <e3032300946eb5962878341f7796f5872c4d138d.1522336130.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1522336130.git.johannes.schindelin@gmx.de>
Technically, it is the git_config_set_multivar_in_file_gently() function that we modify here (but the oneline would get too long if we were that precise).
This change prepares the git_config_set machinery to allow reusing empty sections, by using the file-local function do_config_from_file() directly (whose signature can then be changed without any effect outside of config.c).
An incidental benefit is that we avoid a level of indirection, and we also avoid calling flockfile()/funlockfile() when we already know that we are not operating on stdin/stdout here.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- config.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c index 503aef4b318..eb1e0d335fc 100644 --- a/config.c +++ b/config.c @@ -2706,6 +2706,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, struct stat st; size_t copy_begin, copy_end; int i, new_line = 0; + FILE *f; if (value_regex == NULL) store.value_regex = NULL; @@ -2739,7 +2740,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, * As a side effect, we make sure to transform only a valid * existing config file. */ - if (git_config_from_file(store_aux, config_filename, NULL)) { + f = fopen_or_warn(config_filename, "r"); + if (!f || do_config_from_file(store_aux, CONFIG_ORIGIN_FILE, + config_filename, config_filename, + f, NULL)) { error("invalid config file %s", config_filename); if (store.value_regex != NULL && store.value_regex != CONFIG_REGEX_NONE) { @@ -2747,8 +2751,11 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, free(store.value_regex); } ret = CONFIG_INVALID_FILE; + if (f) + fclose(f); goto out_free; - } + } else + fclose(f); if (store.value_regex != NULL && store.value_regex != CONFIG_REGEX_NONE) {
-- 2.16.2.windows.1.26.g2cc3565eb4b