Skip to content

Commit dc87183

Browse files
iabervongitster
authored andcommitted
Only use GIT_CONFIG in "git config", not other programs
For everything other than using "git config" to read or write a git-style config file that isn't the current repo's config file, GIT_CONFIG was actively detrimental. Rather than argue over which programs are important enough to have work anyway, just fix all of them at the root. Also removes GIT_LOCAL_CONFIG, which would only be useful for programs that do want to use global git-specific config, but not the repo's own git-specific config, and want to use some other, presumably git-specific config. Despite being documented, I can't find any sign that it was ever used. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6603799 commit dc87183

File tree

5 files changed

+33
-45
lines changed

5 files changed

+33
-45
lines changed

Documentation/RelNotes-1.6.0.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ scripts to use "git xyzzy" form, as we will stop installing
2121
Source changes needed for porting to MinGW environment are now all in the
2222
main git.git codebase.
2323

24+
GIT_CONFIG, which was only documented as affecting "git config", but
25+
actually affected all git commands, now only affects "git config".
26+
GIT_LOCAL_CONFIG, also only documented as affecting "git config" and
27+
not different from GIT_CONFIG in a useful way, is removed.
28+
2429

2530
Updates since v1.5.6
2631
--------------------

Documentation/git-config.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ variables. The '--global' and the '--system' options will limit the file used
191191
to the global or system-wide file respectively. The GIT_CONFIG environment
192192
variable has a similar effect, but you can specify any filename you want.
193193

194-
The GIT_CONFIG_LOCAL environment variable on the other hand only changes
195-
the name used instead of the repository configuration file. The global and
196-
the system-wide configuration files will still be read. (For writing options
197-
this will obviously result in the same behavior as using GIT_CONFIG.)
198-
199194

200195
ENVIRONMENT
201196
-----------
@@ -205,10 +200,6 @@ GIT_CONFIG::
205200
Using the "--global" option forces this to ~/.gitconfig. Using the
206201
"--system" option forces this to $(prefix)/etc/gitconfig.
207202

208-
GIT_CONFIG_LOCAL::
209-
Take the configuration from the given file instead if .git/config.
210-
Still read the global and the system-wide configuration files, though.
211-
212203
See also <<FILES>>.
213204

214205

builtin-config.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ static int get_value(const char* key_, const char* regex_)
8181
char *global = NULL, *repo_config = NULL;
8282
const char *system_wide = NULL, *local;
8383

84-
local = getenv(CONFIG_ENVIRONMENT);
84+
local = config_exclusive_filename;
8585
if (!local) {
8686
const char *home = getenv("HOME");
87-
local = getenv(CONFIG_LOCAL_ENVIRONMENT);
88-
if (!local)
89-
local = repo_config = xstrdup(git_path("config"));
87+
local = repo_config = xstrdup(git_path("config"));
9088
if (git_config_global() && home)
9189
global = xstrdup(mkpath("%s/.gitconfig", home));
9290
if (git_config_system())
@@ -289,6 +287,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
289287
char* value;
290288
const char *file = setup_git_directory_gently(&nongit);
291289

290+
config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
291+
292292
while (1 < argc) {
293293
if (!strcmp(argv[1], "--int"))
294294
type = T_INT;
@@ -309,14 +309,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
309309
char *home = getenv("HOME");
310310
if (home) {
311311
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
312-
setenv(CONFIG_ENVIRONMENT, user_config, 1);
313-
free(user_config);
312+
config_exclusive_filename = user_config;
314313
} else {
315314
die("$HOME not set");
316315
}
317316
}
318317
else if (!strcmp(argv[1], "--system"))
319-
setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1);
318+
config_exclusive_filename = git_etc_gitconfig();
320319
else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
321320
if (argc < 3)
322321
usage(git_config_set_usage);
@@ -325,7 +324,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
325324
argv[2]);
326325
else
327326
file = argv[2];
328-
setenv(CONFIG_ENVIRONMENT, file, 1);
327+
config_exclusive_filename = file;
329328
argc--;
330329
argv++;
331330
}

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ static inline enum object_type object_type(unsigned int mode)
298298
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
299299
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
300300
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
301-
#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
302301
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
303302
#define GITATTRIBUTES_FILE ".gitattributes"
304303
#define INFOATTRIBUTES_FILE "info/attributes"
@@ -743,6 +742,7 @@ extern int check_repository_format_version(const char *var, const char *value, v
743742
extern int git_config_system(void);
744743
extern int git_config_global(void);
745744
extern int config_error_nonbool(const char *);
745+
extern const char *config_exclusive_filename;
746746

747747
#define MAX_GITNAME (1000)
748748
extern char git_default_email[MAX_GITNAME];

config.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static int config_linenr;
1616
static int config_file_eof;
1717
static int zlib_compression_seen;
1818

19+
const char *config_exclusive_filename = NULL;
20+
1921
static int get_next_char(void)
2022
{
2123
int c;
@@ -611,31 +613,28 @@ int git_config(config_fn_t fn, void *data)
611613
{
612614
int ret = 0;
613615
char *repo_config = NULL;
614-
const char *home = NULL, *filename;
616+
const char *home = NULL;
615617

616618
/* $GIT_CONFIG makes git read _only_ the given config file,
617619
* $GIT_CONFIG_LOCAL will make it process it in addition to the
618620
* global config file, the same way it would the per-repository
619621
* config file otherwise. */
620-
filename = getenv(CONFIG_ENVIRONMENT);
621-
if (!filename) {
622-
if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
623-
ret += git_config_from_file(fn, git_etc_gitconfig(),
624-
data);
625-
home = getenv("HOME");
626-
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
627-
if (!filename)
628-
filename = repo_config = xstrdup(git_path("config"));
629-
}
622+
if (config_exclusive_filename)
623+
return git_config_from_file(fn, config_exclusive_filename, data);
624+
if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
625+
ret += git_config_from_file(fn, git_etc_gitconfig(),
626+
data);
630627

628+
home = getenv("HOME");
631629
if (git_config_global() && home) {
632630
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
633631
if (!access(user_config, R_OK))
634-
ret = git_config_from_file(fn, user_config, data);
632+
ret += git_config_from_file(fn, user_config, data);
635633
free(user_config);
636634
}
637635

638-
ret += git_config_from_file(fn, filename, data);
636+
repo_config = xstrdup(git_path("config"));
637+
ret += git_config_from_file(fn, repo_config, data);
639638
free(repo_config);
640639
return ret;
641640
}
@@ -873,13 +872,10 @@ int git_config_set_multivar(const char* key, const char* value,
873872
struct lock_file *lock = NULL;
874873
const char* last_dot = strrchr(key, '.');
875874

876-
config_filename = getenv(CONFIG_ENVIRONMENT);
877-
if (!config_filename) {
878-
config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
879-
if (!config_filename)
880-
config_filename = git_path("config");
881-
}
882-
config_filename = xstrdup(config_filename);
875+
if (config_exclusive_filename)
876+
config_filename = xstrdup(config_exclusive_filename);
877+
else
878+
config_filename = xstrdup(git_path("config"));
883879

884880
/*
885881
* Since "key" actually contains the section name and the real
@@ -1136,13 +1132,10 @@ int git_config_rename_section(const char *old_name, const char *new_name)
11361132
int out_fd;
11371133
char buf[1024];
11381134

1139-
config_filename = getenv(CONFIG_ENVIRONMENT);
1140-
if (!config_filename) {
1141-
config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
1142-
if (!config_filename)
1143-
config_filename = git_path("config");
1144-
}
1145-
config_filename = xstrdup(config_filename);
1135+
if (config_exclusive_filename)
1136+
config_filename = xstrdup(config_exclusive_filename);
1137+
else
1138+
config_filename = xstrdup(git_path("config"));
11461139
out_fd = hold_lock_file_for_update(lock, config_filename, 0);
11471140
if (out_fd < 0) {
11481141
ret = error("could not lock config file %s", config_filename);

0 commit comments

Comments
 (0)