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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-04-22 14:47:27 +01:00
parent 16685c2d7a
commit 297386b227
4 changed files with 22 additions and 0 deletions

View File

@@ -2128,3 +2128,12 @@ void mingw_startup()
/* initialize Unicode console */
winansi_init();
}
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;
}

View File

@@ -359,6 +359,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
#define PRIuMAX "I64u"
#define PRId64 "I64d"

View File

@@ -1185,11 +1185,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);

View File

@@ -301,6 +301,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