]> Pileus Git - ~andy/git/commitdiff
environment: add GIT_PREFIX to local_repo_env
authorJeff King <peff@peff.net>
Fri, 8 Mar 2013 09:30:25 +0000 (04:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Mar 2013 22:02:31 +0000 (14:02 -0800)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
environment.c
setup.c

diff --git a/cache.h b/cache.h
index 139b911816b2b8cbf2ea5ba12184d393e161b782..3c6b677418a1db5fd6cd74f1e9cb16b6b8f29ddf 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -345,6 +345,7 @@ static inline enum object_type object_type(unsigned int mode)
 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
 #define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
 #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
+#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
 #define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
 #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
index 81ffb4b666cb9b66d52048422a0911bcf5185173..4fb7ceac3aec94ca2c1ab2e5d94e54ff3f1bcf53 100644 (file)
@@ -88,6 +88,7 @@ const char * const local_repo_env[] = {
        GRAFT_ENVIRONMENT,
        INDEX_ENVIRONMENT,
        NO_REPLACE_OBJECTS_ENVIRONMENT,
+       GIT_PREFIX_ENVIRONMENT,
        NULL
 };
 
diff --git a/setup.c b/setup.c
index 1b120175f2184b782f389d2fc99f3e37710f35d3..d0e3ecdcd4222a3287cbca9b48f9fa04ca4765a8 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -768,9 +768,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
 
        prefix = setup_git_directory_gently_1(nongit_ok);
        if (prefix)
-               setenv("GIT_PREFIX", prefix, 1);
+               setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
        else
-               setenv("GIT_PREFIX", "", 1);
+               setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
 
        if (startup_info) {
                startup_info->have_repository = !nongit_ok || !*nongit_ok;