From c2369bdf7ff082d588c4a4efe280bc4a483d0192 Mon Sep 17 00:00:00 2001 From: Cezary Zawadka Date: Tue, 13 Jul 2010 16:17:43 +0200 Subject: 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 Signed-off-by: Cezary Zawadka Signed-off-by: Eric Sunshine Signed-off-by: Erik Faye-Lund Signed-off-by: Johannes Schindelin Signed-off-by: Stepan Kasal Signed-off-by: Junio C Hamano --- compat/mingw.c | 24 ++++++++++++++++++++++++ compat/mingw.h | 2 ++ 2 files changed, 26 insertions(+) (limited to 'compat') diff --git a/compat/mingw.c b/compat/mingw.c index e9892f8ee4..a0e13bc862 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options) errno = EINVAL; return -1; } + +int mingw_offset_1st_component(const char *path) +{ + int offset = 0; + if (has_dos_drive_prefix(path)) + offset = 2; + + /* unc paths */ + else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) { + + /* skip server name */ + char *pos = strpbrk(path + 2, "\\/"); + if (!pos) + return 0; /* Error: malformed unc path */ + + do { + pos++; + } while (*pos && !is_dir_sep(*pos)); + + offset = pos - path; + } + + return offset + is_dir_sep(path[offset]); +} diff --git a/compat/mingw.h b/compat/mingw.h index e033e720c9..3eaf822e28 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path) return ret; } #define find_last_dir_sep mingw_find_last_dir_sep +int mingw_offset_1st_component(const char *path); +#define offset_1st_component mingw_offset_1st_component #define PATH_SEP ';' #define PRIuMAX "I64u" #define PRId64 "I64d" -- cgit v1.2.3