From 2163e5dbb4cad43d65a4ffc8daeacff5eedd7af9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 8 Mar 2013 04:29:08 -0500 Subject: cache.h: drop LOCAL_REPO_ENV_SIZE We keep a static array of variables that should be cleared when invoking a sub-process on another repo. We statically size the array with the LOCAL_REPO_ENV_SIZE macro so that any readers do not have to count it themselves. As it turns out, no readers actually use the macro, and it creates a maintenance headache, as modifications to the array need to happen in two places (one to add the new element, and another to bump the size). Since it's NULL-terminated, we can just drop the size macro entirely. While we're at it, we'll clean up some comments around it, and add a new mention of it at the top of the list of environment variable macros. Even though local_repo_env is right below that list, it's easy to miss, and additions to that list should consider local_repo_env. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- environment.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'environment.c') diff --git a/environment.c b/environment.c index 85edd7f95a..81ffb4b666 100644 --- a/environment.c +++ b/environment.c @@ -76,11 +76,9 @@ static const char *git_dir; static char *git_object_dir, *git_index_file, *git_graft_file; /* - * Repository-local GIT_* environment variables - * Remember to update local_repo_env_size in cache.h when - * the size of the list changes + * Repository-local GIT_* environment variables; see cache.h for details. */ -const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = { +const char * const local_repo_env[] = { ALTERNATE_DB_ENVIRONMENT, CONFIG_ENVIRONMENT, CONFIG_DATA_ENVIRONMENT, -- cgit v1.2.3 From a6f7f9a32532a636bd458c7a3dc2cc16fbe237d3 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 8 Mar 2013 04:30:25 -0500 Subject: 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 Signed-off-by: Junio C Hamano --- environment.c | 1 + 1 file changed, 1 insertion(+) (limited to 'environment.c') diff --git a/environment.c b/environment.c index 81ffb4b666..4fb7ceac3a 100644 --- a/environment.c +++ b/environment.c @@ -88,6 +88,7 @@ const char * const local_repo_env[] = { GRAFT_ENVIRONMENT, INDEX_ENVIRONMENT, NO_REPLACE_OBJECTS_ENVIRONMENT, + GIT_PREFIX_ENVIRONMENT, NULL }; -- cgit v1.2.3 From 2cd83d10bb6bcf768129e1c4e5a4dee4b6bcd27f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 8 Mar 2013 04:32:22 -0500 Subject: setup: suppress implicit "." work-tree for bare repos If an explicit GIT_DIR is given without a working tree, we implicitly assume that the current working directory should be used as the working tree. E.g.,: GIT_DIR=/some/repo.git git status would compare against the cwd. Unfortunately, we fool this rule for sub-invocations of git by setting GIT_DIR internally ourselves. For example: git init foo cd foo/.git git status ;# fails, as we expect git config alias.st status git status ;# does not fail, but should What happens is that we run setup_git_directory when doing alias lookup (since we need to see the config), set GIT_DIR as a result, and then leave GIT_WORK_TREE blank (because we do not have one). Then when we actually run the status command, we do setup_git_directory again, which sees our explicit GIT_DIR and uses the cwd as an implicit worktree. It's tempting to argue that we should be suppressing that second invocation of setup_git_directory, as it could use the values we already found in memory. However, the problem still exists for sub-processes (e.g., if "git status" were an external command). You can see another example with the "--bare" option, which sets GIT_DIR explicitly. For example: git init foo cd foo/.git git status ;# fails git --bare status ;# does NOT fail We need some way of telling sub-processes "even though GIT_DIR is set, do not use cwd as an implicit working tree". We could do it by putting a special token into GIT_WORK_TREE, but the obvious choice (an empty string) has some portability problems. Instead, we add a new boolean variable, GIT_IMPLICIT_WORK_TREE, which suppresses the use of cwd as a working tree when GIT_DIR is set. We trigger the new variable when we know we are in a bare setting. The variable is left intentionally undocumented, as this is an internal detail (for now, anyway). If somebody comes up with a good alternate use for it, and once we are confident we have shaken any bugs out of it, we can consider promoting it further. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- environment.c | 1 + 1 file changed, 1 insertion(+) (limited to 'environment.c') diff --git a/environment.c b/environment.c index 4fb7ceac3a..92c5dff008 100644 --- a/environment.c +++ b/environment.c @@ -85,6 +85,7 @@ const char * const local_repo_env[] = { DB_ENVIRONMENT, GIT_DIR_ENVIRONMENT, GIT_WORK_TREE_ENVIRONMENT, + GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, GRAFT_ENVIRONMENT, INDEX_ENVIRONMENT, NO_REPLACE_OBJECTS_ENVIRONMENT, -- cgit v1.2.3