Skip to content

Commit 48a7c1c

Browse files
Oblomovgitster
authored andcommitted
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>
1 parent e923eae commit 48a7c1c

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

cache.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ static inline enum object_type object_type(unsigned int mode)
388388
#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
389389
#define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
390390

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+
391400
extern int is_bare_repository_cfg;
392401
extern int is_bare_repository(void);
393402
extern int is_inside_git_dir(void);

connect.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -607,18 +607,8 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
607607
*arg++ = host;
608608
}
609609
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;
622612
conn->use_shell = 1;
623613
}
624614
*arg++ = cmd.buf;

environment.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ static char *work_tree;
6363
static const char *git_dir;
6464
static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
6565

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+
6683
static void setup_git_env(void)
6784
{
6885
git_dir = getenv(GIT_DIR_ENVIRONMENT);

0 commit comments

Comments
 (0)