Skip to content

Commit a6f7f9a

Browse files
peffgitster
authored andcommitted
environment: add GIT_PREFIX to local_repo_env
The GIT_PREFIX variable is set based on our location within the working tree. It should therefore be cleared whenever GIT_WORK_TREE is cleared. In practice, this doesn't cause any bugs, because none of the sub-programs we invoke with local_repo_env cleared actually care about GIT_PREFIX. But this is the right thing to do, and future proofs us against that assumption changing. While we're at it, let's define a GIT_PREFIX_ENVIRONMENT macro; this avoids repetition of the string literal, which can help catch any spelling mistakes in the code. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2163e5d commit a6f7f9a

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ static inline enum object_type object_type(unsigned int mode)
345345
#define GIT_DIR_ENVIRONMENT "GIT_DIR"
346346
#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
347347
#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
348+
#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
348349
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
349350
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
350351
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const char * const local_repo_env[] = {
8888
GRAFT_ENVIRONMENT,
8989
INDEX_ENVIRONMENT,
9090
NO_REPLACE_OBJECTS_ENVIRONMENT,
91+
GIT_PREFIX_ENVIRONMENT,
9192
NULL
9293
};
9394

setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
768768

769769
prefix = setup_git_directory_gently_1(nongit_ok);
770770
if (prefix)
771-
setenv("GIT_PREFIX", prefix, 1);
771+
setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
772772
else
773-
setenv("GIT_PREFIX", "", 1);
773+
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
774774

775775
if (startup_info) {
776776
startup_info->have_repository = !nongit_ok || !*nongit_ok;

0 commit comments

Comments
 (0)