summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Cezary Zawadka <czawadka@gmail.com>2010-07-13 16:17:43 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-06-10 13:30:04 -0700
commitc2369bdf7ff082d588c4a4efe280bc4a483d0192 (patch)
treeb3c9ae8d45b436eaff9c8b4c7e6cde5a0d916168
parentGit 1.9.3 (diff)
downloadtgif-c2369bdf7ff082d588c4a4efe280bc4a483d0192.tar.xz
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>
-rw-r--r--cache.h1
-rw-r--r--compat/mingw.c24
-rw-r--r--compat/mingw.h2
-rw-r--r--git-compat-util.h4
-rw-r--r--path.c7
5 files changed, 30 insertions, 8 deletions
diff --git a/cache.h b/cache.h
index ebe9a405d8..0961fb5c7a 100644
--- a/cache.h
+++ b/cache.h
@@ -781,7 +781,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 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"
diff --git a/git-compat-util.h b/git-compat-util.h
index d493a8c67a..ec41cfb23c 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 f9c5062427..bc804a31b3 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]);
-}