David Reiss schrieb: > 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_DIRS_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. > @@ -415,6 +517,14 @@ const char *setup_git_directory_gently(int *nongit_ok) > die("Unable to read current working directory"); > > /* > + * Compute ceil_offset based on GIT_CEILING_DIRS. It is actually the offset > + * of the first character in cwd after the trailing slash of the ceiling. > + * Putting it so far to the right is necessary in order to bail out of the > + * "--offset" loop early enough. > + */ > + ceil_offset = 1 + longest_ancestor_length(cwd, env_ceiling_dirs); > + > + /* > * Test in the following order (relative to the cwd): > * - .git (file containing "gitdir: <path>") > * - .git/ > @@ -443,9 +553,8 @@ const char *setup_git_directory_gently(int *nongit_ok) > check_repository_format_gently(nongit_ok); > return NULL; > } > - chdir(".."); > do { > - if (!offset) { > + if (offset <= ceil_offset) { > if (nongit_ok) { > if (chdir(cwd)) > die("Cannot come back to cwd"); > @@ -455,6 +564,7 @@ const char *setup_git_directory_gently(int *nongit_ok) > die("Not a git repository"); > } > } while (cwd[--offset] != '/'); If you make it so that the default value of ceil_offset is 0 (i.e. in the absence of any GIT_CEILING_DIRS), and at this place you did } while (offset > ceil_offset && cwd[--offset] != '/'); you wouldn't have to bend backwards with this off-by-one magic, would you? (But I admit that I haven't tried this code, I'm only comparing it to how we do it mingw.git.) -- Hannes -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html