/*
* use the symlink as the remaining components that
- * need to be resloved
+ * need to be resolved
*/
strbuf_swap(&symlink, &remaining);
}
return retval;
}
+/*
+ * Resolve `path` into an absolute, cleaned-up path. The return value
+ * comes from a shared buffer.
+ */
const char *real_path(const char *path)
{
static struct strbuf realpath = STRBUF_INIT;
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);
}