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>

Jeff King committed Mar 20, 2017 at 21:30 UTC af10e8b1559790d5c78fcc2a1aae5c42f3930a00
1 file changed +6 -9
abspath.c
+6 -9
@@ -251,18 +251,15 @@ char *prefix_filename(const char *pfx, const char *arg)
251 struct strbuf path = STRBUF_INIT;
252 size_t pfx_len = pfx ? strlen(pfx) : 0;
253
254 -#ifndef GIT_WINDOWS_NATIVE
255 - if (!pfx_len || is_absolute_path(arg))
256 - return xstrdup(arg);
257 - strbuf_add(&path, pfx, pfx_len);
258 - strbuf_addstr(&path, arg);
259 -#else
260 - /* don't add prefix to absolute paths, but still replace '\' by '/' */
261 - if (is_absolute_path(arg))
254 + if (!pfx_len)
255 + ; /* nothing to prefix */
256 + else if (is_absolute_path(arg))
257 pfx_len = 0;
263 - else if (pfx_len)
258 + else
259 strbuf_add(&path, pfx, pfx_len);
260 +
261 strbuf_addstr(&path, arg);
262 +#ifdef GIT_WINDOWS_NATIVE
263 convert_slashes(path.buf + pfx_len);
264 #endif
265 return strbuf_detach(&path, NULL);