git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Prohaska <prohaska@zib.de>
To: git@vger.kernel.org
Cc: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>,
	Steffen Prohaska <prohaska@zib.de>
Subject: [PATCH 3/3] Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir()
Date: Wed, 21 Nov 2007 21:27:21 +0100	[thread overview]
Message-ID: <11956768412755-git-send-email-prohaska@zib.de> (raw)
In-Reply-To: <11956768413887-git-send-email-prohaska@zib.de>

From: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>

We have a function set_git_dir().  So let's use it, instead
of setting the evironment directly.

This also fixes a problem on Windows: environment.c caches
results of many getenv calls.  A setenv(X) call to the Windows
C runtime (CRT) invalidates all previous values returned by
getenv(X).  So cached values become dangling pointers.

Before this change, git clone was failing with 'invalid object
name HEAD' if ran from Windows' cmd.exe.

[sp: rebased; split off get_git_dir() in builtin-init-db.c
     to separate commit; adjusted commit message. ]

Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 git.c   |    6 +++---
 path.c  |    2 +-
 setup.c |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/git.c b/git.c
index 7604319..8bc25b7 100644
--- a/git.c
+++ b/git.c
@@ -45,14 +45,14 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 				fprintf(stderr, "No directory given for --git-dir.\n" );
 				usage(git_usage_string);
 			}
-			setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
+			set_git_dir( (*argv)[1] );
 			if (envchanged)
 				*envchanged = 1;
 			(*argv)++;
 			(*argc)--;
 			handled++;
 		} else if (!prefixcmp(cmd, "--git-dir=")) {
-			setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
+			set_git_dir(cmd + 10);
 			if (envchanged)
 				*envchanged = 1;
 		} else if (!strcmp(cmd, "--work-tree")) {
@@ -72,7 +72,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 		} else if (!strcmp(cmd, "--bare")) {
 			static char git_dir[PATH_MAX+1];
 			is_bare_repository_cfg = 1;
-			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
+			set_git_dir(getcwd(git_dir, sizeof(git_dir)));
 			if (envchanged)
 				*envchanged = 1;
 		} else {
diff --git a/path.c b/path.c
index 4260952..f26a4a1 100644
--- a/path.c
+++ b/path.c
@@ -248,7 +248,7 @@ char *enter_repo(char *path, int strict)
 
 	if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
 	    validate_headref("HEAD") == 0) {
-		setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+		set_git_dir(".");
 		check_repository_format();
 		return path;
 	}
diff --git a/setup.c b/setup.c
index 43cd3f9..8dbd46c 100644
--- a/setup.c
+++ b/setup.c
@@ -285,7 +285,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			inside_git_dir = 1;
 			if (!work_tree_env)
 				inside_work_tree = 0;
-			setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+			set_git_dir(".");
 			return NULL;
 		}
 		chdir("..");
-- 
1.5.3.5.750.g8692

  reply	other threads:[~2007-11-21 20:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-21 20:27 [PATCH 0/3] msysgit fallout Steffen Prohaska
2007-11-21 20:27 ` [PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings Steffen Prohaska
2007-11-21 20:27   ` [PATCH 2/3] builtin-init-db: use get_git_dir() instead of getenv() Steffen Prohaska
2007-11-21 20:27     ` Steffen Prohaska [this message]
2007-11-22  1:22       ` [PATCH 3/3] Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir() Johannes Schindelin
2007-11-22  2:34         ` Junio C Hamano
2007-11-22  6:13           ` Steffen Prohaska
2007-11-22  7:52             ` Junio C Hamano
2007-11-22  8:31               ` Steffen Prohaska
2007-11-22  9:58                 ` Johannes Sixt
2007-11-22 17:56                   ` Steffen Prohaska
2007-11-22 22:09                     ` Johannes Schindelin
2008-01-01 18:52                     ` Steffen Prohaska
2008-01-03  4:07                       ` Dmitry Kakurin
2008-01-03  6:02                         ` Steffen Prohaska
2008-01-03  6:26                           ` Dmitry Kakurin
2008-01-03  7:53                             ` Steffen Prohaska
2007-11-22  7:29           ` Johannes Sixt

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=11956768412755-git-send-email-prohaska@zib.de \
    --to=prohaska@zib.de \
    --cc=Dmitry.Kakurin@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 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).