From a8522726e67460ac75cc5f9fd0809d06865af09b 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 | 23 +++++++++++++++++++++++ compat/mingw.h | 2 ++ git-compat-util.h | 4 ++++ path.c | 7 ------- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cache.h b/cache.h index ade5df62f4..264628c88e 100644 --- a/cache.h +++ b/cache.h @@ -729,7 +729,6 @@ int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, const char *prefix_list); char *strip_path_suffix(const char *path, const char *suffix); int daemon_avoid_alias(const char *path); -int offset_1st_component(const char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); diff --git a/compat/mingw.c b/compat/mingw.c index 24f9f04fb2..ed03f434eb 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1785,3 +1785,26 @@ const char *get_windows_home_directory() 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]); +} diff --git a/compat/mingw.h b/compat/mingw.h index e259f35f5b..fbbb296cc4 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -284,6 +284,8 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') #define is_dir_sep(c) ((c) == '/' || (c) == '\\') +int mingw_offset_1st_component(const char *path); +#define offset_1st_component mingw_offset_1st_component #define PATH_SEP ';' #define PRIuMAX "I64u" diff --git a/git-compat-util.h b/git-compat-util.h index 78c823f259..15d32a1458 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -204,6 +204,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 1722be651d..9724e38914 100644 --- a/path.c +++ b/path.c @@ -655,10 +655,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]); -} -- 2.11.4.GIT