Skip to content

Commit

Permalink
Merge pull request #104 from dscho/super-config
Browse files Browse the repository at this point in the history
Add support for %PROGRAMDATA%\Git\config

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed May 14, 2015
2 parents e1c2eb5 + e302b11 commit 9c9dc30
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../git-compat-util.h"
#include "win32.h"
#include <conio.h>
#include <shlobj.h>
#include <wchar.h>
#include "../strbuf.h"
#include "../run-command.h"
Expand Down Expand Up @@ -2378,3 +2379,20 @@ 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) {
wchar_t wbuffer[MAX_PATH];
if (SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL,
SHGFP_TYPE_CURRENT, wbuffer) != S_OK)
strbuf_addch(&windows_wide, '\0');
else {
char buffer[MAX_PATH];
xwcstoutf(buffer, wbuffer, sizeof(buffer));
strbuf_addf(&windows_wide, "%s\\Git\\config", buffer);
}
}
return *windows_wide.buf ? windows_wide.buf : NULL;
}
2 changes: 2 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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_config
#define git_super_config() NULL
#endif

#if defined(__HP_cc) && (__HP_cc >= 61000)
#define NORETURN __attribute__((noreturn))
#define NORETURN_PTR
Expand Down

0 comments on commit 9c9dc30

Please sign in to comment.