Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6c536a9

Browse files
czawadkakasal
authored andcommitted
Windows: Allow using UNC path for git repository
[efl: moved MinGW-specific part to compat/] [jes: fixed compilation on non-Windows] Eric Sunshine fixed mingw_offset_1st_component() to return consistently "foo" for UNC "//machine/share/foo", cf http://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0 Author: Eric Sunshine <[email protected]> Signed-off-by: Cezary Zawadka <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Erik Faye-Lund <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Stepan Kasal <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c896851 commit 6c536a9

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ int normalize_path_copy(char *dst, const char *src);
809809
int longest_ancestor_length(const char *path, struct string_list *prefixes);
810810
char *strip_path_suffix(const char *path, const char *suffix);
811811
int daemon_avoid_alias(const char *path);
812-
int offset_1st_component(const char *path);
813812

814813
/* object replacement */
815814
#define LOOKUP_REPLACE_OBJECT 1

compat/mingw.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)
18231823
errno = EINVAL;
18241824
return -1;
18251825
}
1826+
1827+
int mingw_offset_1st_component(const char *path)
1828+
{
1829+
int offset = 0;
1830+
if (has_dos_drive_prefix(path))
1831+
offset = 2;
1832+
1833+
/* unc paths */
1834+
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
1835+
1836+
/* skip server name */
1837+
char *pos = strpbrk(path + 2, "\\/");
1838+
if (!pos)
1839+
return 0; /* Error: malformed unc path */
1840+
1841+
do {
1842+
pos++;
1843+
} while (*pos && !is_dir_sep(*pos));
1844+
1845+
offset = pos - path;
1846+
}
1847+
1848+
return offset + is_dir_sep(path[offset]);
1849+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
339339
return ret;
340340
}
341341
#define find_last_dir_sep mingw_find_last_dir_sep
342+
int mingw_offset_1st_component(const char *path);
343+
#define offset_1st_component mingw_offset_1st_component
342344
#define PATH_SEP ';'
343345
#define PRIuMAX "I64u"
344346
#define PRId64 "I64d"

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ extern char *gitbasename(char *);
267267
#define has_dos_drive_prefix(path) 0
268268
#endif
269269

270+
#ifndef offset_1st_component
271+
#define offset_1st_component(path) (is_dir_sep((path)[0]))
272+
#endif
273+
270274
#ifndef is_dir_sep
271275
#define is_dir_sep(c) ((c) == '/')
272276
#endif

path.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)
823823
}
824824
}
825825
}
826-
827-
int offset_1st_component(const char *path)
828-
{
829-
if (has_dos_drive_prefix(path))
830-
return 2 + is_dir_sep(path[2]);
831-
return is_dir_sep(path[0]);
832-
}

0 commit comments

Comments
 (0)