Re: I don't want the .git directory next to my code.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Thursday, January 17, 2008 - 10:36 am

On Thu, 17 Jan 2008, Jeff King wrote:

Ok, here's the ugliest idea *ever*:

We could actually use POSIX extended attributes (or whatever 
system-specific version of it a particular filesystem supports) for people 
who *really* don't want to pollute their file structure.

I know, I know, it's horrible. It's one of those things that would 
actually be reqlly convenient (and probably even pretty easy to 
implement), but is also going to be *really* subtle when it breaks.

But I bet some people would like it. I personally tend to hate extended 
attributes (they tend to have serious problems with anything that moves 
things around or backs them up - especially across filesystem boundaries), 
but there is no question that they can't be convenient to hide 
information.

Anyway, here's a really stupid patch. It kind of works, but it has no way 
to turn this off.

On at least Linux, with this you can do something like

	.. start off with a git directory ..
	mv .git /external/git/location
	setfattr -n user.git-dir -v /external/git/location .

and now that "user.git-dir" thing acts as a kind of invisible "symlink" to 
the external git directory.

Not exactly heavily tested, and I don't know how portable the whole xattr 
thing is (ie I know OS X has file attributes, I just don't know if the 
interface is at all similar).

I don't like extended attributes myself, but this patch really is pretty 
simple and perhaps useful.

			Linus

---
 setup.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/setup.c b/setup.c
index adede16..97865f4 100644
--- a/setup.c
+++ b/setup.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "dir.h"
+#include <attr/xattr.h>
 
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
@@ -302,6 +303,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	 */
 	offset = len = strlen(cwd);
 	for (;;) {
+		int attr_len;
+		static char git_dir[PATH_MAX];
+
 		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
 			break;
 		if (is_git_directory(".")) {
@@ -312,6 +316,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
+		attr_len = getxattr(".", "user.git-dir", git_dir, sizeof(git_dir)-1);
+		if (attr_len > 0) {
+			git_dir[attr_len] = 0;
+			if (is_git_directory(git_dir)) {
+				setenv(GIT_DIR_ENVIRONMENT, git_dir, 1);
+				break;
+			}
+		}
 		chdir("..");
 		do {
 			if (!offset) {
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: I don't want the .git directory next to my code., Randal L. Schwartz, (Tue Jan 15, 8:50 pm)
Re: I don't want the .git directory next to my code., Nguyen Thai Ngoc Duy, (Tue Jan 15, 9:03 pm)
Re: I don't want the .git directory next to my code., David Symonds, (Tue Jan 15, 9:06 pm)
Re: I don't want the .git directory next to my code., Daniel Barkalow, (Tue Jan 15, 9:13 pm)
Re: I don't want the .git directory next to my code., David Symonds, (Tue Jan 15, 9:24 pm)
Re: I don't want the .git directory next to my code., Daniel Barkalow, (Tue Jan 15, 9:44 pm)
Re: I don't want the .git directory next to my code., Neil Macneale, (Tue Jan 15, 10:27 pm)
Re: I don't want the .git directory next to my code., Mike Krier, (Tue Jan 15, 11:07 pm)
Re: I don't want the .git directory next to my code., Matthieu Moy, (Wed Jan 16, 2:59 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 3:36 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 3:37 am)
Re: I don't want the .git directory next to my code., Matthieu Moy, (Wed Jan 16, 4:59 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 5:12 am)
Re: I don't want the .git directory next to my code., Matthieu Moy, (Wed Jan 16, 5:25 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 5:45 am)
Re: I don't want the .git directory next to my code., Jakub Narebski, (Wed Jan 16, 6:13 am)
Re: I don't want the .git directory next to my code., Bert Wesarg, (Wed Jan 16, 6:21 am)
Re: I don't want the .git directory next to my code., Junio C Hamano, (Wed Jan 16, 10:40 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 10:51 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Wed Jan 16, 10:52 am)
Re: I don't want the .git directory next to my code., Linus Torvalds, (Wed Jan 16, 11:15 am)
Re: I don't want the .git directory next to my code., Linus Torvalds, (Wed Jan 16, 11:25 am)
Re: I don't want the .git directory next to my code., Junio C Hamano, (Wed Jan 16, 12:23 pm)
Re: I don't want the .git directory next to my code., Wayne Davison, (Wed Jan 16, 3:33 pm)
Re: I don't want the .git directory next to my code., Brian Downing, (Wed Jan 16, 5:59 pm)
Re: I don't want the .git directory next to my code., Randal L. Schwartz, (Wed Jan 16, 6:35 pm)
Re: I don't want the .git directory next to my code., Sam Vilain, (Wed Jan 16, 6:42 pm)
Re: I don't want the .git directory next to my code., Linus Torvalds, (Wed Jan 16, 7:38 pm)
Re: I don't want the .git directory next to my code., Martin Langhoff, (Wed Jan 16, 7:59 pm)
Re: I don't want the .git directory next to my code., Randal L. Schwartz, (Wed Jan 16, 10:44 pm)
Re: I don't want the .git directory next to my code., Kris Shannon, (Wed Jan 16, 11:38 pm)
Re: I don't want the .git directory next to my code., Wincent Colaiuta, (Thu Jan 17, 3:34 am)
Re: I don't want the .git directory next to my code., Linus Torvalds, (Thu Jan 17, 10:36 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 10:49 am)
Re: I don't want the .git directory next to my code., Linus Torvalds, (Thu Jan 17, 11:02 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 11:10 am)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 12:20 pm)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 1:08 pm)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 1:57 pm)
Re: I don't want the .git directory next to my code., Martin Langhoff, (Thu Jan 17, 2:05 pm)
Re: I don't want the .git directory next to my code., Johannes Schindelin, (Thu Jan 17, 2:05 pm)
Re: I don't want the .git directory next to my code., David Symonds, (Fri Jan 18, 12:52 am)
Re: I don't want the .git directory next to my code., Andreas Ericsson, (Fri Jan 18, 1:41 am)