aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorDavid Reiss <dreiss@facebook.com>2008-05-19 23:49:26 -0700
committerJunio C Hamano <gitster@pobox.com>2008-05-23 14:15:01 -0700
commit0454dd93bfb2334355ec62fff670d8c6cb3570a1 (patch)
tree8c0b1ada7cce01e71c2a2bbed0cfd23a26db8ba2 /setup.c
parentd553e737897e8edbbc2092bf345fc58b2dae5251 (diff)
downloadgit-0454dd93bfb2334355ec62fff670d8c6cb3570a1.tar.gz
git-0454dd93bfb2334355ec62fff670d8c6cb3570a1.tar.xz
Add support for GIT_CEILING_DIRECTORIES
Make git recognize a new environment variable that prevents it from chdir'ing up into specified directories when looking for a GIT_DIR. Useful for avoiding slow network directories. For example, I use git in an environment where homedirs are automounted and "ls /home/nonexistent" takes about 9 seconds. Setting GIT_CEILING_DIRS="/home" allows "git help -a" (for bash completion) and "git symbolic-ref" (for my shell prompt) to run in a reasonable time. Signed-off-by: David Reiss <dreiss@facebook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/setup.c b/setup.c
index b8fd47639..c14b10636 100644
--- a/setup.c
+++ b/setup.c
@@ -359,10 +359,11 @@ const char *read_gitfile_gently(const char *path)
const char *setup_git_directory_gently(int *nongit_ok)
{
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
+ const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
static char cwd[PATH_MAX+1];
const char *gitdirenv;
const char *gitfile_dir;
- int len, offset;
+ int len, offset, ceil_offset;
/*
* Let's assume that we are in a git repository.
@@ -414,6 +415,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");
+ ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);
+
/*
* Test in the following order (relative to the cwd):
* - .git (file containing "gitdir: <path>")
@@ -444,17 +447,16 @@ const char *setup_git_directory_gently(int *nongit_ok)
return NULL;
}
chdir("..");
- do {
- if (!offset) {
- if (nongit_ok) {
- if (chdir(cwd))
- die("Cannot come back to cwd");
- *nongit_ok = 1;
- return NULL;
- }
- die("Not a git repository");
+ while (--offset > ceil_offset && cwd[offset] != '/');
+ if (offset <= ceil_offset) {
+ if (nongit_ok) {
+ if (chdir(cwd))
+ die("Cannot come back to cwd");
+ *nongit_ok = 1;
+ return NULL;
}
- } while (cwd[--offset] != '/');
+ die("Not a git repository");
+ }
}
inside_git_dir = 0;