real_path(): properly handle nonexistent top-level paths

The change has two points:

1. Do not strip off a leading slash, because that erroneously turns an
   absolute path into a relative path.

2. Do not remove slashes from groups of multiple slashes; instead let
   chdir() handle them.  It could be, for example, that it wants to
   leave leading double-slashes alone.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty
2012-09-07 00:41:03 +02:00
committed by Junio C Hamano
parent 7bcf48dad8
commit f4c21e89d7
2 changed files with 2 additions and 2 deletions

View File

@ -45,8 +45,8 @@ const char *real_path(const char *path)
if (!is_directory(buf)) {
char *last_slash = find_last_dir_sep(buf);
if (last_slash) {
*last_slash = '\0';
last_elem = xstrdup(last_slash + 1);
last_slash[1] = '\0';
} else {
last_elem = xstrdup(buf);
*buf = '\0';