aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-07-07 02:17:23 -0700
committerJunio C Hamano <gitster@pobox.com>2008-07-07 02:17:23 -0700
commit17d778e710f9dacc770b5790e792b85cdba75a9d (patch)
tree1a3a97aa0c6d5cd86505e12ab2fc58e4f5bf849f /setup.c
parent5e97f464df082d8f45e163bbf24341dceeafe89d (diff)
parent450f437fb0fe276a6e946c281c768118e39dc9e7 (diff)
downloadgit-17d778e710f9dacc770b5790e792b85cdba75a9d.tar.gz
git-17d778e710f9dacc770b5790e792b85cdba75a9d.tar.xz
Merge branch 'dr/ceiling'
* dr/ceiling: Eliminate an unnecessary chdir("..") Add support for GIT_CEILING_DIRECTORIES Fold test-absolute-path into test-path-utils Implement normalize_absolute_path Conflicts: cache.h setup.c
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/setup.c b/setup.c
index cc3fb380c..6cf909463 100644
--- a/setup.c
+++ b/setup.c
@@ -376,11 +376,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 minoffset = 0;
+ int len, offset, ceil_offset;
/*
* Let's assume that we are in a git repository.
@@ -431,8 +431,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");
- if (has_dos_drive_prefix(cwd))
- minoffset = 2;
+
+ ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);
+ if (ceil_offset < 0 && has_dos_drive_prefix(cwd))
+ ceil_offset = 1;
/*
* Test in the following order (relative to the cwd):
@@ -463,18 +465,17 @@ const char *setup_git_directory_gently(int *nongit_ok)
check_repository_format_gently(nongit_ok);
return NULL;
}
- chdir("..");
- do {
- if (offset <= minoffset) {
- 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 (offset > minoffset && cwd[--offset] != '/');
+ die("Not a git repository");
+ }
+ chdir("..");
}
inside_git_dir = 0;