diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-31 08:08:17 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-04-18 16:07:32 +0200 |
| commit | bd95f836f51804011b8a8c532471733f92f3e119 (patch) | |
| tree | 47c56ea8ac1ecd12eff50597f031e1647b0a8444 /src | |
| parent | c047317e400efc75b07aa0fff61ee1fcd794e74e (diff) | |
| download | libgit2-bd95f836f51804011b8a8c532471733f92f3e119.tar.gz | |
config: split out the refresh step
This will be used by the writing commands in a later step.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config_file.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/config_file.c b/src/config_file.c index 437a5c592..24ace6039 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -254,11 +254,34 @@ static int config_open(git_config_backend *cfg, git_config_level_t level) return res; } +/* The meat of the refresh, as we want to use it in different places */ +static int config__refresh(git_config_backend *cfg) +{ + git_strmap *values = NULL; + diskfile_backend *b = (diskfile_backend *)cfg; + struct reader *reader = NULL; + int error = 0; + + if ((error = git_strmap_alloc(&values)) < 0) + goto out; + + reader = git_array_get(b->readers, git_array_size(b->readers) - 1); + + if ((error = config_parse(values, b, reader, b->level, 0)) < 0) + goto out; + + values = git__swap(b->header.values, values); + +out: + free_vars(values); + git_buf_free(&reader->buffer); + return error; +} + static int config_refresh(git_config_backend *cfg) { int error = 0, updated = 0, any_updated = 0; diskfile_backend *b = (diskfile_backend *)cfg; - git_strmap *values = NULL; struct reader *reader = NULL; uint32_t i; @@ -278,19 +301,7 @@ static int config_refresh(git_config_backend *cfg) if (!any_updated) return (error == GIT_ENOTFOUND) ? 0 : error; - - if ((error = git_strmap_alloc(&values)) < 0) - goto cleanup; - - if ((error = config_parse(values, b, reader, b->level, 0)) < 0) - goto cleanup; - - values = git__swap(b->header.values, values); - -cleanup: - free_vars(values); - git_buf_free(&reader->buffer); - return error; + return config__refresh(cfg); } static void backend_free(git_config_backend *_backend) |
