git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Lars R. Damerow" <lars@pixar.com>
To: git@vger.kernel.org
Subject: [PATCH 3/3] Add support for GIT_ONE_FILESYSTEM
Date: Wed, 17 Mar 2010 12:55:53 -0700	[thread overview]
Message-ID: <1268855753-25840-4-git-send-email-lars@pixar.com> (raw)
In-Reply-To: <1268855753-25840-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               |   24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 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 f0b56b9..ef23e79 100644
--- 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,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,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);
-- 
1.6.5.2

  parent reply	other threads:[~2010-03-17 20:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17 19:55 [PATCH v3 0/3] Add support for GIT_ONE_FILESYSTEM Lars R. Damerow
2010-03-17 19:55 ` [PATCH 1/3] config.c: remove static keyword from git_env_bool() Lars R. Damerow
2010-03-17 19:55 ` [PATCH 2/3] truncate cwd string before printing error message Lars R. Damerow
2010-03-17 19:55 ` Lars R. Damerow [this message]
2010-03-28  9:22   ` [PATCH 3/3] Add support for GIT_ONE_FILESYSTEM Jeff King
2010-03-28 12:05     ` Jeff King
2010-03-28 16:44     ` Junio C Hamano
2010-03-28 17:32       ` Lars Damerow
2010-03-30 15:58         ` Jeff King
2010-03-30 22:43       ` Linus Torvalds
2010-03-30 22:59         ` Thomas Rast
2010-03-30 23:04           ` Jeff King
2010-03-30 23:02         ` Jeff King
2010-03-30 23:10           ` Junio C Hamano
2010-03-30 23:12           ` Linus Torvalds
2010-03-31  0:54             ` Erik Faye-Lund
2010-04-04 18:00               ` [PATCH] GIT_ONE_FILESYSTEM: flip the default to stop at filesystem boundaries Junio C Hamano
2010-04-04 22:30                 ` [PATCH] Rename ONE_FILESYSTEM to DISCOVERY_ACROSS_FILESYSTEM Junio C Hamano
2010-04-04 22:37                   ` Matthieu Moy
2010-04-04 22:39                 ` [PATCH] GIT_ONE_FILESYSTEM: flip the default to stop at filesystem boundaries Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268855753-25840-4-git-send-email-lars@pixar.com \
    --to=lars@pixar.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).