Merge branch 'program-data-config'

This branch introduces support for reading the "Windows-wide" Git
configuration from `%PROGRAMDATA%\Git\config`. As these settings are
intended to be shared between *all* Git-related software, that config
file takes an even lower precedence than `$(prefix)/etc/gitconfig`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2018-06-08 13:42:33 +02:00
Родитель 20af8cb4bb 76a1f9abfa
Коммит d6e4a926bf
7 изменённых файлов: 43 добавлений и 7 удалений

Просмотреть файл

@ -7,7 +7,9 @@ the Git commands' behavior. The files `.git/config` and optionally
repository are 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

Просмотреть файл

@ -272,8 +272,16 @@ FILES
If not set explicitly with `--file`, there are four files where
'git config' will search for configuration options:
$PROGRAMDATA/Git/config::
(Windows-only) System-wide configuration file shared with other Git
implementations. Typically `$PROGRAMDATA` points to `C:\ProgramData`.
$(prefix)/etc/gitconfig::
System-wide configuration file.
(Windows-only) This file contains only the settings which are
specific for this installation of Git for Windows and which should
not be shared with other Git implementations like JGit, libgit2.
`--system` will select this file.
$XDG_CONFIG_HOME/git/config::
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set

Просмотреть файл

@ -566,7 +566,8 @@ for further details.
`GIT_CONFIG_NOSYSTEM`::
Whether to skip reading settings from the system-wide
`$(prefix)/etc/gitconfig` file. This environment variable can
`$(prefix)/etc/gitconfig` file (and on Windows, also from the
`%PROGRAMDATA%\Git\config` file). This environment variable can
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
predictable environment for a picky script, or you can set it
temporarily to avoid using a buggy `/etc/gitconfig` file while

Просмотреть файл

@ -2540,3 +2540,17 @@ int uname(struct utsname *buf)
"%u", (v >> 16) & 0x7fff);
return 0;
}
const char *program_data_config(void)
{
static struct strbuf path = STRBUF_INIT;
static unsigned initialized;
if (!initialized) {
const char *env = mingw_getenv("PROGRAMDATA");
if (env)
strbuf_addf(&path, "%s/Git/config", env);
initialized = 1;
}
return *path.buf ? path.buf : NULL;
}

Просмотреть файл

@ -445,6 +445,8 @@ static inline void convert_slashes(char *path)
#define PATH_SEP ';'
extern char *mingw_query_user_email(void);
#define query_user_email mingw_query_user_email
extern const char *program_data_config(void);
#define git_program_data_config program_data_config
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
#define PRIuMAX "I64u"
#define PRId64 "I64d"

Просмотреть файл

@ -1676,11 +1676,16 @@ static int do_git_config_sequence(const struct config_options *opts,
repo_config = NULL;
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,
opts->system_gently ?
ACCESS_EACCES_OK : 0))
ret += git_config_from_file(fn, git_etc_gitconfig(),
data);
if (git_config_system()) {
int flags = opts->system_gently ? ACCESS_EACCES_OK : 0;
const char *program_data = git_program_data_config();
const char *etc = git_etc_gitconfig();
if (program_data && !access_or_die(program_data, R_OK, flags))
ret += git_config_from_file(fn, program_data, data);
if (!access_or_die(etc, R_OK, flags))
ret += git_config_from_file(fn, etc, data);
}
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))

Просмотреть файл

@ -421,6 +421,10 @@ static inline char *git_find_last_dir_sep(const char *path)
#endif
#endif
#ifndef git_program_data_config
#define git_program_data_config() NULL
#endif
#if defined(__HP_cc) && (__HP_cc >= 61000)
#define NORETURN __attribute__((noreturn))
#define NORETURN_PTR