All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] Remove .git auto detection from setup_git_env()
Date: Fri,  5 Feb 2010 18:47:48 +0700	[thread overview]
Message-ID: <1265370468-6147-1-git-send-email-pclouds@gmail.com> (raw)

When GIT_DIR environment variable is not specified, .git will be
searched if a repository is needed. Currently this can be done in two
places: setup_git_directory_gently() and setup_git_env().

The one in setup_git_env() is no longer correct and should IMHO have
been removed since the introduction of setup_git_directory_gently() in
d288a70. Having two ways of auto detection may lead to obscure errors
because .git may be misdetected by setup_git_env(),
automatically called via git_path(), which is all over the place.

This patch makes setup_git_env() die if GIT_DIR is not explictly
set. That's setup_git_directory_gently()'s job. If you ever want to
touch things inside $GIT_DIR, you should have already called
setup_git_directory_gently().

This patch breaks commands (in a good way) and obviously not for
mainline. I still have to go through "make test" to see how many are
impacted. But I think this is a good change. Am I missing something?

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 environment.c |    4 +---
 setup.c       |    4 +++-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/environment.c b/environment.c
index 739ec27..b609569 100644
--- a/environment.c
+++ b/environment.c
@@ -67,9 +67,7 @@ static void setup_git_env(void)
 {
 	git_dir = getenv(GIT_DIR_ENVIRONMENT);
 	if (!git_dir)
-		git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
-	if (!git_dir)
-		git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+		die("GIT_DIR not properly set");
 	git_object_dir = getenv(DB_ENVIRONMENT);
 	if (!git_object_dir) {
 		git_object_dir = xmalloc(strlen(git_dir) + 9);
diff --git a/setup.c b/setup.c
index 710e2f3..ae1ba52 100644
--- a/setup.c
+++ b/setup.c
@@ -396,8 +396,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
 				die("Repository setup failed");
 			break;
 		}
-		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
+		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {
+			set_git_dir(DEFAULT_GIT_DIR_ENVIRONMENT);
 			break;
+		}
 		if (is_git_directory(".")) {
 			inside_git_dir = 1;
 			if (!work_tree_env)
-- 
1.7.0.rc0.54.gd33ef

             reply	other threads:[~2010-02-05 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-05 11:47 Nguyễn Thái Ngọc Duy [this message]
2010-02-05 15:12 ` [PATCH] Remove .git auto detection from setup_git_env() Jeff King
2010-02-05 17:22   ` Junio C Hamano
2010-02-05 17:27     ` Junio C Hamano
2010-02-05 20:29       ` René Scharfe

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=1265370468-6147-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.