Skip to content

Commit 50877b3

Browse files
committed
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 <[email protected]>
1 parent 71cff51 commit 50877b3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

compat/mingw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ HANDLE winansi_get_osfhandle(int fd);
388388
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
389389
int mingw_skip_dos_drive_prefix(char **path);
390390
#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
391+
#define has_unc_prefix(path) (*(path) == '\\' && (path)[1] == '\\' ? 2 : 0)
391392
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
392393
static inline char *mingw_find_last_dir_sep(const char *path)
393394
{

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ static inline int git_skip_dos_drive_prefix(char **path)
346346
#define skip_dos_drive_prefix git_skip_dos_drive_prefix
347347
#endif
348348

349+
#ifndef has_unc_prefix
350+
static inline int git_has_unc_prefix(const char *path)
351+
{
352+
return 0;
353+
}
354+
#define has_unc_prefix git_has_unc_prefix
355+
#endif
356+
349357
#ifndef is_dir_sep
350358
static inline int git_is_dir_sep(int c)
351359
{

path.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,9 @@ const char *remove_leading_path(const char *in, const char *prefix)
943943
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
944944
{
945945
char *dst0;
946-
int i;
946+
int i = has_unc_prefix(src);
947947

948-
for (i = has_dos_drive_prefix(src); i > 0; i--)
948+
for (i = i ? i : has_dos_drive_prefix(src); i > 0; i--)
949949
*dst++ = *src++;
950950
dst0 = dst;
951951

0 commit comments

Comments
 (0)