From 042a3ee04c52e19fba31577b04d7de5b294aab14 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 | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compat/mingw.h b/compat/mingw.h index 738865c6c0..d5ba56ac6f 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -359,6 +359,7 @@ HANDLE winansi_get_osfhandle(int fd); */ #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') +#define has_unc_prefix(path) (*(path) == '\\' && (path)[1] == '\\') #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 4fe10cc146..6af19397e5 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -335,6 +335,14 @@ static inline int git_has_dos_drive_prefix(const char *path) #define has_dos_drive_prefix git_has_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 56317a66be..e89d07f79f 100644 --- a/path.c +++ b/path.c @@ -704,7 +704,7 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len) { char *dst0; - if (has_dos_drive_prefix(src)) { + if (has_unc_prefix(src) || has_dos_drive_prefix(src)) { *dst++ = *src++; *dst++ = *src++; }