diff options
Diffstat (limited to 'abspath.c')
-rw-r--r-- | abspath.c | 30 |
1 files changed, 11 insertions, 19 deletions
@@ -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); } |