diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-07-07 02:17:23 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-07-07 02:17:23 -0700 |
commit | 17d778e710f9dacc770b5790e792b85cdba75a9d (patch) | |
tree | 1a3a97aa0c6d5cd86505e12ab2fc58e4f5bf849f /setup.c | |
parent | Merge branch 'db/no-git-config' (diff) | |
parent | Eliminate an unnecessary chdir("..") (diff) | |
download | tgif-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.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -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; |