git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly
@ 2007-08-06  9:44 Dmitry Kakurin
  2007-08-06 10:42 ` Johannes Schindelin
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Kakurin @ 2007-08-06  9:44 UTC (permalink / raw)
  To: git

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.

Added cache-aware function set_git_dir to complement get_git_dir

Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
---
 builtin-init-db.c |    4 +---
 cache.h           |    1 +
 environment.c     |    6 ++++++
 git.c             |    6 +++---
 path.c            |    2 +-
 setup.c           |    6 +++---
 7 files changed, 21 insertions(+), 10 deletions(-)
 create mode 100644 config.mak

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 5c0feba..62e579d 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -344,9 +344,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.
diff --git a/cache.h b/cache.h
index 91e9f71..bc2916e 100644
--- a/cache.h
+++ b/cache.h
@@ -210,6 +210,7 @@ extern int is_bare_repository(void);
 extern int is_inside_git_dir(void);
 extern int is_inside_work_tree(void);
 extern const char *get_git_dir(void);
+extern void set_git_dir(const char *newDir);
 extern char *get_object_directory(void);
 extern char *get_refs_directory(void);
 extern char *get_index_file(void);
diff --git a/environment.c b/environment.c
index f83fb9e..6ea7088 100644
--- a/environment.c
+++ b/environment.c
@@ -80,6 +80,12 @@ const char *get_git_dir(void)
  return git_dir;
 }
 
+void set_git_dir(const char *newDir)
+{
+    setenv(GIT_DIR_ENVIRONMENT, newDir, 1);
+    git_dir = NULL; // reset cache
+}
+
 char *get_object_directory(void)
 {
  if (!git_object_dir)
diff --git a/git.c b/git.c
index 210a763..53dfa05 100644
--- a/git.c
+++ b/git.c
@@ -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 {
diff --git a/path.c b/path.c
index 8a06cf7..14af033 100644
--- a/path.c
+++ b/path.c
@@ -266,7 +266,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 47cd790..c5cf3ea 100644
--- a/setup.c
+++ b/setup.c
@@ -292,7 +292,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
    }
    die("Not a git repository");
   }
-  setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+  set_git_dir(cwd);
   gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
   if (!gitdirenv)
    die("getenv after setenv failed");
@@ -332,8 +332,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
   * In case there is a work tree we may change the directory,
   * therefore make GIT_DIR an absolute path.
   */
- if ( !is_absolute_path( gitdirenv ) ) {
-  setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);
+ if (!is_absolute_path(gitdirenv)) {
+  set_git_dir(gitdir);
   gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
   if (!gitdirenv)
    die("getenv after setenv failed");
-- 
1.5.3.GIT

- Dmitry

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-08-06 22:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-06  9:44 [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly Dmitry Kakurin
2007-08-06 10:42 ` Johannes Schindelin
2007-08-06 21:51   ` Dmitry Kakurin
2007-08-06 21:55   ` Dmitry Kakurin
2007-08-06 21:56     ` Johannes Schindelin
2007-08-06 22:32       ` Dmitry Kakurin
2007-08-06 22:48         ` Johannes Schindelin

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).