summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c10
-rw-r--r--src/config.h1
-rw-r--r--src/repository.c14
-rw-r--r--src/sysdir.c19
-rw-r--r--src/sysdir.h14
-rw-r--r--src/win32/findfile.c10
-rw-r--r--src/win32/findfile.h1
7 files changed, 64 insertions, 5 deletions
diff --git a/src/config.c b/src/config.c
index f0b2c3a61..f4d4cb2b9 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1086,6 +1086,12 @@ int git_config_find_system(git_buf *path)
return git_sysdir_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
}
+int git_config_find_programdata(git_buf *path)
+{
+ git_buf_sanitize(path);
+ return git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA);
+}
+
int git_config__global_location(git_buf *buf)
{
const git_buf *paths;
@@ -1133,6 +1139,10 @@ int git_config_open_default(git_config **out)
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_SYSTEM, 0);
+ if (!error && !git_config_find_programdata(&buf))
+ error = git_config_add_file_ondisk(cfg, buf.ptr,
+ GIT_CONFIG_LEVEL_PROGRAMDATA, 0);
+
git_buf_free(&buf);
if (error) {
diff --git a/src/config.h b/src/config.h
index ba745331a..00c12b50d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -12,6 +12,7 @@
#include "vector.h"
#include "repository.h"
+#define GIT_CONFIG_FILENAME_PROGRAMDATA "config"
#define GIT_CONFIG_FILENAME_SYSTEM "gitconfig"
#define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig"
#define GIT_CONFIG_FILENAME_XDG "config"
diff --git a/src/repository.c b/src/repository.c
index 77145cfc8..38d18693a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -585,7 +585,8 @@ static int load_config(
git_repository *repo,
const char *global_config_path,
const char *xdg_config_path,
- const char *system_config_path)
+ const char *system_config_path,
+ const char *programdata_path)
{
int error;
git_buf config_path = GIT_BUF_INIT;
@@ -626,6 +627,12 @@ static int load_config(
error != GIT_ENOTFOUND)
goto on_error;
+ if (programdata_path != NULL &&
+ (error = git_config_add_file_ondisk(
+ cfg, programdata_path, GIT_CONFIG_LEVEL_PROGRAMDATA, 0)) < 0 &&
+ error != GIT_ENOTFOUND)
+ goto on_error;
+
giterr_clear(); /* clear any lingering ENOTFOUND errors */
*out = cfg;
@@ -651,11 +658,13 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
git_buf global_buf = GIT_BUF_INIT;
git_buf xdg_buf = GIT_BUF_INIT;
git_buf system_buf = GIT_BUF_INIT;
+ git_buf programdata_buf = GIT_BUF_INIT;
git_config *config;
git_config_find_global(&global_buf);
git_config_find_xdg(&xdg_buf);
git_config_find_system(&system_buf);
+ git_config_find_programdata(&programdata_buf);
/* If there is no global file, open a backend for it anyway */
if (git_buf_len(&global_buf) == 0)
@@ -665,7 +674,8 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
&config, repo,
path_unless_empty(&global_buf),
path_unless_empty(&xdg_buf),
- path_unless_empty(&system_buf));
+ path_unless_empty(&system_buf),
+ path_unless_empty(&programdata_buf));
if (!error) {
GIT_REFCOUNT_OWN(config, repo);
diff --git a/src/sysdir.c b/src/sysdir.c
index 2795de491..bf53d830f 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -15,6 +15,16 @@
#include "win32/findfile.h"
#endif
+static int git_sysdir_guess_programdata_dirs(git_buf *out)
+{
+#ifdef GIT_WIN32
+ return git_win32__find_programdata_dirs(out);
+#else
+ git_buf_clear(out);
+ return 0;
+#endif
+}
+
static int git_sysdir_guess_system_dirs(git_buf *out)
{
#ifdef GIT_WIN32
@@ -76,12 +86,13 @@ static int git_sysdir_guess_template_dirs(git_buf *out)
typedef int (*git_sysdir_guess_cb)(git_buf *out);
static git_buf git_sysdir__dirs[GIT_SYSDIR__MAX] =
- { GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT };
+ { GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT };
static git_sysdir_guess_cb git_sysdir__dir_guess[GIT_SYSDIR__MAX] = {
git_sysdir_guess_system_dirs,
git_sysdir_guess_global_dirs,
git_sysdir_guess_xdg_dirs,
+ git_sysdir_guess_programdata_dirs,
git_sysdir_guess_template_dirs,
};
@@ -258,6 +269,12 @@ int git_sysdir_find_xdg_file(git_buf *path, const char *filename)
path, filename, GIT_SYSDIR_XDG, "global/xdg");
}
+int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
+{
+ return git_sysdir_find_in_dirlist(
+ path, filename, GIT_SYSDIR_PROGRAMDATA, "ProgramData");
+}
+
int git_sysdir_find_template_dir(git_buf *path)
{
return git_sysdir_find_in_dirlist(
diff --git a/src/sysdir.h b/src/sysdir.h
index f1bbf0bae..12874fc85 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -39,6 +39,15 @@ extern int git_sysdir_find_xdg_file(git_buf *path, const char *filename);
extern int git_sysdir_find_system_file(git_buf *path, const char *filename);
/**
+ * Find a "ProgramData" file (i.e. one in %PROGRAMDATA%)
+ *
+ * @param path buffer to write the full path into
+ * @param filename name of file to find in the ProgramData directory
+ * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
+ */
+extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename);
+
+/**
* Find template directory.
*
* @param path buffer to write the full path into
@@ -50,8 +59,9 @@ typedef enum {
GIT_SYSDIR_SYSTEM = 0,
GIT_SYSDIR_GLOBAL = 1,
GIT_SYSDIR_XDG = 2,
- GIT_SYSDIR_TEMPLATE = 3,
- GIT_SYSDIR__MAX = 4,
+ GIT_SYSDIR_PROGRAMDATA = 3,
+ GIT_SYSDIR_TEMPLATE = 4,
+ GIT_SYSDIR__MAX = 5,
} git_sysdir_t;
/**
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index de27dd060..58c22279e 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -215,3 +215,13 @@ int git_win32__find_xdg_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
+
+int git_win32__find_programdata_dirs(git_buf *out)
+{
+ static const wchar_t *programdata_tmpls[2] = {
+ L"%PROGRAMDATA%\\Git",
+ NULL,
+ };
+
+ return win32_find_existing_dirs(out, programdata_tmpls);
+}
diff --git a/src/win32/findfile.h b/src/win32/findfile.h
index a50319b9a..3d5fff439 100644
--- a/src/win32/findfile.h
+++ b/src/win32/findfile.h
@@ -11,6 +11,7 @@
extern int git_win32__find_system_dirs(git_buf *out, const wchar_t *subpath);
extern int git_win32__find_global_dirs(git_buf *out);
extern int git_win32__find_xdg_dirs(git_buf *out);
+extern int git_win32__find_programdata_dirs(git_buf *out);
#endif