Re: [RFC] introduce GIT_WORK_DIR environment variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/11/07, Matthias Lederhofer <matled@xxxxxxx> wrote:
+               gitwd = getenv(GIT_WORKING_DIR_ENVIRONMENT);
+               if (!gitwd || stat(gitwd, &st_work))
                        return NULL;

I propose the following instead of the last two lines:

               if (!gitwd)
                       return NULL;
               if (stat(gitwd, &st_work))
                       die("Unable to stat git working directory %s",gitwd);

+               if (inside_git_dir == -1 && stat(gitdirenv, &st_git))
+                       die("Unable to stat git directory");
+               if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
+                       die("Unable to read current working directory");
+               len = strlen(cwd);
+
+               prefix = cwd+len;
+               for (;;) {
+                       c = *prefix;
+                       *prefix = '\0';
+                       if (stat(cwd, &st))
+                               die("Unable to stat '%s'", cwd);
+                       if (st_work.st_dev == st.st_dev &&
+                           st_work.st_ino == st.st_ino)
+                               break;
+                       if (inside_git_dir == -1 &&
+                           st_git.st_dev == st.st_dev &&
+                           st_git.st_ino == st.st_ino)
+                               inside_git_dir = 1;
+                       *prefix = c;
+
+                       if (prefix == cwd+1) {
+                               has_working_directory = 0;
+                               return NULL;

My case seems a bit complicated than usual. The working directory
(/home/pclouds/blog/data) was not a prefix of cwd (/home/pclouds/blog)
so the code failed silently at this line. If I replace
"has_working_directory = 0; return NULL;" with "strcpy(cwd,gitwd);c =
0;break;", it may work but see below

+                       }
+                       while (*(--prefix) != '/')
+                               ; /* do nothing */
+                       if (prefix == cwd)
+                               prefix++;
+               }
+
+               if (chdir(cwd))
+                       die("Cannot change directory to '%s'", cwd);
+

If cwd changed and GIT_DIR is a relative path, git can no longer
access GIT_DIR properly.
--
Duy
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]