From 7095d5b33f4fda1c9e1dcd178dde1b773937aea3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 31 Aug 2015 12:57:45 +0000 Subject: [PATCH] mingw: support UNC alternates Just like we support having alternates pointing to different drives, we want to support alternates pointing to network shares, i.e. UNC paths. Technically, what we do in this patch is not to support UNC alternates, but to support UNC paths when normalizing paths. But the latter implies the former, and the former really was the motivation for this patch. Signed-off-by: Johannes Schindelin --- compat/mingw.h | 1 + git-compat-util.h | 8 ++++++++ path.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compat/mingw.h b/compat/mingw.h index 034fff9479..c41449aa54 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -395,6 +395,7 @@ HANDLE winansi_get_osfhandle(int fd); (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) int mingw_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix mingw_skip_dos_drive_prefix +#define has_unc_prefix(path) (*(path) == '\\' && (path)[1] == '\\' ? 2 : 0) #define is_dir_sep(c) ((c) == '/' || (c) == '\\') static inline char *mingw_find_last_dir_sep(const char *path) { diff --git a/git-compat-util.h b/git-compat-util.h index b4d9c2aa58..4dc7bff19e 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -346,6 +346,14 @@ static inline int git_skip_dos_drive_prefix(char **path) #define skip_dos_drive_prefix git_skip_dos_drive_prefix #endif +#ifndef has_unc_prefix +static inline int git_has_unc_prefix(const char *path) +{ + return 0; +} +#define has_unc_prefix git_has_unc_prefix +#endif + #ifndef is_dir_sep static inline int git_is_dir_sep(int c) { diff --git a/path.c b/path.c index fe3c4d96c6..f379bc50e2 100644 --- a/path.c +++ b/path.c @@ -986,9 +986,9 @@ const char *remove_leading_path(const char *in, const char *prefix) int normalize_path_copy_len(char *dst, const char *src, int *prefix_len) { char *dst0; - int i; + int i = has_unc_prefix(src); - for (i = has_dos_drive_prefix(src); i > 0; i--) + for (i = i ? i : has_dos_drive_prefix(src); i > 0; i--) *dst++ = *src++; dst0 = dst;