Code

Add support for GIT_ONE_FILESYSTEM
authorLars R. Damerow <lars@pixar.com>
Wed, 17 Mar 2010 19:55:53 +0000 (12:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 28 Mar 2010 16:43:20 +0000 (09:43 -0700)
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>
Documentation/git.txt
setup.c

index 4e00b315ff7450efb4a48ba184c6d65991d53c58..bf1b45eef1e1e2904cbcc1fcbd84528618a5dc1d 100644 (file)
@@ -530,6 +530,12 @@ git so take care if using Cogito etc.
        a GIT_DIR set on the command line or in the environment.
        (Useful for excluding slow-loading network directories.)
 
+'GIT_ONE_FILESYSTEM'::
+       If set to a true value ("true" or a non-zero integer), stop at
+       filesystem boundaries when looking for a repository directory.
+       Like 'GIT_CEILING_DIRECTORIES', it will not affect an explicit
+       respository directory set via 'GIT_DIR' or on the command line.
+
 git Commits
 ~~~~~~~~~~~
 'GIT_AUTHOR_NAME'::
diff --git a/setup.c b/setup.c
index f0b56b9f545433d60644cf34d11eab798fee3a20..8b911b1a38f2a937ad6c2b69870f2c30872181dc 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -323,6 +323,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
        const char *gitdirenv;
        const char *gitfile_dir;
        int len, offset, ceil_offset, root_len;
+       int current_device = 0, one_filesystem = 0;
+       struct stat buf;
 
        /*
         * Let's assume that we are in a git repository.
@@ -390,6 +392,12 @@ const char *setup_git_directory_gently(int *nongit_ok)
         *   etc.
         */
        offset = len = strlen(cwd);
+       one_filesystem = git_env_bool("GIT_ONE_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) {
@@ -422,6 +430,23 @@ const char *setup_git_directory_gently(int *nongit_ok)
                        }
                        die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
                }
+               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 since GIT_ONE_FILESYSTEM is set.", cwd);
+                       }
+               }
                if (chdir("..")) {
                        cwd[offset] = '\0';
                        die_errno("Cannot change to '%s/..'", cwd);