Skip to content

Commit a8e8253

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 840c875 commit a8e8253

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
@@ -984,9 +984,9 @@ const char *remove_leading_path(const char *in, const char *prefix)
984984
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
985985
{
986986
char *dst0;
987-
int i;
987+
int i = has_unc_prefix(src);
988988

989-
for (i = has_dos_drive_prefix(src); i > 0; i--)
989+
for (i = i ? i : has_dos_drive_prefix(src); i > 0; i--)
990990
*dst++ = *src++;
991991
dst0 = dst;
992992

0 commit comments

Comments
 (0)