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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, 17 Jan 2008, Jeff King wrote:
> 
> You don't seem happy with any of those. But the fact remains that the
> git repo has to be stored _somewhere_, and when you run git, there needs
> to be some mapping telling it which git repo matches your working
> directory. So how _do_ you want to specify that mapping? 

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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux