From f3dad3acd75651099c0502e7586ef5a44c22684f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 20:06:36 +0200 Subject: [PATCH] Add fall-back support to the configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a config has several files, we need to check all of them before we can say that a variable doesn't exist. Signed-off-by: Carlos Martín Nieto --- src/config.c | 12 +++++++++--- tests/resources/config/.gitconfig | Bin 36 -> 50 bytes tests/t15-config.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 29b9b799f..39a236ad9 100644 --- a/src/config.c +++ b/src/config.c @@ -310,13 +310,19 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out) { file_internal *internal; git_config_file *file; + int i, error; if (cfg->files.length == 0) return git__throw(GIT_EINVALIDARGS, "Cannot get variable value; no files open in the `git_config` instance"); - internal = git_vector_get(&cfg->files, 0); - file = internal->file; + for (i = 0; i < cfg->files.length; ++i) { + internal = git_vector_get(&cfg->files, i); + file = internal->file; + error = file->get(file, name, out); + if (error == GIT_SUCCESS) + break; + } - return file->get(file, name, out); + return error; } diff --git a/tests/resources/config/.gitconfig b/tests/resources/config/.gitconfig index 8f8075b60ac07b9be5cb10abdd334d30ebed3e38..fa72bddfc67268526d286766501b279370ef0db2 100644 GIT binary patch delta 19 acmY!}nxMkRS)8AnT9T2Om#$!|U<3d+f(4%d delta 4 LcmXp~nV