summaryrefslogtreecommitdiff
path: root/abspath.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-03-21 01:30:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-21 18:18:41 (GMT)
commitaf10e8b1559790d5c78fcc2a1aae5c42f3930a00 (patch)
tree3af9a091c1043fd65056d815c94419e914bdafcc /abspath.c
parente4da43b1f063d227b5f7d2922d27458748763a2d (diff)
downloadgit-af10e8b1559790d5c78fcc2a1aae5c42f3930a00.zip
git-af10e8b1559790d5c78fcc2a1aae5c42f3930a00.tar.gz
git-af10e8b1559790d5c78fcc2a1aae5c42f3930a00.tar.bz2
prefix_filename: simplify windows #ifdef
The prefix_filename function used to do an early return when there was no prefix on non-Windows platforms, but always allocated on Windows so that it could call convert_slashes(). Now that the function always allocates, we can unify the logic and make convert_slashes() the only conditional part. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'abspath.c')
-rw-r--r--abspath.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/abspath.c b/abspath.c
index 4addd1f..7f1cfe9 100644
--- a/abspath.c
+++ b/abspath.c
@@ -251,18 +251,15 @@ char *prefix_filename(const char *pfx, const char *arg)
struct strbuf path = STRBUF_INIT;
size_t pfx_len = pfx ? strlen(pfx) : 0;
-#ifndef GIT_WINDOWS_NATIVE
- if (!pfx_len || is_absolute_path(arg))
- return xstrdup(arg);
- strbuf_add(&path, pfx, pfx_len);
- strbuf_addstr(&path, arg);
-#else
- /* don't add prefix to absolute paths, but still replace '\' by '/' */
- if (is_absolute_path(arg))
+ 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 strbuf_detach(&path, NULL);