Skip to content

Commit 2550076

Browse files
committed
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 <[email protected]>
1 parent 7cee121 commit 2550076

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

compat/mingw.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,3 +2378,12 @@ void mingw_startup()
23782378
/* init length of current directory for handle_long_path */
23792379
current_directory_len = GetCurrentDirectoryW(0, NULL);
23802380
}
2381+
2382+
const char *windows_wide_config(void)
2383+
{
2384+
static struct strbuf windows_wide = STRBUF_INIT;
2385+
if (!windows_wide.len)
2386+
strbuf_addf(&windows_wide,
2387+
"%s\\Git\\config", getenv("PROGRAMDATA"));
2388+
return windows_wide.buf;
2389+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
392392
int mingw_offset_1st_component(const char *path);
393393
#define offset_1st_component mingw_offset_1st_component
394394
#define PATH_SEP ';'
395+
extern const char *windows_wide_config(void);
396+
#define git_super_config windows_wide_config
395397
#ifndef __MINGW64_VERSION_MAJOR
396398
#define PRIuMAX "I64u"
397399
#define PRId64 "I64d"

config.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,18 @@ int git_config_system(void)
12041204
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
12051205
{
12061206
int ret = 0, found = 0;
1207+
const char *super_config = git_super_config();
12071208
char *xdg_config = NULL;
12081209
char *user_config = NULL;
12091210

12101211
home_config_paths(&user_config, &xdg_config, "config");
12111212

1213+
if (super_config && git_config_system() &&
1214+
!access(super_config, R_OK)) {
1215+
ret += git_config_from_file(fn, super_config, data);
1216+
found += 1;
1217+
}
1218+
12121219
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
12131220
ret += git_config_from_file(fn, git_etc_gitconfig(),
12141221
data);

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ static inline char *git_find_last_dir_sep(const char *path)
307307
#define find_last_dir_sep git_find_last_dir_sep
308308
#endif
309309

310+
#ifndef git_super_gitconfig
311+
#define git_super_gitconfig NULL
312+
#endif
313+
310314
#if defined(__HP_cc) && (__HP_cc >= 61000)
311315
#define NORETURN __attribute__((noreturn))
312316
#define NORETURN_PTR

0 commit comments

Comments
 (0)