Skip to content

Commit af10e8b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4da43b commit af10e8b

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

abspath.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,15 @@ char *prefix_filename(const char *pfx, const char *arg)
251251
struct strbuf path = STRBUF_INIT;
252252
size_t pfx_len = pfx ? strlen(pfx) : 0;
253253

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))
262257
pfx_len = 0;
263-
else if (pfx_len)
258+
else
264259
strbuf_add(&path, pfx, pfx_len);
260+
265261
strbuf_addstr(&path, arg);
262+
#ifdef GIT_WINDOWS_NATIVE
266263
convert_slashes(path.buf + pfx_len);
267264
#endif
268265
return strbuf_detach(&path, NULL);

0 commit comments

Comments
 (0)