diff --git a/compat/mingw.h b/compat/mingw.h index 790f2b866d..c8639c5e32 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -428,6 +428,7 @@ static inline int mingw_skip_dos_drive_prefix(char **path) return ret; } #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 7ea91942fe..2015bd96fc 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -347,6 +347,14 @@ static inline int git_skip_dos_drive_prefix(const 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 a0a3aff342..c4d8d21cb5 100644 --- a/path.c +++ b/path.c @@ -945,9 +945,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;