From: tboegi@web.de
To: git@vger.kernel.org
Cc: "Torsten Bögershausen" <tboegi@web.de>
Subject: [PATCH/RFC v1 1/1] cygwin: Allow pushing to UNC paths
Date: Wed, 28 Jun 2017 18:29:58 +0200 [thread overview]
Message-ID: <20170628162958.519-1-tboegi@web.de> (raw)
From: Torsten Bögershausen <tboegi@web.de>
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 are 2 problems:
- Git converts the leading "//" into a single "/".
- The remote repo is not accepted because setup.c calls
access(getenv(DB_ENVIRONMENT), X_OK)
and this call fails. In other words, checking the executable bit
of a directory mounted on a SAMBA share is not reliable (and not needed).
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.
- Use cygwin_access() with a relaxed test for the executable bit on
a directory pointed out by an UNC path.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
compat/cygwin.c | 29 +++++++++++++++++++++++++++++
compat/cygwin.h | 7 +++++++
config.mak.uname | 1 +
git-compat-util.h | 3 +++
t/t0060-path-utils.sh | 2 ++
5 files changed, 42 insertions(+)
create mode 100644 compat/cygwin.c
create mode 100644 compat/cygwin.h
diff --git a/compat/cygwin.c b/compat/cygwin.c
new file mode 100644
index 0000000..d98e877
--- /dev/null
+++ b/compat/cygwin.c
@@ -0,0 +1,29 @@
+#include "../git-compat-util.h"
+#include "../cache.h"
+
+int cygwin_offset_1st_component(const char *path)
+{
+ const char *pos = path;
+ /* unc paths */
+ if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
+ /* skip server name */
+ pos = strchr(pos + 2, '/');
+ if (!pos)
+ return 0; /* Error: malformed unc path */
+
+ do {
+ pos++;
+ } while (*pos && pos[0] != '/');
+ }
+ return pos + is_dir_sep(*pos) - path;
+}
+
+#undef access
+int cygwin_access(const char *filename, int mode)
+{
+ /* the execute bit does not work on SAMBA drives */
+ if (filename[0] == '/' && filename[1] == '/' )
+ return access(filename, mode & ~X_OK);
+ else
+ return access(filename, mode);
+}
diff --git a/compat/cygwin.h b/compat/cygwin.h
new file mode 100644
index 0000000..efa12ad
--- /dev/null
+++ b/compat/cygwin.h
@@ -0,0 +1,7 @@
+int cygwin_access(const char *filename, int mode);
+#undef access
+#define access cygwin_access
+
+
+int cygwin_offset_1st_component(const char *path);
+#define offset_1st_component cygwin_offset_1st_component
diff --git a/config.mak.uname b/config.mak.uname
index adfb90b..551e465 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -184,6 +184,7 @@ ifeq ($(uname_O),Cygwin)
UNRELIABLE_FSTAT = UnfortunatelyYes
SPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
+ COMPAT_OBJS += compat/cygwin.o
endif
ifeq ($(uname_S),FreeBSD)
NEEDS_LIBICONV = YesPlease
diff --git a/git-compat-util.h b/git-compat-util.h
index 047172d..db9c22d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -189,6 +189,9 @@
#include <sys/sysctl.h>
#endif
+#if defined(__CYGWIN__)
+#include "compat/cygwin.h"
+#endif
#if defined(__MINGW32__)
/* pull in Windows compatibility stuff */
#include "compat/mingw.h"
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 444b5a4..7ea2bb5 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -70,6 +70,8 @@ ancestor() {
case $(uname -s) in
*MINGW*)
;;
+*CYGWIN*)
+ ;;
*)
test_set_prereq POSIX
;;
--
2.10.0
next reply other threads:[~2017-06-28 16:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-28 16:29 tboegi [this message]
2017-06-28 17:40 ` [PATCH/RFC v1 1/1] cygwin: Allow pushing to UNC paths Junio C Hamano
2017-07-01 12:50 ` [PATCH v2 1/2] Check DB_ENVIRONMENT using is_directory() tboegi
2017-07-01 17:24 ` Junio C Hamano
2017-07-03 14:41 ` [PATCH v3 1/1] cygwin: Allow pushing to UNC paths tboegi
2017-07-05 21:14 ` Junio C Hamano
2017-07-01 12:50 ` [PATCH v2 2/2] " tboegi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170628162958.519-1-tboegi@web.de \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).