Merge branch 'cb/maint-report-mount-point-correctly-in-setup' into maint

The filesystem boundary was not correctly reported when .git directory
discovery stopped at a mount point.

By Clemens Buchacher
* cb/maint-report-mount-point-correctly-in-setup:
  properly keep track of current working directory
This commit is contained in:
Junio C Hamano
2012-05-07 13:13:03 -07:00

22
setup.c
View File

@ -569,13 +569,15 @@ static const char *setup_nongit(const char *cwd, int *nongit_ok)
return NULL; return NULL;
} }
static dev_t get_device_or_die(const char *path, const char *prefix) static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_len)
{ {
struct stat buf; struct stat buf;
if (stat(path, &buf)) if (stat(path, &buf)) {
die_errno("failed to stat '%s%s%s'", die_errno("failed to stat '%*s%s%s'",
prefix_len,
prefix ? prefix : "", prefix ? prefix : "",
prefix ? "/" : "", path); prefix ? "/" : "", path);
}
return buf.st_dev; return buf.st_dev;
} }
@ -589,7 +591,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
static char cwd[PATH_MAX+1]; static char cwd[PATH_MAX+1];
const char *gitdirenv, *ret; const char *gitdirenv, *ret;
char *gitfile; char *gitfile;
int len, offset, ceil_offset; int len, offset, offset_parent, ceil_offset;
dev_t current_device = 0; dev_t current_device = 0;
int one_filesystem = 1; int one_filesystem = 1;
@ -631,7 +633,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
*/ */
one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0); one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0);
if (one_filesystem) if (one_filesystem)
current_device = get_device_or_die(".", NULL); current_device = get_device_or_die(".", NULL, 0);
for (;;) { for (;;) {
gitfile = (char*)read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT); gitfile = (char*)read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
if (gitfile) if (gitfile)
@ -653,11 +655,12 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
if (is_git_directory(".")) if (is_git_directory("."))
return setup_bare_git_dir(cwd, offset, len, nongit_ok); return setup_bare_git_dir(cwd, offset, len, nongit_ok);
while (--offset > ceil_offset && cwd[offset] != '/'); offset_parent = offset;
if (offset <= ceil_offset) while (--offset_parent > ceil_offset && cwd[offset_parent] != '/');
if (offset_parent <= ceil_offset)
return setup_nongit(cwd, nongit_ok); return setup_nongit(cwd, nongit_ok);
if (one_filesystem) { if (one_filesystem) {
dev_t parent_device = get_device_or_die("..", cwd); dev_t parent_device = get_device_or_die("..", cwd, offset);
if (parent_device != current_device) { if (parent_device != current_device) {
if (nongit_ok) { if (nongit_ok) {
if (chdir(cwd)) if (chdir(cwd))
@ -666,7 +669,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
return NULL; return NULL;
} }
cwd[offset] = '\0'; cwd[offset] = '\0';
die("Not a git repository (or any parent up to mount parent %s)\n" die("Not a git repository (or any parent up to mount point %s)\n"
"Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd); "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
} }
} }
@ -674,6 +677,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
cwd[offset] = '\0'; cwd[offset] = '\0';
die_errno("Cannot change to '%s/..'", cwd); die_errno("Cannot change to '%s/..'", cwd);
} }
offset = offset_parent;
} }
} }