summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-02-04 23:18:30 +0100
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-02-17 19:43:43 +0100
commit5e0dc4af013e23d0cbc737d8ab2756aaf38e1516 (patch)
treeb6b8aaf99d7775bb177ca5f429a7677965fb6ba5 /src/config.c
parent78d65f390f031d18ce698a24e1f83b99cc8cf699 (diff)
downloadlibgit2-5e0dc4af013e23d0cbc737d8ab2756aaf38e1516.tar.gz
Support getting multivars
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index 490d8b52d..ccc7362ac 100644
--- a/src/config.c
+++ b/src/config.c
@@ -337,6 +337,33 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
return git__throw(error, "Config value '%s' not found", name);
}
+int git_config_get_multivar(git_config *cfg, const char *name, const char *regexp,
+ int (*fn)(const char *value, void *data), void *data)
+{
+ file_internal *internal;
+ git_config_file *file;
+ int error = GIT_ENOTFOUND;
+ unsigned int i;
+
+
+ if (cfg->files.length == 0)
+ return git__throw(GIT_EINVALIDARGS, "Cannot get variable value; no files open in the `git_config` instance");
+
+ /*
+ * This loop runs the "wrong" way 'round because we need to
+ * look at every value from the most general to most specific
+ */
+ for (i = cfg->files.length; i > 0; --i) {
+ internal = git_vector_get(&cfg->files, i - 1);
+ file = internal->file;
+ error = file->get_multivar(file, name, regexp, fn, data);
+ if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
+ git__rethrow(error, "Failed to get multivar");
+ }
+
+ return GIT_SUCCESS;
+}
+
int git_config_find_global_r(git_buf *path)
{
return git_futils_find_global_file(path, GIT_CONFIG_FILENAME);