From 255007634fca56ab0c7020b308c280f24ee198c4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 22 Apr 2015 14:47:27 +0100 Subject: [PATCH 1/2] Windows: use %PROGRAMDATA%\Git\config as Windows-wide configuration Between the libgit2 and the Git for Windows project, there has been a discussion how we could share Git configuration to avoid duplication (or worse: skew). Earlier, libgit2 was nice enough to just re-use Git for Windows' C:\Program Files (x86)\Git\etc\gitconfig but with the upcoming Git for Windows 2.x, there would be more paths to search, as we will have 64-bit and 32-bit versions, and the corresponding config files will be in %PROGRAMFILES%\Git\mingw64\etc and ...\mingw32\etc, respectively. Therefore we came to a consensus to use %PROGRAMDATA%\Git as the location for Git-specific files that are of wider interest than just Git for Windows. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 9 +++++++++ compat/mingw.h | 2 ++ config.c | 7 +++++++ git-compat-util.h | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index ae937a7bb45384..043b847ec1d93e 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2378,3 +2378,12 @@ void mingw_startup() /* init length of current directory for handle_long_path */ current_directory_len = GetCurrentDirectoryW(0, NULL); } + +const char *windows_wide_config(void) +{ + static struct strbuf windows_wide = STRBUF_INIT; + if (!windows_wide.len) + strbuf_addf(&windows_wide, + "%s\\Git\\config", getenv("PROGRAMDATA")); + return windows_wide.buf; +} diff --git a/compat/mingw.h b/compat/mingw.h index a628b2d48dfd1d..d2f5bc8192c20e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -392,6 +392,8 @@ static inline char *mingw_find_last_dir_sep(const char *path) int mingw_offset_1st_component(const char *path); #define offset_1st_component mingw_offset_1st_component #define PATH_SEP ';' +extern const char *windows_wide_config(void); +#define git_super_config windows_wide_config #ifndef __MINGW64_VERSION_MAJOR #define PRIuMAX "I64u" #define PRId64 "I64d" diff --git a/config.c b/config.c index 423be73c59869e..90829c010961aa 100644 --- a/config.c +++ b/config.c @@ -1204,11 +1204,18 @@ int git_config_system(void) int git_config_early(config_fn_t fn, void *data, const char *repo_config) { int ret = 0, found = 0; + const char *super_config = git_super_config(); char *xdg_config = NULL; char *user_config = NULL; home_config_paths(&user_config, &xdg_config, "config"); + if (super_config && git_config_system() && + !access(super_config, R_OK)) { + ret += git_config_from_file(fn, super_config, data); + found += 1; + } + if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) { ret += git_config_from_file(fn, git_etc_gitconfig(), data); diff --git a/git-compat-util.h b/git-compat-util.h index 89f86f50eb4cc5..52f4a13a7a3853 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -307,6 +307,10 @@ static inline char *git_find_last_dir_sep(const char *path) #define find_last_dir_sep git_find_last_dir_sep #endif +#ifndef git_super_gitconfig +#define git_super_gitconfig NULL +#endif + #if defined(__HP_cc) && (__HP_cc >= 61000) #define NORETURN __attribute__((noreturn)) #define NORETURN_PTR From c963b8eef67f55cbc4264b0f2128bfc9dde637a7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 22 Apr 2015 14:54:58 +0100 Subject: [PATCH 2/2] Document the Windows-wide config file Signed-off-by: Johannes Schindelin --- Documentation/config.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 549d0c14279592..b45eec0fedcf15 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -6,7 +6,9 @@ the Git commands' behavior. The `.git/config` file in each repository is used to store the configuration for that repository, and `$HOME/.gitconfig` is used to store a per-user configuration as fallback values for the `.git/config` file. The file `/etc/gitconfig` -can be used to store a system-wide default configuration. +can be used to store a system-wide default configuration. On Windows, +configuration can also be stored in `C:\ProgramData\Git\config`; This +file will be used also by libgit2-based software. The configuration variables are used by both the Git plumbing and the porcelains. The variables are divided into sections, wherein