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

[PATCH] getenv/setenv: use constants if available

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 28, 2007, 14:15 UTC
Message-ID
<20070628141525.GA25448@moooo.ath.cx>

There were places using "GIT_DIR" instead of GIT_DIR_ENVIRONMENT and "GIT_CONFIG" instead of CONFIG_ENVIRONMENT. This makes it easier to find all places touching an environment variable using git grep or similar tools.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
I only found one other place where a string was used directly even
though there is a constant: GIT_REFLOG_ACTION is only defined in
git-revert.c and builtin-fetch--tool.c uses the environment variable
too.  At least when searching with grep this makes no problem because
the name of the constant is the same as the string it is defined to..
---
 builtin-config.c |    4 ++--
 path.c           |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 3f7cab1..7d2063c 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -178,14 +178,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 			char *home = getenv("HOME");
 			if (home) {
 				char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
-				setenv("GIT_CONFIG", user_config, 1);
+				setenv(CONFIG_ENVIRONMENT, user_config, 1);
 				free(user_config);
 			} else {
 				die("$HOME not set");
 			}
 		}
 		else if (!strcmp(argv[1], "--system"))
-			setenv("GIT_CONFIG", ETC_GITCONFIG, 1);
+			setenv(CONFIG_ENVIRONMENT, ETC_GITCONFIG, 1);
 		else if (!strcmp(argv[1], "--null") || !strcmp(argv[1], "-z")) {
 			term = '\0';
 			delim = '\n';
diff --git a/path.c b/path.c
index 6395cf2..c4ce962 100644
--- a/path.c
+++ b/path.c
@@ -252,7 +252,7 @@ char *enter_repo(char *path, int strict)
 
 	if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
 	    validate_headref("HEAD") == 0) {
-		setenv("GIT_DIR", ".", 1);
+		setenv(GIT_DIR_ENVIRONMENT, ".", 1);
 		check_repository_format();
 		return path;
 	}
-- 
1.5.2.2.1398.ga4b05
Message 1 of 1 in “getenv/setenv: use constants if available”
  1. getenv/setenv: use constants if availableMatthias Lederhofer, Jun 28, 2007

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.