git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] environment: add GIT_PREFIX to local_repo_env

From
Jeff King <peff@peff.net>
Date
Mar 8, 2013, 09:30 UTC
Message-ID
<20130308093025.GB1923@sigill.intra.peff.net>
In-Reply-To
<20130308092824.GA9127@sigill.intra.peff.net>

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 again 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>
---
I noticed this one because it was near code I was touching in an earlier
iteration of patch 3. I gave a quick skim and did not notice any other
variables which would want to receive the same treatment.
 cache.h       | 1 +
 environment.c | 1 +
 setup.c       | 4 ++--
 3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index b90044a..23e6e62 100644
--- 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"
diff --git a/environment.c b/environment.c
index dc73927..2bd1c37 100644
--- a/environment.c
+++ b/environment.c
@@ -95,6 +95,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 1dee47e..1996295 100644
--- a/setup.c
+++ b/setup.c
@@ -794,9 +794,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;
-- 
1.8.2.rc2.4.g3e774bb
Previous: Jeff KingNext: Eric Sunshine
Message 12 of 16 in “[BUG] bare repository detection does not work with aliases”
  1. Mark LodatoMar 7, 2013
  2. Jeff KingMar 8, 2013
  3. Junio C HamanoMar 8, 2013
  4. Jeff KingMar 8, 2013
  5. setup: suppress implicit "." work-tree for bare reposJeff King, Mar 8, 2013
  6. Johannes SixtMar 8, 2013
  7. Jeff KingMar 8, 2013
  8. Junio C HamanoMar 8, 2013
  9. Jeff KingMar 8, 2013
  10. [PATCHv2] setup and GIT_IMPLICIT_WORK_TREEJeff King, Mar 8, 2013
  11. 1/3 cache.h: drop LOCAL_REPO_ENV_SIZEJeff King, Mar 8, 2013
  12. 2/3 environment: add GIT_PREFIX to local_repo_envJeff King, Mar 8, 2013
  13. Eric SunshineMar 8, 2013
  14. Jeff KingMar 8, 2013
  15. Junio C HamanoMar 8, 2013
  16. 3/3 setup: suppress implicit "." work-tree for bare reposJeff King, Mar 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.