threads / patch / 9404

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

Subject: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

## tl;dr

7 messages between Aug 6, 2007 and Aug 6, 2007. Diffs are folded; open one to read it.

replies: 6people: 2as markdown or json

Dmitry Kakurin· Aug 6, 2007, 09:44 UTC · lore

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
Show changes to 6 files +15 −10

builtin-init-db.c, cache.h, environment.c, git.c, path.c, setup.c

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
Johannes Schindelin· Aug 6, 2007, 10:42 UTC · re: Dmitry Kakurin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

Hi,
On Mon, 6 Aug 2007, Dmitry Kakurin wrote:
Show 5 quoted lines
> 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

The real problem here: mingw.git did not merge with upstream git.git in a long time (mainly because its maintainer is on holiday). In the meantime, set_git_dir() is already there!

I had more problems than I thought with setting up a fork of mingw.git. It seems that the relative alternates path to mingw.git is followed, but not that one from mingw.git to git.git. So I could upload, but not fetch.

So I propose to use http://repo.or.cz/w/git/mingw4msysgit.git/ in the meantime. (Just give me your account name, and you'll be able to push to it.)

BTW your patch was white-space mangled.

Ciao, Dscho

Dmitry Kakurin· Aug 6, 2007, 21:51 UTC · re: Johannes Schindelin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> long time (mainly because its maintainer is on holiday).  In the meantime,
> set_git_dir() is already there!
I didn't know that.
> BTW your patch was white-space mangled.
I'll be sending patches as attachments from now on.
- Dmitry
Dmitry Kakurin· Aug 6, 2007, 21:55 UTC · re: Johannes Schindelin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> I had more problems than I thought with setting up a fork of mingw.git.
> It seems that the relative alternates path to mingw.git is followed, but
> not that one from mingw.git to git.git.  So I could upload, but not fetch.
Does it mean that fork of a fork does not work on repo.or.cz?
- Dmitry
Johannes Schindelin· Aug 6, 2007, 21:56 UTC · re: Dmitry Kakurin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

Hi,
On Mon, 6 Aug 2007, Dmitry Kakurin wrote:
Show 6 quoted lines
> On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > I had more problems than I thought with setting up a fork of mingw.git.
> > It seems that the relative alternates path to mingw.git is followed, but
> > not that one from mingw.git to git.git.  So I could upload, but not fetch.
> 
> Does it mean that fork of a fork does not work on repo.or.cz?

Yes, at the moment it does not work. Therefore I set up git/mingw4msysgit.git, for the time being.

Ciao, Dscho

Dmitry Kakurin· Aug 6, 2007, 22:32 UTC · re: Johannes Schindelin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > Does it mean that fork of a fork does not work on repo.or.cz?
>
> Yes, at the moment it does not work.  Therefore I set up
> git/mingw4msysgit.git, for the time being.

That's too bad. I was thinking about adopting distributed dev model for MinGW port of Git: we all would fork off mingw.git on repo.or.cz and then we would pull from each other instead of exchanging patches thru e-mail. Personally I don't like email patch exchange process.

Can this problem on repo.or.cs be fixed? Did Petr reply?
- Dmitry
Johannes Schindelin· Aug 6, 2007, 22:48 UTC · re: Dmitry Kakurin · lore

Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly

Hi,
On Mon, 6 Aug 2007, Dmitry Kakurin wrote:
Show 11 quoted lines
> On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> > > Does it mean that fork of a fork does not work on repo.or.cz?
> >
> > Yes, at the moment it does not work.  Therefore I set up 
> > git/mingw4msysgit.git, for the time being.
> 
> That's too bad. I was thinking about adopting distributed dev model for 
> MinGW port of Git: we all would fork off mingw.git on repo.or.cz and 
> then we would pull from each other instead of exchanging patches thru 
> e-mail. Personally I don't like email patch exchange process.

We can still do that. Just set up a fork of _git.git_, and initialise it with mingw4msysgit.git.

> Can this problem on repo.or.cs be fixed? Did Petr reply?

I think it can. But Pasky seems to be extraordinarily busy these days. So no, I got no reply besides a message on IRC that he'll try to do something about the situation tonight.

Ciao, Dscho

← back to recent threads