git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder@fzi.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Johannes Sixt" <j.sixt@viscovery.net>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"SZEDER Gábor" <szeder@ira.uka.de>,
	git@vger.kernel.org
Subject: Re: [RFC PATCH] Fix gitdir detection when in subdir of gitdir
Date: Mon, 19 Jan 2009 03:03:11 +0100	[thread overview]
Message-ID: <20090119020311.GA8753@neumann> (raw)
In-Reply-To: <7vhc3wuwxb.fsf@gitster.siamese.dyndns.org>

On Sun, Jan 18, 2009 at 01:27:44PM -0800, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > I think (1) the solution (almost) makes sense, (2) the patch needs to be
> > explained a lot better as you mentioned in your two messages, and (3) if
> > it does not affect any other case than when you are in a subdirectory of
> > the .git/ directory, then you are doing something funny anyway and
> > performance issue Dscho mentions, if any, is not a concern.
> >
> > My "(almost)" in (1) above is because the patch uses this new behaviour
> > even when you are inside the .git/ directory itself (or at the root of a
> > bare repository), which is a very common case that we do not have to nor
> > want to change the behaviour.  It also invalidates the precondition of (3)
> > above.
> 
> And this is a trivial follow-up on top of Szeder's patch.

Thanks.  In the meantime I was working on a patch that sets relative
path in this case, too.  I got it almost working: all tests passed
except '.git/objects/: is-bare-repository' in 't1500-rev-parse'.  I
couldn't figure it out why this test failed, however.

In case somebody might be interested for such an uncommon case, the
patch is below.


Best,
Gábor


 setup.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/setup.c b/setup.c
index 6b277b6..b4d37d7 100644
--- a/setup.c
+++ b/setup.c
@@ -375,7 +375,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	static char cwd[PATH_MAX+1];
 	const char *gitdirenv;
 	const char *gitfile_dir;
-	int len, offset, ceil_offset;
+	int len, offset, ceil_offset, cdup_count = 0;
 
 	/*
 	 * Let's assume that we are in a git repository.
@@ -453,10 +453,22 @@ const char *setup_git_directory_gently(int *nongit_ok)
 		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
 			break;
 		if (is_git_directory(".")) {
+			char gd_rel_path[PATH_MAX];
 			inside_git_dir = 1;
 			if (!work_tree_env)
 				inside_work_tree = 0;
-			setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+			if (cdup_count) {
+				char *p = gd_rel_path;
+				while (cdup_count-- > 1) {
+					*p++ = '.'; *p++ = '.'; *p++ = '/';
+				}
+				*p++ = '.'; *p++ = '.';
+				*p = '\0';
+			} else {
+				gd_rel_path[0] = '.';
+				gd_rel_path[1] = '\0';
+			}
+			setenv(GIT_DIR_ENVIRONMENT, gd_rel_path, 1);
 			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
@@ -472,6 +484,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 		}
 		if (chdir(".."))
 			die("Cannot change to %s/..: %s", cwd, strerror(errno));
+		cdup_count++;
 	}
 
 	inside_git_dir = 0;

  reply	other threads:[~2009-01-19  2:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 15:37 [RFC PATCH] Fix gitdir detection when in subdir of gitdir SZEDER Gábor
2009-01-16 16:29 ` Johannes Schindelin
2009-01-16 16:47   ` Johannes Sixt
2009-01-16 16:50     ` Johannes Sixt
2009-01-16 17:23       ` SZEDER Gábor
2009-01-16 18:07       ` Junio C Hamano
2009-01-16 20:55         ` Johannes Schindelin
2009-01-18 21:27         ` Junio C Hamano
2009-01-19  2:03           ` SZEDER Gábor [this message]
2009-01-19  3:15             ` Junio C Hamano
2009-01-19  7:17             ` Johannes Sixt
2009-01-19  2:08           ` [PATCH] t1500: extend with tests of 'git rev-parse --git-dir' SZEDER Gábor

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=20090119020311.GA8753@neumann \
    --to=szeder@fzi.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=szeder@ira.uka.de \
    /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).