@matheusbsbs / matheus-bagliano / commits / dc87183189
Fork 0

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>

Daniel Barkalow committed Jun 30, 2008 at 03:37 UTC dc87183189b54441e315d35d48983d80ab085299
5 files changed +33 -45
Documentation/RelNotes-1.6.0.txt
+5
@@ -21,6 +21,11 @@ scripts to use "git xyzzy" form, as we will stop installing
21 Source changes needed for porting to MinGW environment are now all in the
22 main git.git codebase.
23
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 +
29
30 Updates since v1.5.6
31 --------------------
Documentation/git-config.txt
-9
@@ -191,11 +191,6 @@ variables. The '--global' and the '--system' options will limit the file used
191 to the global or system-wide file respectively. The GIT_CONFIG environment
192 variable has a similar effect, but you can specify any filename you want.
193
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 -
194
195 ENVIRONMENT
196 -----------
@@ -205,10 +200,6 @@ GIT_CONFIG::
200 Using the "--global" option forces this to ~/.gitconfig. Using the
201 "--system" option forces this to $(prefix)/etc/gitconfig.
202
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 -
203 See also <<FILES>>.
204
205
builtin-config.c
+7 -8
@@ -81,12 +81,10 @@ static int get_value(const char* key_, const char* regex_)
81 char *global = NULL, *repo_config = NULL;
82 const char *system_wide = NULL, *local;
83
84 - local = getenv(CONFIG_ENVIRONMENT);
84 + local = config_exclusive_filename;
85 if (!local) {
86 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"));
88 if (git_config_global() && home)
89 global = xstrdup(mkpath("%s/.gitconfig", home));
90 if (git_config_system())
@@ -289,6 +287,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
287 char* value;
288 const char *file = setup_git_directory_gently(&nongit);
289
290 + config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
291 +
292 while (1 < argc) {
293 if (!strcmp(argv[1], "--int"))
294 type = T_INT;
@@ -309,14 +309,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
309 char *home = getenv("HOME");
310 if (home) {
311 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;
313 } else {
314 die("$HOME not set");
315 }
316 }
317 else if (!strcmp(argv[1], "--system"))
319 - setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1);
318 + config_exclusive_filename = git_etc_gitconfig();
319 else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) {
320 if (argc < 3)
321 usage(git_config_set_usage);
@@ -325,7 +324,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
324 argv[2]);
325 else
326 file = argv[2];
328 - setenv(CONFIG_ENVIRONMENT, file, 1);
327 + config_exclusive_filename = file;
328 argc--;
329 argv++;
330 }
cache.h
+1 -1
@@ -298,7 +298,6 @@ static inline enum object_type object_type(unsigned int mode)
298 #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
299 #define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
300 #define CONFIG_ENVIRONMENT "GIT_CONFIG"
301 -#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
301 #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
302 #define GITATTRIBUTES_FILE ".gitattributes"
303 #define INFOATTRIBUTES_FILE "info/attributes"
@@ -743,6 +742,7 @@ extern int check_repository_format_version(const char *var, const char *value, v
742 extern int git_config_system(void);
743 extern int git_config_global(void);
744 extern int config_error_nonbool(const char *);
745 +extern const char *config_exclusive_filename;
746
747 #define MAX_GITNAME (1000)
748 extern char git_default_email[MAX_GITNAME];
config.c
+20 -27
@@ -16,6 +16,8 @@ static int config_linenr;
16 static int config_file_eof;
17 static int zlib_compression_seen;
18
19 +const char *config_exclusive_filename = NULL;
20 +
21 static int get_next_char(void)
22 {
23 int c;
@@ -611,31 +613,28 @@ int git_config(config_fn_t fn, void *data)
613 {
614 int ret = 0;
615 char *repo_config = NULL;
614 - const char *home = NULL, *filename;
616 + const char *home = NULL;
617
618 /* $GIT_CONFIG makes git read _only_ the given config file,
619 * $GIT_CONFIG_LOCAL will make it process it in addition to the
620 * global config file, the same way it would the per-repository
621 * 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);
627
628 + home = getenv("HOME");
629 if (git_config_global() && home) {
630 char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
631 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);
633 free(user_config);
634 }
635
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);
638 free(repo_config);
639 return ret;
640 }
@@ -873,13 +872,10 @@ int git_config_set_multivar(const char* key, const char* value,
872 struct lock_file *lock = NULL;
873 const char* last_dot = strrchr(key, '.');
874
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"));
879
880 /*
881 * 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)
1132 int out_fd;
1133 char buf[1024];
1134
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"));
1139 out_fd = hold_lock_file_for_update(lock, config_filename, 0);
1140 if (out_fd < 0) {
1141 ret = error("could not lock config file %s", config_filename);