Skip to content

Commit 1060ab5

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 692260f commit 1060ab5

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
@@ -345,6 +345,14 @@ static inline int git_skip_dos_drive_prefix(char **path)
345345
#define skip_dos_drive_prefix git_skip_dos_drive_prefix
346346
#endif
347347

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

path.c

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

945-
for (i = has_dos_drive_prefix(src); i > 0; i--)
945+
for (i = i ? i : has_dos_drive_prefix(src); i > 0; i--)
946946
*dst++ = *src++;
947947
dst0 = dst;
948948

0 commit comments

Comments
 (0)