@matheusbsbs / matheus-bagliano / commits / f66a4d68d2
Fork 0

Do not check if getcwd() result begins with a slash.

In user space, and for getcwd(), the check to see if the resulting path begins with a '/' does not make sense. This is merely a mistake by Linus who is so used to code for the kernel, where a d_path() return value pathname can be either a real path, or something like "pipe:[8003]", and the difference is the '/' at the beginning. Pointed out by Dscho, Matthias Lederhofer and clarified by Linus. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 4, 2007 at 12:45 UTC f66a4d68d2066998605f5910c3c8dd1e4a25fc7f
1 file changed +4 -4
setup.c
+4 -4
@@ -211,7 +211,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
211 if (!gitdirenv) {
212 int len, offset;
213
214 - if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
214 + if (!getcwd(cwd, sizeof(cwd)-1))
215 die("Unable to read current working directory");
216
217 offset = len = strlen(cwd);
@@ -271,7 +271,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
271 die("Not a git repository: '%s'", gitdirenv);
272 }
273
274 - if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
274 + if (!getcwd(cwd, sizeof(cwd)-1))
275 die("Unable to read current working directory");
276 if (chdir(gitdirenv)) {
277 if (nongit_ok) {
@@ -281,7 +281,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
281 die("Cannot change directory to $%s '%s'",
282 GIT_DIR_ENVIRONMENT, gitdirenv);
283 }
284 - if (!getcwd(gitdir, sizeof(gitdir)-1) || gitdir[0] != '/')
284 + if (!getcwd(gitdir, sizeof(gitdir)-1))
285 die("Unable to read current working directory");
286 if (chdir(cwd))
287 die("Cannot come back to cwd");
@@ -340,7 +340,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
340 die("Cannot change directory to working tree '%s'",
341 gitworktree);
342 }
343 - if (!getcwd(worktree, sizeof(worktree)-1) || worktree[0] != '/')
343 + if (!getcwd(worktree, sizeof(worktree)-1))
344 die("Unable to read current working directory");
345 strcat(worktree, "/");
346 inside_work_tree = !prefixcmp(cwd, worktree);