Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-16 03:39:00 +0400
committerRussell Belfer <rb@github.com>2013-03-16 03:39:00 +0400
commit5540d9477ed143707435324e785336d254b12e47 (patch)
tree4ffaba1990a82cc51ee5169d7d2913ecceef4df2 /src/config.c
parenta5f6138407efb6d8866fe8de5aac13454aefcd82 (diff)
Implement global/system file search paths
The goal of this work is to expose the search logic for "global", "system", and "xdg" files through the git_libgit2_opts() interface. Behind the scenes, I changed the logic for finding files to have a notion of a git_strarray that represents a search path and to store a separate search path for each of the three tiers of config file. For each tier, I implemented a function to initialize it to default values (generally based on environment variables), and then general interfaces to get it, set it, reset it, and prepend new directories to it. Next, I exposed these interfaces through the git_libgit2_opts interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants for the user to control which search path they were modifying. There are alternative designs for the opts interface / argument ordering, so I'm putting this phase out for discussion. Additionally, I ended up doing a little bit of clean up regarding attr.h and attr_file.h, adding a new attrcache.h so the other two files wouldn't have to be included in so many places.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c88
1 files changed, 29 insertions, 59 deletions
diff --git a/src/config.c b/src/config.c
index d6aa3078c..85db0ab3c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -510,62 +510,48 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
return file->set_multivar(file, name, regexp, value);
}
-int git_config_find_global_r(git_buf *path)
+static int git_config__find_file_to_path(
+ char *out, size_t outlen, int (*find)(git_buf *buf))
{
- int error = git_futils_find_global_file(path, GIT_CONFIG_FILENAME);
+ int error = 0;
+ git_buf path = GIT_BUF_INIT;
+
+ if ((error = find(&path)) < 0)
+ goto done;
+
+ if (path.size >= outlen) {
+ giterr_set(GITERR_NOMEMORY, "Buffer is too short for the path");
+ error = -1;
+ goto done;
+ }
+ git_buf_copy_cstr(out, outlen, &path);
+
+done:
+ git_buf_free(&path);
return error;
}
-int git_config_find_xdg_r(git_buf *path)
+int git_config_find_global_r(git_buf *path)
{
- int error = git_futils_find_global_file(path, GIT_CONFIG_FILENAME_ALT);
-
- return error;
+ return git_futils_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_find_global(char *global_config_path, size_t length)
{
- git_buf path = GIT_BUF_INIT;
- int ret = git_config_find_global_r(&path);
-
- if (ret < 0) {
- git_buf_free(&path);
- return ret;
- }
-
- if (path.size >= length) {
- git_buf_free(&path);
- giterr_set(GITERR_NOMEMORY,
- "Path is to long to fit on the given buffer");
- return -1;
- }
+ return git_config__find_file_to_path(
+ global_config_path, length, git_config_find_global_r);
+}
- git_buf_copy_cstr(global_config_path, length, &path);
- git_buf_free(&path);
- return 0;
+int git_config_find_xdg_r(git_buf *path)
+{
+ return git_futils_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG);
}
int git_config_find_xdg(char *xdg_config_path, size_t length)
{
- git_buf path = GIT_BUF_INIT;
- int ret = git_config_find_xdg_r(&path);
-
- if (ret < 0) {
- git_buf_free(&path);
- return ret;
- }
-
- if (path.size >= length) {
- git_buf_free(&path);
- giterr_set(GITERR_NOMEMORY,
- "Path is to long to fit on the given buffer");
- return -1;
- }
-
- git_buf_copy_cstr(xdg_config_path, length, &path);
- git_buf_free(&path);
- return 0;
+ return git_config__find_file_to_path(
+ xdg_config_path, length, git_config_find_xdg_r);
}
int git_config_find_system_r(git_buf *path)
@@ -575,24 +561,8 @@ int git_config_find_system_r(git_buf *path)
int git_config_find_system(char *system_config_path, size_t length)
{
- git_buf path = GIT_BUF_INIT;
- int ret = git_config_find_system_r(&path);
-
- if (ret < 0) {
- git_buf_free(&path);
- return ret;
- }
-
- if (path.size >= length) {
- git_buf_free(&path);
- giterr_set(GITERR_NOMEMORY,
- "Path is to long to fit on the given buffer");
- return -1;
- }
-
- git_buf_copy_cstr(system_config_path, length, &path);
- git_buf_free(&path);
- return 0;
+ return git_config__find_file_to_path(
+ system_config_path, length, git_config_find_system_r);
}
int git_config_open_default(git_config **out)