From: Junio C Hamano Date: Mon, 7 Jun 2010 01:42:12 +0000 (-0700) Subject: Merge branch 'maint' X-Git-Tag: v1.7.2-rc0~96 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/624016114ed96ebdbd896c51d68f15790d834042?hp=-c Merge branch 'maint' * maint: setup: document prefix --- 624016114ed96ebdbd896c51d68f15790d834042 diff --combined setup.c index 5a083fa77d,0e4cfe603f..7e0460205d --- a/setup.c +++ b/setup.c @@@ -323,8 -323,6 +323,8 @@@ const char *setup_git_directory_gently( const char *gitdirenv; const char *gitfile_dir; int len, offset, ceil_offset, root_len; + int current_device = 0, one_filesystem = 1; + struct stat buf; /* * Let's assume that we are in a git repository. @@@ -392,12 -390,6 +392,12 @@@ * etc. */ offset = len = strlen(cwd); + one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0); + if (one_filesystem) { + if (stat(".", &buf)) + die_errno("failed to stat '.'"); + current_device = buf.st_dev; + } for (;;) { gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT); if (gitfile_dir) { @@@ -430,27 -422,8 +430,27 @@@ } die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT); } - if (chdir("..")) + if (one_filesystem) { + if (stat("..", &buf)) { + cwd[offset] = '\0'; + die_errno("failed to stat '%s/..'", cwd); + } + if (buf.st_dev != current_device) { + if (nongit_ok) { + if (chdir(cwd)) + die_errno("Cannot come back to cwd"); + *nongit_ok = 1; + return NULL; + } + cwd[offset] = '\0'; + die("Not a git repository (or any parent up to mount parent %s)\n" + "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd); + } + } + if (chdir("..")) { + cwd[offset] = '\0'; die_errno("Cannot change to '%s/..'", cwd); + } } inside_git_dir = 0; @@@ -546,6 -519,12 +546,12 @@@ int check_repository_format(void return check_repository_format_gently(NULL); } + /* + * Returns the "prefix", a path to the current working directory + * relative to the work tree root, or NULL, if the current working + * directory is not a strict subdirectory of the work tree root. The + * prefix always ends with a '/' character. + */ const char *setup_git_directory(void) { const char *retval = setup_git_directory_gently(NULL);