Skip to content

Commit 286eed9

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 bdae1f4 commit 286eed9

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
@@ -387,6 +387,7 @@ HANDLE winansi_get_osfhandle(int fd);
387387
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
388388
int mingw_skip_dos_drive_prefix(char **path);
389389
#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
390+
#define has_unc_prefix(path) (*(path) == '\\' && (path)[1] == '\\' ? 2 : 0)
390391
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
391392
static inline char *mingw_find_last_dir_sep(const char *path)
392393
{

git-compat-util.h

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

352+
#ifndef has_unc_prefix
353+
static inline int git_has_unc_prefix(const char *path)
354+
{
355+
return 0;
356+
}
357+
#define has_unc_prefix git_has_unc_prefix
358+
#endif
359+
352360
#ifndef is_dir_sep
353361
static inline int git_is_dir_sep(int c)
354362
{

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)