From 1f72afd86d043a61a80cb38f4f69fb5fc6befdc8 Mon Sep 17 00:00:00 2001 From: Cezary Zawadka Date: Tue, 13 Jul 2010 16:17:43 +0200 Subject: [PATCH] Allow using UNC path for git repository [efl: moved MinGW-specific part to compat/] [jes: fixed compilation on non-Windows] Signed-off-by: Cezary Zawadka Signed-off-by: Erik Faye-Lund Signed-off-by: Johannes Schindelin --- cache.h | 1 - compat/mingw.c | 48 +++++++++++++++++++++++------------------------ compat/mingw.h | 2 ++ git-compat-util.h | 4 ++++ path.c | 7 ------- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/cache.h b/cache.h index 2ab5dd45b2..02b7925d4b 100644 --- a/cache.h +++ b/cache.h @@ -788,7 +788,6 @@ int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, struct string_list *prefixes); char *strip_path_suffix(const char *path, const char *suffix); int daemon_avoid_alias(const char *path); -int offset_1st_component(const char *path); /* object replacement */ #define LOOKUP_REPLACE_OBJECT 1 diff --git a/compat/mingw.c b/compat/mingw.c index 13ec7eae29..385a9e766d 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1986,6 +1986,30 @@ const char *get_windows_home_directory(void) return home_directory; } + +int mingw_offset_1st_component(const char *path) +{ + if (has_dos_drive_prefix(path)) + return 2 + is_dir_sep(path[2]); + + /* unc paths */ + if (is_dir_sep(path[0]) && is_dir_sep(path[1])) { + + /* skip server name */ + char *pos = strpbrk(path + 2, "\\/"); + if (!pos) + return 0; + + do { + pos++; + } while (*pos && !is_dir_sep(*pos)); + + return pos - path; + } + + return is_dir_sep(path[0]); +} + int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen) { int upos = 0, wpos = 0; @@ -2175,27 +2199,3 @@ void mingw_startup() /* initialize Unicode console */ winansi_init(); } - -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 2a4a03e487..71a14be5a5 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -348,6 +348,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" diff --git a/git-compat-util.h b/git-compat-util.h index 20638e48db..93be2e0ee5 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -270,6 +270,10 @@ extern char *gitbasename(char *); #define has_dos_drive_prefix(path) 0 #endif +#ifndef offset_1st_component +#define offset_1st_component(path) (is_dir_sep((path)[0])) +#endif + #ifndef is_dir_sep #define is_dir_sep(c) ((c) == '/') #endif diff --git a/path.c b/path.c index a5bb08cc3b..09b362c951 100644 --- a/path.c +++ b/path.c @@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p) } } } - -int offset_1st_component(const char *path) -{ - if (has_dos_drive_prefix(path)) - return 2 + is_dir_sep(path[2]); - return is_dir_sep(path[0]); -}