config: read system-wide defaults from /etc/gitconfig

The settings in /etc/gitconfig can be overridden in ~/.gitconfig,
which in turn can be overridden in .git/config.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Johannes Schindelin 2007-02-14 12:48:14 +01:00 коммит произвёл Junio C Hamano
Родитель 437b1b20df
Коммит 32043c9f8c
4 изменённых файлов: 20 добавлений и 5 удалений

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

@ -5,7 +5,8 @@ The git configuration file contains a number of variables that affect
the git command's behavior. `.git/config` file for each repository the git command's behavior. `.git/config` file for each repository
is used to store the information for that repository, and is used to store the information for that repository, and
`$HOME/.gitconfig` is used to store per user information to give `$HOME/.gitconfig` is used to store per user information to give
fallback values for `.git/config` file. fallback values for `.git/config` file. The file `/etc/gitconfig`
can be used to store system-wide defaults.
They can be used by both the git plumbing They can be used by both the git plumbing
and the porcelains. The variables are divided into sections, where and the porcelains. The variables are divided into sections, where

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

@ -124,6 +124,7 @@ prefix = $(HOME)
bindir = $(prefix)/bin bindir = $(prefix)/bin
gitexecdir = $(bindir) gitexecdir = $(bindir)
template_dir = $(prefix)/share/git-core/templates/ template_dir = $(prefix)/share/git-core/templates/
ETC_GITCONFIG = $(prefix)/etc/gitconfig
# DESTDIR= # DESTDIR=
# default configuration for gitweb # default configuration for gitweb
@ -584,6 +585,7 @@ endif
# Shell quote (do not use $(call) to accommodate ancient setups); # Shell quote (do not use $(call) to accommodate ancient setups);
SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
bindir_SQ = $(subst ','\'',$(bindir)) bindir_SQ = $(subst ','\'',$(bindir))
@ -596,7 +598,8 @@ PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
LIBS = $(GITLIBS) $(EXTLIBS) LIBS = $(GITLIBS) $(EXTLIBS)
BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS) BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
LIB_OBJS += $(COMPAT_OBJS) LIB_OBJS += $(COMPAT_OBJS)
ALL_CFLAGS += $(BASIC_CFLAGS) ALL_CFLAGS += $(BASIC_CFLAGS)

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

@ -64,7 +64,7 @@ static int get_value(const char* key_, const char* regex_)
int ret = -1; int ret = -1;
char *tl; char *tl;
char *global = NULL, *repo_config = NULL; char *global = NULL, *repo_config = NULL;
const char *local; const char *system_wide = NULL, *local;
local = getenv(CONFIG_ENVIRONMENT); local = getenv(CONFIG_ENVIRONMENT);
if (!local) { if (!local) {
@ -74,6 +74,7 @@ static int get_value(const char* key_, const char* regex_)
local = repo_config = xstrdup(git_path("config")); local = repo_config = xstrdup(git_path("config"));
if (home) if (home)
global = xstrdup(mkpath("%s/.gitconfig", home)); global = xstrdup(mkpath("%s/.gitconfig", home));
system_wide = ETC_GITCONFIG;
} }
key = xstrdup(key_); key = xstrdup(key_);
@ -103,11 +104,15 @@ static int get_value(const char* key_, const char* regex_)
} }
} }
if (do_all && system_wide)
git_config_from_file(show_config, system_wide);
if (do_all && global) if (do_all && global)
git_config_from_file(show_config, global); git_config_from_file(show_config, global);
git_config_from_file(show_config, local); git_config_from_file(show_config, local);
if (!do_all && !seen && global) if (!do_all && !seen && global)
git_config_from_file(show_config, global); git_config_from_file(show_config, global);
if (!do_all && !seen && system_wide)
git_config_from_file(show_config, system_wide);
free(key); free(key);
if (regexp) { if (regexp) {
@ -147,7 +152,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
} else { } else {
die("$HOME not set"); die("$HOME not set");
} }
} else if (!strcmp(argv[1], "--rename-section")) { }
else if (!strcmp(argv[1], "--system"))
setenv("GIT_CONFIG", ETC_GITCONFIG, 1);
else if (!strcmp(argv[1], "--rename-section")) {
int ret; int ret;
if (argc != 4) if (argc != 4)
usage(git_config_set_usage); usage(git_config_set_usage);
@ -159,7 +167,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
return 1; return 1;
} }
return 0; return 0;
} else }
else
break; break;
argc--; argc--;
argv++; argv++;

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

@ -383,6 +383,8 @@ int git_config(config_fn_t fn)
* config file otherwise. */ * config file otherwise. */
filename = getenv(CONFIG_ENVIRONMENT); filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) { if (!filename) {
if (!access(ETC_GITCONFIG, R_OK))
ret += git_config_from_file(fn, ETC_GITCONFIG);
home = getenv("HOME"); home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT); filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!filename) if (!filename)