]> git.ipfire.org Git - thirdparty/git.git/blobdiff - abspath.c
t9300: drop some useless uses of cat
[thirdparty/git.git] / abspath.c
index b02e068aa347db683b00246061b48bfafabbc1c0..708aff8d42c562112fe4076635af903c7f41fbaa 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -183,7 +183,7 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
 
                        /*
                         * use the symlink as the remaining components that
-                        * need to be resloved
+                        * need to be resolved
                         */
                        strbuf_swap(&symlink, &remaining);
                }
@@ -246,29 +246,21 @@ char *absolute_pathdup(const char *path)
        return strbuf_detach(&sb, NULL);
 }
 
-/*
- * Unlike prefix_path, this should be used if the named file does
- * not have to interact with index entry; i.e. name of a random file
- * on the filesystem.
- */
-const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
+char *prefix_filename(const char *pfx, const char *arg)
 {
-       static struct strbuf path = STRBUF_INIT;
-#ifndef GIT_WINDOWS_NATIVE
-       if (!pfx_len || is_absolute_path(arg))
-               return arg;
-       strbuf_reset(&path);
-       strbuf_add(&path, pfx, pfx_len);
-       strbuf_addstr(&path, arg);
-#else
-       /* don't add prefix to absolute paths, but still replace '\' by '/' */
-       strbuf_reset(&path);
-       if (is_absolute_path(arg))
+       struct strbuf path = STRBUF_INIT;
+       size_t pfx_len = pfx ? strlen(pfx) : 0;
+
+       if (!pfx_len)
+               ; /* nothing to prefix */
+       else if (is_absolute_path(arg))
                pfx_len = 0;
-       else if (pfx_len)
+       else
                strbuf_add(&path, pfx, pfx_len);
+
        strbuf_addstr(&path, arg);
+#ifdef GIT_WINDOWS_NATIVE
        convert_slashes(path.buf + pfx_len);
 #endif
-       return path.buf;
+       return strbuf_detach(&path, NULL);
 }