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 <sunshine@sunshineco.com> Signed-off-by: Cezary Zawadka <czawadka@gmail.com> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Cezary Zawadka committed Jul 13, 2010 at 16:17 UTC c2369bdf7ff082d588c4a4efe280bc4a483d0192
5 files changed +30 -8
cache.h
-1
@@ -781,7 +781,6 @@ int normalize_path_copy(char *dst, const char *src);
781 int longest_ancestor_length(const char *path, struct string_list *prefixes);
782 char *strip_path_suffix(const char *path, const char *suffix);
783 int daemon_avoid_alias(const char *path);
784 -int offset_1st_component(const char *path);
784
785 /* object replacement */
786 #define LOOKUP_REPLACE_OBJECT 1
compat/mingw.c
+24
@@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)
1823 errno = EINVAL;
1824 return -1;
1825 }
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
+2
@@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
339 return ret;
340 }
341 #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
344 #define PATH_SEP ';'
345 #define PRIuMAX "I64u"
346 #define PRId64 "I64d"
git-compat-util.h
+4
@@ -270,6 +270,10 @@ extern char *gitbasename(char *);
270 #define has_dos_drive_prefix(path) 0
271 #endif
272
273 +#ifndef offset_1st_component
274 +#define offset_1st_component(path) (is_dir_sep((path)[0]))
275 +#endif
276 +
277 #ifndef is_dir_sep
278 #define is_dir_sep(c) ((c) == '/')
279 #endif
path.c
-7
@@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)
823 }
824 }
825 }
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 -}