Skip to contentSkip to conversation

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

PATCH In review Dmitry Kakurin 2 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Added cache-aware function set_git_dir to complement get_git_dir

---

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

builtin-init-db.c +1 -3
index 5c0feba..62e579d 100644
@@ -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.
cache.h +0 -0
index 91e9f71..bc2916e 100644
@@ -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);

environment.c +0 -0
index f83fb9e..6ea7088 100644
@@ -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)

git.c +3 -3
index 210a763..53dfa05 100644
@@ -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 {
path.c +1 -1
index 8a06cf7..14af033 100644
@@ -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;
 }
setup.c +3 -3
index 47cd790..c5cf3ea 100644
@@ -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");
Signature · 3 lines
1.5.3.GIT

- Dmitry
#1 lore raw

Hi,

Quoted 5 lines · Dmitry Kakurin

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

#2 lore raw
Quoted 2 lines · Johannes Schindelin

long time (mainly because its maintainer is on holiday). In the meantime, set_git_dir() is already there!

I didn't know that.

Quoted 1 line

BTW your patch was white-space mangled.

I'll be sending patches as attachments from now on.

- Dmitry

#3 lore raw
In reply to Johannes Schindelin
Quoted 3 lines · Johannes Schindelin

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

#4 lore raw

Hi,

Quoted 6 lines · Dmitry Kakurin
Quoted 3 lines · Johannes Schindelin

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

#5 lore raw
Quoted 4 lines · Johannes Schindelin
Quoted 1 line

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

#6 lore raw

Hi,

Quoted 11 lines · Dmitry Kakurin
Quoted 4 lines · Johannes Schindelin
Quoted 1 line

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.

Quoted 1 line

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