Merge branch 'sk/windows-unc-path'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 17:07:03 +0000 (10:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 17:07:03 +0000 (10:07 -0700)
* sk/windows-unc-path:
Windows: allow using UNC path for git repository

cache.h
compat/mingw.c
compat/mingw.h
git-compat-util.h
path.c
diff --git a/cache.h b/cache.h
index 1e4b4f06e1ee013db0cb696115ead61a76087f4e..cbe1935ba6b17b6ccc37a400ea7cf0f67830e1d0 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -826,7 +826,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
index e9892f8ee48db4739321d37726cff63dec8c0f13..a0e13bc862c052d8c18a6cba1c47a5a15fd12f7b 100644 (file)
@@ -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]);
+}
index e033e720c900c430a0a74b0223522c396cb66629..3eaf822e28e23e6e46e82a9bb7c9db1ed42d252c 100644 (file)
@@ -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"
index 7849d314051a1de351c9c985516135397042a091..b6f03b36dc762b891e77a5ca44e7ca5f270c5af9 100644 (file)
@@ -267,6 +267,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 f9c5062427e7d8170a1e2e597fcf22ae517a865e..bc804a31b3382e689dd6ff5b4a727b109a691f7a 100644 (file)
--- 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]);
-}