{"thread":{"id":"9404","subject":"[MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","startedAt":"2007-08-06T09:44:49Z","lastAt":"2007-08-06T22:48:10Z","messageCount":7,"participants":["Dmitry Kakurin","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50002","messageId":"BD28FA320B7749FFBE3135FE92380BCE@ntdev.corp.microsoft.com","threadId":"9404","inReplyTo":null,"subject":"[MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Dmitry Kakurin","fromEmail":"dmitry.kakurin@gmail.com","sentAt":"2007-08-06T09:44:49Z","receivedAt":"2007-08-06T09:44:49Z","isPatch":true,"sender":{"key":"dmitry.kakurin@gmail.com","avatar":null},"body":"environment.c caches results of many getenv calls.\nUnder MinGW setenv(X) invalidates all previous values returned by getenv(X)\nso cached values become dangling pointers.\n\nAdded cache-aware function set_git_dir to complement get_git_dir\n\nSigned-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>\n---\n builtin-init-db.c |    4 +---\n cache.h           |    1 +\n environment.c     |    6 ++++++\n git.c             |    6 +++---\n path.c            |    2 +-\n setup.c           |    6 +++---\n 7 files changed, 21 insertions(+), 10 deletions(-)\n create mode 100644 config.mak\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 5c0feba..62e579d 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -344,9 +344,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n  /*\n   * Set up the default .git directory contents\n   */\n- git_dir = getenv(GIT_DIR_ENVIRONMENT);\n- if (!git_dir)\n-  git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n+ git_dir = get_git_dir();\n  safe_create_dir(git_dir, 0);\n \n  /* Check to see if the repository version is right.\ndiff --git a/cache.h b/cache.h\nindex 91e9f71..bc2916e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -210,6 +210,7 @@ extern int is_bare_repository(void);\n extern int is_inside_git_dir(void);\n extern int is_inside_work_tree(void);\n extern const char *get_git_dir(void);\n+extern void set_git_dir(const char *newDir);\n extern char *get_object_directory(void);\n extern char *get_refs_directory(void);\n extern char *get_index_file(void);\ndiff --git a/environment.c b/environment.c\nindex f83fb9e..6ea7088 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -80,6 +80,12 @@ const char *get_git_dir(void)\n  return git_dir;\n }\n \n+void set_git_dir(const char *newDir)\n+{\n+    setenv(GIT_DIR_ENVIRONMENT, newDir, 1);\n+    git_dir = NULL; // reset cache\n+}\n+\n char *get_object_directory(void)\n {\n  if (!git_object_dir)\ndiff --git a/git.c b/git.c\nindex 210a763..53dfa05 100644\n--- a/git.c\n+++ b/git.c\n@@ -67,14 +67,14 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)\n     fprintf(stderr, \"No directory given for --git-dir.\\n\" );\n     usage(git_usage_string);\n    }\n-   setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);\n+   set_git_dir( (*argv)[1] );\n    if (envchanged)\n     *envchanged = 1;\n    (*argv)++;\n    (*argc)--;\n    handled++;\n   } else if (!prefixcmp(cmd, \"--git-dir=\")) {\n-   setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);\n+   set_git_dir(cmd + 10);\n    if (envchanged)\n     *envchanged = 1;\n   } else if (!strcmp(cmd, \"--work-tree\")) {\n@@ -93,7 +93,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)\n     *envchanged = 1;\n   } else if (!strcmp(cmd, \"--bare\")) {\n    static char git_dir[PATH_MAX+1];\n-   setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);\n+   set_git_dir(getcwd(git_dir, sizeof(git_dir)));\n    if (envchanged)\n     *envchanged = 1;\n   } else {\ndiff --git a/path.c b/path.c\nindex 8a06cf7..14af033 100644\n--- a/path.c\n+++ b/path.c\n@@ -266,7 +266,7 @@ char *enter_repo(char *path, int strict)\n \n  if (access(\"objects\", X_OK) == 0 && access(\"refs\", X_OK) == 0 &&\n      validate_headref(\"HEAD\") == 0) {\n-  setenv(GIT_DIR_ENVIRONMENT, \".\", 1);\n+  set_git_dir(\".\");\n   check_repository_format();\n   return path;\n  }\ndiff --git a/setup.c b/setup.c\nindex 47cd790..c5cf3ea 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -292,7 +292,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n    }\n    die(\"Not a git repository\");\n   }\n-  setenv(GIT_DIR_ENVIRONMENT, cwd, 1);\n+  set_git_dir(cwd);\n   gitdirenv = getenv(GIT_DIR_ENVIRONMENT);\n   if (!gitdirenv)\n    die(\"getenv after setenv failed\");\n@@ -332,8 +332,8 @@ const char *setup_git_directory_gently(int *nongit_ok)\n   * In case there is a work tree we may change the directory,\n   * therefore make GIT_DIR an absolute path.\n   */\n- if ( !is_absolute_path( gitdirenv ) ) {\n-  setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);\n+ if (!is_absolute_path(gitdirenv)) {\n+  set_git_dir(gitdir);\n   gitdirenv = getenv(GIT_DIR_ENVIRONMENT);\n   if (!gitdirenv)\n    die(\"getenv after setenv failed\");\n-- \n1.5.3.GIT\n\n- Dmitry\n"},{"id":"50010","messageId":"Pine.LNX.4.64.0708061134380.14781@racer.site","threadId":"9404","inReplyTo":"BD28FA320B7749FFBE3135FE92380BCE@ntdev.corp.microsoft.com","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-06T10:42:42Z","receivedAt":"2007-08-06T10:42:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 6 Aug 2007, Dmitry Kakurin wrote:\n\n> environment.c caches results of many getenv calls. Under MinGW setenv(X) \n> invalidates all previous values returned by getenv(X) so cached values \n> become dangling pointers.\n> \n> Added cache-aware function set_git_dir to complement get_git_dir\n\nThe real problem here: mingw.git did not merge with upstream git.git in a \nlong time (mainly because its maintainer is on holiday).  In the meantime, \nset_git_dir() is already there!\n\nI had more problems than I thought with setting up a fork of mingw.git.  \nIt seems that the relative alternates path to mingw.git is followed, but \nnot that one from mingw.git to git.git.  So I could upload, but not fetch.\n\nSo I propose to use http://repo.or.cz/w/git/mingw4msysgit.git/ in the \nmeantime.  (Just give me your account name, and you'll be able to push to \nit.)\n\nBTW your patch was white-space mangled.\n\nCiao,\nDscho\n"},{"id":"50044","messageId":"a1bbc6950708061451o28272201w1713d8b8adfc695f@mail.gmail.com","threadId":"9404","inReplyTo":"Pine.LNX.4.64.0708061134380.14781@racer.site","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Dmitry Kakurin","fromEmail":"dmitry.kakurin@gmail.com","sentAt":"2007-08-06T21:51:59Z","receivedAt":"2007-08-06T21:51:59Z","isPatch":true,"sender":{"key":"dmitry.kakurin@gmail.com","avatar":null},"body":"On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> long time (mainly because its maintainer is on holiday).  In the meantime,\n> set_git_dir() is already there!\n\nI didn't know that.\n\n> BTW your patch was white-space mangled.\n\nI'll be sending patches as attachments from now on.\n\n- Dmitry\n"},{"id":"50045","messageId":"a1bbc6950708061455v459182cei3fb6b3b518d4b176@mail.gmail.com","threadId":"9404","inReplyTo":"Pine.LNX.4.64.0708061134380.14781@racer.site","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Dmitry Kakurin","fromEmail":"dmitry.kakurin@gmail.com","sentAt":"2007-08-06T21:55:09Z","receivedAt":"2007-08-06T21:55:09Z","isPatch":true,"sender":{"key":"dmitry.kakurin@gmail.com","avatar":null},"body":"On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> I had more problems than I thought with setting up a fork of mingw.git.\n> It seems that the relative alternates path to mingw.git is followed, but\n> not that one from mingw.git to git.git.  So I could upload, but not fetch.\n\nDoes it mean that fork of a fork does not work on repo.or.cz?\n\n- Dmitry\n"},{"id":"50046","messageId":"Pine.LNX.4.64.0708062255420.14781@racer.site","threadId":"9404","inReplyTo":"a1bbc6950708061455v459182cei3fb6b3b518d4b176@mail.gmail.com","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-06T21:56:26Z","receivedAt":"2007-08-06T21:56:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 6 Aug 2007, Dmitry Kakurin wrote:\n\n> On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > I had more problems than I thought with setting up a fork of mingw.git.\n> > It seems that the relative alternates path to mingw.git is followed, but\n> > not that one from mingw.git to git.git.  So I could upload, but not fetch.\n> \n> Does it mean that fork of a fork does not work on repo.or.cz?\n\nYes, at the moment it does not work.  Therefore I set up \ngit/mingw4msysgit.git, for the time being.\n\nCiao,\nDscho\n"},{"id":"50049","messageId":"a1bbc6950708061532t45fb0cf4w716971260b0640ae@mail.gmail.com","threadId":"9404","inReplyTo":"Pine.LNX.4.64.0708062255420.14781@racer.site","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Dmitry Kakurin","fromEmail":"dmitry.kakurin@gmail.com","sentAt":"2007-08-06T22:32:56Z","receivedAt":"2007-08-06T22:32:56Z","isPatch":true,"sender":{"key":"dmitry.kakurin@gmail.com","avatar":null},"body":"On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > Does it mean that fork of a fork does not work on repo.or.cz?\n>\n> Yes, at the moment it does not work.  Therefore I set up\n> git/mingw4msysgit.git, for the time being.\n\nThat's too bad.\nI was thinking about adopting distributed dev model for MinGW port of Git:\nwe all would fork off mingw.git on repo.or.cz and then we would pull\nfrom each other instead of exchanging patches thru e-mail.\nPersonally I don't like email patch exchange process.\n\nCan this problem on repo.or.cs be fixed? Did Petr reply?\n\n- Dmitry\n"},{"id":"50053","messageId":"Pine.LNX.4.64.0708062346120.14781@racer.site","threadId":"9404","inReplyTo":"a1bbc6950708061532t45fb0cf4w716971260b0640ae@mail.gmail.com","subject":"Re: [MinGW PATCH] git clone was failing with 'invalid object name HEAD' if ran from cmd.exe directly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-06T22:48:10Z","receivedAt":"2007-08-06T22:48:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 6 Aug 2007, Dmitry Kakurin wrote:\n\n> On 8/6/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> > > Does it mean that fork of a fork does not work on repo.or.cz?\n> >\n> > Yes, at the moment it does not work.  Therefore I set up \n> > git/mingw4msysgit.git, for the time being.\n> \n> That's too bad. I was thinking about adopting distributed dev model for \n> MinGW port of Git: we all would fork off mingw.git on repo.or.cz and \n> then we would pull from each other instead of exchanging patches thru \n> e-mail. Personally I don't like email patch exchange process.\n\nWe can still do that.  Just set up a fork of _git.git_, and initialise it \nwith mingw4msysgit.git.\n\n> Can this problem on repo.or.cs be fixed? Did Petr reply?\n\nI think it can.  But Pasky seems to be extraordinarily busy these days.  \nSo no, I got no reply besides a message on IRC that he'll try to do \nsomething about the situation tonight.\n\nCiao,\nDscho\n"}]}