]> git.ipfire.org Git - thirdparty/git.git/blobdiff - abspath.c
grep: Add the option '--line-number'
[thirdparty/git.git] / abspath.c
index c91a29cb298a3ad792ff8745f3e8e0eb28d71678..ff140689ed2453809e7c3794c9989918e90df392 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -24,6 +24,10 @@ const char *make_absolute_path(const char *path)
        char *last_elem = NULL;
        struct stat st;
 
+       /* We've already done it */
+       if (path == buf || path == next_buf)
+               return path;
+
        if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
                die ("Too long path: %.*s", 60, path);
 
@@ -108,10 +112,14 @@ const char *make_nonrelative_path(const char *path)
                if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
                        die("Too long path: %.*s", 60, path);
        } else {
+               size_t len;
+               const char *fmt;
                const char *cwd = get_pwd_cwd();
                if (!cwd)
                        die_errno("Cannot determine the current working directory");
-               if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
+               len = strlen(cwd);
+               fmt = (len > 0 && is_dir_sep(cwd[len-1])) ? "%s%s" : "%s/%s";
+               if (snprintf(buf, PATH_MAX, fmt, cwd, path) >= PATH_MAX)
                        die("Too long path: %.*s", 60, path);
        }
        return buf;