git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

environment.c caches results of many getenv calls.
Under MinGW setenv(X) invalidates all previous values returned by getenv(X)
so cached values become dangling pointers.

Replaced all setenv(GIT_DIR, ...) with set_git_dir

Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
This commit is contained in:
Dmitry Kakurin
2007-08-09 13:41:02 -07:00
parent dfcdb3d9fc
commit 855f254b2b
4 changed files with 6 additions and 8 deletions

View File

@@ -318,9 +318,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
/*
* Set up the default .git directory contents
*/
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
git_dir = get_git_dir();
safe_create_dir(git_dir, 0);
/* Check to see if the repository version is right.

6
git.c
View File

@@ -67,14 +67,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")) {
@@ -93,7 +93,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--bare")) {
static char git_dir[PATH_MAX+1];
setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);
set_git_dir(getcwd(git_dir, sizeof(git_dir)));
if (envchanged)
*envchanged = 1;
} else {

2
path.c
View File

@@ -265,7 +265,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;
}

View File

@@ -332,7 +332,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("..");