git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Add support for GIT_ONE_FILESYSTEM

From
Lars R. Damerow <lars@pixar.com>
Date
Mar 16, 2010, 22:05 UTC
Message-ID
<1268777101-22122-3-git-send-email-lars@pixar.com>
In-Reply-To
<1268777101-22122-1-git-send-email-lars@pixar.com>

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>
---
 Documentation/git.txt |    3 +++
 setup.c               |   17 ++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 35c0c79..dbb590f 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -529,6 +529,9 @@ 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'::
+	Stop at filesystem boundaries when looking for .git or objects.
+
 git Commits
 ~~~~~~~~~~~
 'GIT_AUTHOR_NAME'::
diff --git a/setup.c b/setup.c
index 5716d90..d40e2e6 100644
--- a/setup.c
+++ b/setup.c
@@ -319,10 +319,12 @@ 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_DIRECTORIES_ENVIRONMENT);
-	static char cwd[PATH_MAX+1];
+	static char cwd[PATH_MAX+1], err_cwd[PATH_MAX+1];
 	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,11 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	 *   etc.
 	 */
 	offset = len = strlen(cwd);
+	if ((one_filesystem = git_env_bool("GIT_ONE_FILESYSTEM", 0))) {
+		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 +429,14 @@ 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))
+				die_errno("failed to stat '%s/..'", getcwd(err_cwd, sizeof(err_cwd)-1));
+			if (buf.st_dev != current_device)
+				die("Not a git repository (or any parent up to %s/..)\n"
+					"Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.",
+					getcwd(err_cwd, sizeof(err_cwd)-1));
+		}
 		if (chdir(".."))
 			die_errno("Cannot change to '%s/..'", cwd);
 	}
-- 
1.6.5.2
Previous: Lars R. DamerowNext: Nguyen Thai Ngoc Duy
Message 3 of 5 in “Add support for GIT_ONE_FILESYSTEM (resubmission)”
  1. 0/2 Add support for GIT_ONE_FILESYSTEM (resubmission)Lars R. Damerow, Mar 16, 2010
  2. 1/2 config.c: remove static keyword from git_env_bool()Lars R. Damerow, Mar 16, 2010
  3. 2/2 Add support for GIT_ONE_FILESYSTEMLars R. Damerow, Mar 16, 2010
  4. Nguyen Thai Ngoc DuyMar 17, 2010
  5. Johannes SixtMar 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.