Skip to content

Commit

Permalink
Do not check if getcwd() result begins with a slash.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 4, 2007
1 parent 73616fd commit f66a4d6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (!gitdirenv) {
int len, offset;

if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");

offset = len = strlen(cwd);
Expand Down Expand Up @@ -271,7 +271,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Not a git repository: '%s'", gitdirenv);
}

if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");
if (chdir(gitdirenv)) {
if (nongit_ok) {
Expand All @@ -281,7 +281,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Cannot change directory to $%s '%s'",
GIT_DIR_ENVIRONMENT, gitdirenv);
}
if (!getcwd(gitdir, sizeof(gitdir)-1) || gitdir[0] != '/')
if (!getcwd(gitdir, sizeof(gitdir)-1))
die("Unable to read current working directory");
if (chdir(cwd))
die("Cannot come back to cwd");
Expand Down Expand Up @@ -340,7 +340,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Cannot change directory to working tree '%s'",
gitworktree);
}
if (!getcwd(worktree, sizeof(worktree)-1) || worktree[0] != '/')
if (!getcwd(worktree, sizeof(worktree)-1))
die("Unable to read current working directory");
strcat(worktree, "/");
inside_work_tree = !prefixcmp(cwd, worktree);
Expand Down

0 comments on commit f66a4d6

Please sign in to comment.