Refactor list of of repo-local env vars
Move the list of GIT_* environment variables that are local to a repository into a static list in environment.c, as it is also useful elsewhere. Also add the missing GIT_CONFIG variable to the list. Make it easy to use the list both by NULL-termination and by size; the latter (excluding the terminating NULL) is stored in the local_repo_env_size define. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Feb 25, 2010 at 00:34 UTC
48a7c1c49d675fa37b609b499dd9e27439ec7f51
3 files changed
+28
-12
cache.h
+9
@@ -388,6 +388,15 @@ static inline enum object_type object_type(unsigned int mode)
388
#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
389
#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
390
391
+/*
392
+ * Repository-local GIT_* environment variables
393
+ * The array is NULL-terminated to simplify its usage in contexts such
394
+ * environment creation or simple walk of the list.
395
+ * The number of non-NULL entries is available as a macro.
396
+ */
397
+#define LOCAL_REPO_ENV_SIZE 8
398
+extern const char *const local_repo_env[LOCAL_REPO_ENV_SIZE + 1];
399
+
400
extern int is_bare_repository_cfg;
401
extern int is_bare_repository(void);
402
extern int is_inside_git_dir(void);
connect.c
+2
-12
@@ -607,18 +607,8 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
607
*arg++ = host;
608
}
609
else {
610
- /* remove these from the environment */
611
- const char *env[] = {
612
- ALTERNATE_DB_ENVIRONMENT,
613
- DB_ENVIRONMENT,
614
- GIT_DIR_ENVIRONMENT,
615
- GIT_WORK_TREE_ENVIRONMENT,
616
- GRAFT_ENVIRONMENT,
617
- INDEX_ENVIRONMENT,
618
- NO_REPLACE_OBJECTS_ENVIRONMENT,
619
- NULL
620
- };
621
- conn->env = env;
610
+ /* remove repo-local variables from the environment */
611
+ conn->env = local_repo_env;
612
conn->use_shell = 1;
613
}
614
*arg++ = cmd.buf;
environment.c
+17
@@ -63,6 +63,23 @@ static char *work_tree;
63
static const char *git_dir;
64
static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
65
66
+/*
67
+ * Repository-local GIT_* environment variables
68
+ * Remember to update local_repo_env_size in cache.h when
69
+ * the size of the list changes
70
+ */
71
+const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
72
+ ALTERNATE_DB_ENVIRONMENT,
73
+ CONFIG_ENVIRONMENT,
74
+ DB_ENVIRONMENT,
75
+ GIT_DIR_ENVIRONMENT,
76
+ GIT_WORK_TREE_ENVIRONMENT,
77
+ GRAFT_ENVIRONMENT,
78
+ INDEX_ENVIRONMENT,
79
+ NO_REPLACE_OBJECTS_ENVIRONMENT,
80
+ NULL
81
+};
82
+
83
static void setup_git_env(void)
84
{
85
git_dir = getenv(GIT_DIR_ENVIRONMENT);