[PATCH] Handle UNC paths everywhere
From: Robin Rosenberg <hidden>
Date: 2016-06-15 22:48:05
Subsystem:
the rest · Maintainer:
Linus Torvalds
From 37a74ccd395d91e5662665ca49d7f4ec49811de0 Mon Sep 17 00:00:00 2001
From: Robin Rosenberg <redacted> Date: Mon, 25 Jan 2010 01:41:03 +0100 Subject: [PATCH] Handle UNC paths everywhere In Windows paths beginning with // are knows as UNC paths. They are absolute paths, usually referring to a shared resource on a server. Examples of legal UNC paths \\hub\repos\repo \\?\unc\hub\repos \\?\d:\repo Signed-off-by: Robin Rosenberg <redacted> --- cache.h | 2 +- compat/basename.c | 2 +- compat/mingw.h | 8 +++++++- connect.c | 2 +- git-compat-util.h | 9 +++++++++ path.c | 2 +- setup.c | 2 +- sha1_file.c | 20 ++++++++++++++++++++ transport.c | 2 +- 9 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/cache.h b/cache.h
index 767a50e..8f63640 100644
--- a/cache.h
+++ b/cache.h@@ -648,7 +648,7 @@ int safe_create_leading_directories_const(const char *path);
char *enter_repo(char *path, int strict);
static inline int is_absolute_path(const char *path)
{
- return path[0] == '/' || has_dos_drive_prefix(path);
+ return path[0] == '/' || has_win32_abs_prefix(path);
}
int is_directory(const char *);
const char *make_absolute_path(const char *path);diff --git a/compat/basename.c b/compat/basename.c
index d8f8a3c..c1d81f6 100644
--- a/compat/basename.c
+++ b/compat/basename.c@@ -5,7 +5,7 @@ char *gitbasename (char *path) { const char *base; /* Skip over the disk name in MSDOS pathnames. */ - if (has_dos_drive_prefix(path)) + if (has_win32_abs_prefix(path)) path += 2; for (base = path; *path; path++) { if (is_dir_sep(*path))
diff --git a/compat/mingw.h b/compat/mingw.h
index 1b528da..d1aa8be 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h@@ -210,7 +210,13 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format * git specific compatibility */ -#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') +#define has_dos_drive_prefix(path) \ + (isalpha(*(path)) && (path)[1] == ':') +#define has_unc_prefix(path) \ + (is_dir_sep((path)[0]) && is_dir_sep((path)[1])) +#define has_win32_abs_prefix(path) \ + (has_dos_drive_prefix(path) || has_unc_prefix(path)) + #define is_dir_sep(c) ((c) == '/' || (c) == '\\') #define PATH_SEP ';' #define PRIuMAX "I64u"
diff --git a/connect.c b/connect.c
index 7945e38..9d4556c 100644
--- a/connect.c
+++ b/connect.c@@ -535,7 +535,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
end = host;
path = strchr(end, c);
- if (path && !has_dos_drive_prefix(end)) {
+ if (path && !has_win32_abs_prefix(end)) {
if (c == ':') {
protocol = PROTO_SSH;
*path++ = '\0';diff --git a/git-compat-util.h b/git-compat-util.h
index ef60803..0de9dac 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h@@ -170,6 +170,15 @@ extern char *gitbasename(char *); #define has_dos_drive_prefix(path) 0 #endif +#ifndef has_unc_prefix +#define has_unc_prefix(path) 0 +#endif + +#ifndef has_win32_abs_prefix +#error no abs +#define has_win32_abs_prefix(path) 0 +#endif + #ifndef is_dir_sep #define is_dir_sep(c) ((c) == '/') #endif
diff --git a/path.c b/path.c
index 047fdb0..79451a2 100644
--- a/path.c
+++ b/path.c@@ -409,7 +409,7 @@ int normalize_path_copy(char *dst, const char *src) { char *dst0; - if (has_dos_drive_prefix(src)) { + if (has_win32_abs_prefix(src)) { *dst++ = *src++; *dst++ = *src++; }
diff --git a/setup.c b/setup.c
index 029371e..4f72817 100644
--- a/setup.c
+++ b/setup.c@@ -342,7 +342,7 @@ const char *setup_git_directory_gently(int *nongit_ok) die_errno("Unable to read current working directory"); ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs); - if (ceil_offset < 0 && has_dos_drive_prefix(cwd)) + if (ceil_offset < 0 && has_win32_abs_prefix(cwd)) ceil_offset = 1; /*
diff --git a/sha1_file.c b/sha1_file.c
index 4cc8939..f1ad3f5 100644
--- a/sha1_file.c
+++ b/sha1_file.c@@ -87,6 +87,26 @@ static inline int offset_1st_component(const char *path) { if (has_dos_drive_prefix(path)) return 2 + (path[2] == '/'); + if (has_unc_prefix(path)) { + int p = 2; + int skip; + if (path[p] == '?') { + if (path[p+1] && !has_dos_drive_prefix(path+p+2)) { + skip = 3; + } else { + skip = 2; + } + } else + skip = 2; + + while (skip && path[p]) { + if (is_dir_sep(path[p])) + --skip; + ++p; + } + printf("Left with %s\n", path+p); + return p; + } return *path == '/'; }
diff --git a/transport.c b/transport.c
index 644a30a..9f5b24e 100644
--- a/transport.c
+++ b/transport.c@@ -797,7 +797,7 @@ static int is_local(const char *url) const char *colon = strchr(url, ':'); const char *slash = strchr(url, '/'); return !colon || (slash && slash < colon) || - has_dos_drive_prefix(url); + has_win32_abs_prefix(url); } static int is_file(const char *url)
--
1.6.4.msysgit.0.598.g37a74