зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
e4da43b1f0
Коммит
af10e8b155
15
abspath.c
15
abspath.c
|
@ -251,18 +251,15 @@ char *prefix_filename(const char *pfx, const char *arg)
|
||||||
struct strbuf path = STRBUF_INIT;
|
struct strbuf path = STRBUF_INIT;
|
||||||
size_t pfx_len = pfx ? strlen(pfx) : 0;
|
size_t pfx_len = pfx ? strlen(pfx) : 0;
|
||||||
|
|
||||||
#ifndef GIT_WINDOWS_NATIVE
|
if (!pfx_len)
|
||||||
if (!pfx_len || is_absolute_path(arg))
|
; /* nothing to prefix */
|
||||||
return xstrdup(arg);
|
else if (is_absolute_path(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))
|
|
||||||
pfx_len = 0;
|
pfx_len = 0;
|
||||||
else if (pfx_len)
|
else
|
||||||
strbuf_add(&path, pfx, pfx_len);
|
strbuf_add(&path, pfx, pfx_len);
|
||||||
|
|
||||||
strbuf_addstr(&path, arg);
|
strbuf_addstr(&path, arg);
|
||||||
|
#ifdef GIT_WINDOWS_NATIVE
|
||||||
convert_slashes(path.buf + pfx_len);
|
convert_slashes(path.buf + pfx_len);
|
||||||
#endif
|
#endif
|
||||||
return strbuf_detach(&path, NULL);
|
return strbuf_detach(&path, NULL);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче