cygwin: allow pushing to UNC paths

cygwin can use an UNC path like //server/share/repo $ cd //server/share/dir $ mkdir test $ cd test $ git init --bare However, when we try to push from a local Git repository to this repo, there is a problem: Git converts the leading "//" into a single "/". As cygwin handles an UNC path so well, Git can support them better: - Introduce cygwin_offset_1st_component() which keeps the leading "//", similar to what Git for Windows does. - Move CYGWIN out of the POSIX in the tests for path normalization in t0060 Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Jul 3, 2017 at 16:41 UTC 496f2569892273a142889193350ceb95b6019011
5 files changed +27
compat/cygwin.c new
+19
@@ -0,0 +1,19 @@
1 +#include "../git-compat-util.h"
2 +#include "../cache.h"
3 +
4 +int cygwin_offset_1st_component(const char *path)
5 +{
6 + const char *pos = path;
7 + /* unc paths */
8 + if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
9 + /* skip server name */
10 + pos = strchr(pos + 2, '/');
11 + if (!pos)
12 + return 0; /* Error: malformed unc path */
13 +
14 + do {
15 + pos++;
16 + } while (*pos && pos[0] != '/');
17 + }
18 + return pos + is_dir_sep(*pos) - path;
19 +}
compat/cygwin.h new
+2
@@ -0,0 +1,2 @@
1 +int cygwin_offset_1st_component(const char *path);
2 +#define offset_1st_component cygwin_offset_1st_component
config.mak.uname
+1
@@ -181,6 +181,7 @@ ifeq ($(uname_O),Cygwin)
181 UNRELIABLE_FSTAT = UnfortunatelyYes
182 SPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield
183 OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
184 + COMPAT_OBJS += compat/cygwin.o
185 endif
186 ifeq ($(uname_S),FreeBSD)
187 NEEDS_LIBICONV = YesPlease
git-compat-util.h
+3
@@ -189,6 +189,9 @@
189 #include <sys/sysctl.h>
190 #endif
191
192 +#if defined(__CYGWIN__)
193 +#include "compat/cygwin.h"
194 +#endif
195 #if defined(__MINGW32__)
196 /* pull in Windows compatibility stuff */
197 #include "compat/mingw.h"
t/t0060-path-utils.sh
+2
@@ -70,6 +70,8 @@ ancestor() {
70 case $(uname -s) in
71 *MINGW*)
72 ;;
73 +*CYGWIN*)
74 + ;;
75 *)
76 test_set_prereq POSIX
77 ;;