Add support for GIT_ONE_FILESYSTEM
This patch makes git pay attention to the GIT_ONE_FILESYSTEM environment variable. When that variable is set, git will stop searching for a GIT_DIR when it attempts to cross a filesystem boundary. When working in an environment with too many automount points to make maintaining a GIT_CEILING_DIRECTORIES list enjoyable, GIT_ONE_FILESYSTEM gives the option of turning all such attempts off with one setting. Signed-off-by: Lars R. Damerow <lars@pixar.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars R. Damerow committed
Mar 17, 2010 at 12:55 UTC
8030e44215fe8f34edd57d711a35f2f0f97a0423
2 files changed
+31
Documentation/git.txt
+6
@@ -530,6 +530,12 @@ git so take care if using Cogito etc.
530
a GIT_DIR set on the command line or in the environment.
531
(Useful for excluding slow-loading network directories.)
532
533
+'GIT_ONE_FILESYSTEM'::
534
+ If set to a true value ("true" or a non-zero integer), stop at
535
+ filesystem boundaries when looking for a repository directory.
536
+ Like 'GIT_CEILING_DIRECTORIES', it will not affect an explicit
537
+ respository directory set via 'GIT_DIR' or on the command line.
538
+
539
git Commits
540
~~~~~~~~~~~
541
'GIT_AUTHOR_NAME'::
setup.c
+25
@@ -323,6 +323,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
323
const char *gitdirenv;
324
const char *gitfile_dir;
325
int len, offset, ceil_offset, root_len;
326
+ int current_device = 0, one_filesystem = 0;
327
+ struct stat buf;
328
329
/*
330
* Let's assume that we are in a git repository.
@@ -390,6 +392,12 @@ const char *setup_git_directory_gently(int *nongit_ok)
392
* etc.
393
*/
394
offset = len = strlen(cwd);
395
+ one_filesystem = git_env_bool("GIT_ONE_FILESYSTEM", 0);
396
+ if (one_filesystem) {
397
+ if (stat(".", &buf))
398
+ die_errno("failed to stat '.'");
399
+ current_device = buf.st_dev;
400
+ }
401
for (;;) {
402
gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
403
if (gitfile_dir) {
@@ -422,6 +430,23 @@ const char *setup_git_directory_gently(int *nongit_ok)
430
}
431
die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
432
}
433
+ if (one_filesystem) {
434
+ if (stat("..", &buf)) {
435
+ cwd[offset] = '\0';
436
+ die_errno("failed to stat '%s/..'", cwd);
437
+ }
438
+ if (buf.st_dev != current_device) {
439
+ if (nongit_ok) {
440
+ if (chdir(cwd))
441
+ die_errno("Cannot come back to cwd");
442
+ *nongit_ok = 1;
443
+ return NULL;
444
+ }
445
+ cwd[offset] = '\0';
446
+ die("Not a git repository (or any parent up to mount parent %s)\n"
447
+ "Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.", cwd);
448
+ }
449
+ }
450
if (chdir("..")) {
451
cwd[offset] = '\0';
452
die_errno("Cannot change to '%s/..'", cwd);