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>
This commit is contained in:
parent
75c384efb5
commit
d4ebc36c5e
@ -125,7 +125,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
|
|||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
if (!template_dir) {
|
if (!template_dir) {
|
||||||
template_dir = getenv("GIT_TEMPLATE_DIR");
|
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
|
||||||
if (!template_dir)
|
if (!template_dir)
|
||||||
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
|
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ static int get_value(const char* key_, const char* regex_)
|
|||||||
char *global = NULL, *repo_config = NULL;
|
char *global = NULL, *repo_config = NULL;
|
||||||
const char *local;
|
const char *local;
|
||||||
|
|
||||||
local = getenv("GIT_CONFIG");
|
local = getenv(CONFIG_ENVIRONMENT);
|
||||||
if (!local) {
|
if (!local) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
local = getenv("GIT_CONFIG_LOCAL");
|
local = getenv(CONFIG_LOCAL_ENVIRONMENT);
|
||||||
if (!local)
|
if (!local)
|
||||||
local = repo_config = xstrdup(git_path("config"));
|
local = repo_config = xstrdup(git_path("config"));
|
||||||
if (home)
|
if (home)
|
||||||
|
4
cache.h
4
cache.h
@ -122,6 +122,10 @@ extern int cache_errno;
|
|||||||
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
|
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
|
||||||
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
|
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
|
||||||
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
|
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
|
||||||
|
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
|
||||||
|
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
|
||||||
|
#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"
|
||||||
|
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
|
||||||
|
|
||||||
extern int is_bare_git_dir(const char *dir);
|
extern int is_bare_git_dir(const char *dir);
|
||||||
extern const char *get_git_dir(void);
|
extern const char *get_git_dir(void);
|
||||||
|
12
config.c
12
config.c
@ -350,10 +350,10 @@ int git_config(config_fn_t fn)
|
|||||||
* $GIT_CONFIG_LOCAL will make it process it in addition to the
|
* $GIT_CONFIG_LOCAL will make it process it in addition to the
|
||||||
* global config file, the same way it would the per-repository
|
* global config file, the same way it would the per-repository
|
||||||
* config file otherwise. */
|
* config file otherwise. */
|
||||||
filename = getenv("GIT_CONFIG");
|
filename = getenv(CONFIG_ENVIRONMENT);
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
filename = getenv("GIT_CONFIG_LOCAL");
|
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
filename = repo_config = xstrdup(git_path("config"));
|
filename = repo_config = xstrdup(git_path("config"));
|
||||||
}
|
}
|
||||||
@ -544,9 +544,9 @@ int git_config_set_multivar(const char* key, const char* value,
|
|||||||
char* lock_file;
|
char* lock_file;
|
||||||
const char* last_dot = strrchr(key, '.');
|
const char* last_dot = strrchr(key, '.');
|
||||||
|
|
||||||
config_filename = getenv("GIT_CONFIG");
|
config_filename = getenv(CONFIG_ENVIRONMENT);
|
||||||
if (!config_filename) {
|
if (!config_filename) {
|
||||||
config_filename = getenv("GIT_CONFIG_LOCAL");
|
config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
|
||||||
if (!config_filename)
|
if (!config_filename)
|
||||||
config_filename = git_path("config");
|
config_filename = git_path("config");
|
||||||
}
|
}
|
||||||
@ -754,9 +754,9 @@ int git_config_rename_section(const char *old_name, const char *new_name)
|
|||||||
int out_fd;
|
int out_fd;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
config_filename = getenv("GIT_CONFIG");
|
config_filename = getenv(CONFIG_ENVIRONMENT);
|
||||||
if (!config_filename) {
|
if (!config_filename) {
|
||||||
config_filename = getenv("GIT_CONFIG_LOCAL");
|
config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
|
||||||
if (!config_filename)
|
if (!config_filename)
|
||||||
config_filename = git_path("config");
|
config_filename = git_path("config");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ const char *git_exec_path(void)
|
|||||||
if (current_exec_path)
|
if (current_exec_path)
|
||||||
return current_exec_path;
|
return current_exec_path;
|
||||||
|
|
||||||
env = getenv("GIT_EXEC_PATH");
|
env = getenv(EXEC_PATH_ENVIRONMENT);
|
||||||
if (env && *env) {
|
if (env && *env) {
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ int execv_git_cmd(const char **argv)
|
|||||||
char git_command[PATH_MAX + 1];
|
char git_command[PATH_MAX + 1];
|
||||||
int i;
|
int i;
|
||||||
const char *paths[] = { current_exec_path,
|
const char *paths[] = { current_exec_path,
|
||||||
getenv("GIT_EXEC_PATH"),
|
getenv(EXEC_PATH_ENVIRONMENT),
|
||||||
builtin_exec_path };
|
builtin_exec_path };
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(paths); ++i) {
|
for (i = 0; i < ARRAY_SIZE(paths); ++i) {
|
||||||
|
@ -1279,7 +1279,7 @@ int main(int argc, char *argv[])
|
|||||||
struct commit *result, *h1, *h2;
|
struct commit *result, *h1, *h2;
|
||||||
|
|
||||||
git_config(git_default_config); /* core.filemode */
|
git_config(git_default_config); /* core.filemode */
|
||||||
original_index_file = getenv("GIT_INDEX_FILE");
|
original_index_file = getenv(INDEX_ENVIRONMENT);
|
||||||
|
|
||||||
if (!original_index_file)
|
if (!original_index_file)
|
||||||
original_index_file = xstrdup(git_path("index"));
|
original_index_file = xstrdup(git_path("index"));
|
||||||
|
Loading…
Reference in New Issue
Block a user