Skip to content

Commit 4b2c954

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 662c605 commit 4b2c954

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
@@ -392,6 +392,7 @@ static inline int mingw_skip_dos_drive_prefix(char **path)
392392
return ret;
393393
}
394394
#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
395+
#define has_unc_prefix(path) (*(path) == '\\' && (path)[1] == '\\' ? 2 : 0)
395396
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
396397
static inline char *mingw_find_last_dir_sep(const char *path)
397398
{

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(const 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)