]> git.proxmox.com Git - libgit2.git/commitdiff
Correctly read xdr compatible %HOME%/.config/git/config config file
authorSven Strickroth <email@cs-ware.de>
Mon, 24 Sep 2012 16:59:00 +0000 (18:59 +0200)
committerSven Strickroth <email@cs-ware.de>
Mon, 24 Sep 2012 16:59:00 +0000 (18:59 +0200)
This file is not just read if the global config file (%HOME%/.gitconfig)
is not found, however, it is used everytime but with lower priority.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
include/git2/config.h
src/config.c
src/repository.c

index 21d8a0b05ddaa66e91a312b52e56993154359a9c..a3202c2b1323f0ff9ecde84c5681fc80e392c6b1 100644 (file)
@@ -61,12 +61,32 @@ typedef struct {
  * may be used on any `git_config` call to load the
  * global configuration file.
  *
+ * This method will not guess the path to the xdr compatible
+ * config file (.config/git/config).
+ *
  * @param global_config_path Buffer of GIT_PATH_MAX length to store the path
  * @return 0 if a global configuration file has been
  *     found. Its path will be stored in `buffer`.
  */
 GIT_EXTERN(int) git_config_find_global(char *global_config_path, size_t length);
 
+/**
+ * Locate the path to the global xdr compatible configuration file
+ *
+ * The xdr compatible configuration file is usually
+ * located in `$HOME/.config/git/config`.
+ *
+ * This method will try to guess the full path to that
+ * file, if the file exists. The returned path
+ * may be used on any `git_config` call to load the
+ * global configuration file.
+ *
+ * @param global_config_path Buffer of GIT_PATH_MAX length to store the path
+ * @return 0 if a global configuration file has been
+ *     found. Its path will be stored in `buffer`.
+ */
+GIT_EXTERN(int) git_config_find_xdr(char *global_config_path, size_t length);
+
 /**
  * Locate the path to the system configuration file
  *
index e62dccf51ad3eb7102b57114eddd920ec5f68f71..b3d6fc69a34b1d4890c7b2dc6b0c31663ae782c9 100644 (file)
@@ -451,8 +451,12 @@ int git_config_find_global_r(git_buf *path)
 {
        int error = git_futils_find_global_file(path, GIT_CONFIG_FILENAME);
 
-       if (error == GIT_ENOTFOUND)
-               error = git_futils_find_global_file(path, GIT_CONFIG_FILENAME_ALT);
+       return error;
+}
+
+int git_config_find_xdr_r(git_buf *path)
+{
+       int error = git_futils_find_global_file(path, GIT_CONFIG_FILENAME_ALT);
 
        return error;
 }
index 1a46db0a51444b7cd18c779d23898c54410751b4..3906cb3880ac9fb8049c5cae5dd7132a861f19e3 100644 (file)
@@ -445,6 +445,7 @@ static int load_config(
        git_config **out,
        git_repository *repo,
        const char *global_config_path,
+       const char *xdr_config_path,
        const char *system_config_path)
 {
        git_buf config_path = GIT_BUF_INIT;
@@ -459,13 +460,18 @@ static int load_config(
                &config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO) < 0)
                goto on_error;
 
-       if (git_config_add_file_ondisk(cfg, config_path.ptr, 3) < 0)
+       if (git_config_add_file_ondisk(cfg, config_path.ptr, 4) < 0)
                goto on_error;
 
        git_buf_free(&config_path);
 
        if (global_config_path != NULL) {
-               if (git_config_add_file_ondisk(cfg, global_config_path, 2) < 0)
+               if (git_config_add_file_ondisk(cfg, global_config_path, 3) < 0)
+                       goto on_error;
+       }
+
+       if (xdr_config_path != NULL) {
+               if (git_config_add_file_ondisk(cfg, xdr_config_path, 3) < 0)
                        goto on_error;
        }
 
@@ -487,19 +493,23 @@ on_error:
 int git_repository_config__weakptr(git_config **out, git_repository *repo)
 {
        if (repo->_config == NULL) {
-               git_buf global_buf = GIT_BUF_INIT, system_buf = GIT_BUF_INIT;
+               git_buf global_buf = GIT_BUF_INIT, xdr_buf = GIT_BUF_INIT, system_buf = GIT_BUF_INIT;
                int res;
 
                const char *global_config_path = NULL;
+               const char *xdr_config_path = NULL;
                const char *system_config_path = NULL;
 
                if (git_config_find_global_r(&global_buf) == 0)
                        global_config_path = global_buf.ptr;
 
+               if (git_config_find_xdr_r(&xdr_buf) == 0)
+                       xdr_config_path = xdr_buf.ptr;
+
                if (git_config_find_system_r(&system_buf) == 0)
                        system_config_path = system_buf.ptr;
 
-               res = load_config(&repo->_config, repo, global_config_path, system_config_path);
+               res = load_config(&repo->_config, repo, global_config_path, xdr_config_path, system_config_path);
 
                git_buf_free(&global_buf);
                git_buf_free(&system_buf);