Use preprocessor constants for environment variable names.
We broke the discipline Linus set up to allow compiler help us avoid typos in environment names in the early days of git over time. This defines a handful preprocessor constants for environment variable names used in relatively core parts of the system. I've left out variable names specific to subsystems such as HTTP and SSL as I do not think they are big problems. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 19, 2006 at 01:28 UTC
d4ebc36c5ee964592303c59260417b758d024c31
6 files changed
+16
-12
builtin-init-db.c
+1
-1
@@ -125,7 +125,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
125
DIR *dir;
126
127
if (!template_dir) {
128
- template_dir = getenv("GIT_TEMPLATE_DIR");
128
+ template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
129
if (!template_dir)
130
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
131
}
builtin-repo-config.c
+2
-2
@@ -67,10 +67,10 @@ static int get_value(const char* key_, const char* regex_)
67
char *global = NULL, *repo_config = NULL;
68
const char *local;
69
70
- local = getenv("GIT_CONFIG");
70
+ local = getenv(CONFIG_ENVIRONMENT);
71
if (!local) {
72
const char *home = getenv("HOME");
73
- local = getenv("GIT_CONFIG_LOCAL");
73
+ local = getenv(CONFIG_LOCAL_ENVIRONMENT);
74
if (!local)
75
local = repo_config = xstrdup(git_path("config"));
76
if (home)
cache.h
+4
@@ -122,6 +122,10 @@ extern int cache_errno;
122
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
123
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
124
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
125
+#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
126
+#define CONFIG_ENVIRONMENT "GIT_CONFIG"
127
+#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
128
+#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
129
130
extern int is_bare_git_dir(const char *dir);
131
extern const char *get_git_dir(void);
config.c
+6
-6
@@ -350,10 +350,10 @@ int git_config(config_fn_t fn)
350
* $GIT_CONFIG_LOCAL will make it process it in addition to the
351
* global config file, the same way it would the per-repository
352
* config file otherwise. */
353
- filename = getenv("GIT_CONFIG");
353
+ filename = getenv(CONFIG_ENVIRONMENT);
354
if (!filename) {
355
home = getenv("HOME");
356
- filename = getenv("GIT_CONFIG_LOCAL");
356
+ filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
357
if (!filename)
358
filename = repo_config = xstrdup(git_path("config"));
359
}
@@ -544,9 +544,9 @@ int git_config_set_multivar(const char* key, const char* value,
544
char* lock_file;
545
const char* last_dot = strrchr(key, '.');
546
547
- config_filename = getenv("GIT_CONFIG");
547
+ config_filename = getenv(CONFIG_ENVIRONMENT);
548
if (!config_filename) {
549
- config_filename = getenv("GIT_CONFIG_LOCAL");
549
+ config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
550
if (!config_filename)
551
config_filename = git_path("config");
552
}
@@ -754,9 +754,9 @@ int git_config_rename_section(const char *old_name, const char *new_name)
754
int out_fd;
755
char buf[1024];
756
757
- config_filename = getenv("GIT_CONFIG");
757
+ config_filename = getenv(CONFIG_ENVIRONMENT);
758
if (!config_filename) {
759
- config_filename = getenv("GIT_CONFIG_LOCAL");
759
+ config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
760
if (!config_filename)
761
config_filename = git_path("config");
762
}
exec_cmd.c
+2
-2
@@ -21,7 +21,7 @@ const char *git_exec_path(void)
21
if (current_exec_path)
22
return current_exec_path;
23
24
- env = getenv("GIT_EXEC_PATH");
24
+ env = getenv(EXEC_PATH_ENVIRONMENT);
25
if (env && *env) {
26
return env;
27
}
@@ -35,7 +35,7 @@ int execv_git_cmd(const char **argv)
35
char git_command[PATH_MAX + 1];
36
int i;
37
const char *paths[] = { current_exec_path,
38
- getenv("GIT_EXEC_PATH"),
38
+ getenv(EXEC_PATH_ENVIRONMENT),
39
builtin_exec_path };
40
41
for (i = 0; i < ARRAY_SIZE(paths); ++i) {
merge-recursive.c
+1
-1
@@ -1279,7 +1279,7 @@ int main(int argc, char *argv[])
1279
struct commit *result, *h1, *h2;
1280
1281
git_config(git_default_config); /* core.filemode */
1282
- original_index_file = getenv("GIT_INDEX_FILE");
1282
+ original_index_file = getenv(INDEX_ENVIRONMENT);
1283
1284
if (!original_index_file)
1285
original_index_file = xstrdup(git_path("index"));