{"thread":{"id":"46278","subject":"[PATCH/RFC v1 1/1] cygwin: Allow pushing to UNC paths","startedAt":"2017-06-28T16:30:08Z","lastAt":"2017-07-05T21:14:25Z","messageCount":7,"participants":["tboegi@web.de","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"323430","messageId":"20170628162958.519-1-tboegi@web.de","threadId":"46278","inReplyTo":null,"subject":"[PATCH/RFC v1 1/1] cygwin: Allow pushing to UNC paths","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2017-06-28T16:29:58Z","receivedAt":"2017-06-28T16:30:08Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\ncygwin can use an UNC path like //server/share/repo\n$ cd //server/share/dir\n$ mkdir test\n$ cd test\n$ git init --bare\n\nHowever, when we try to push from a local Git repository to this repo,\nthere are 2 problems:\n- Git converts the leading \"//\" into a single \"/\".\n- The remote repo is not accepted because setup.c calls\n  access(getenv(DB_ENVIRONMENT), X_OK)\n  and this call fails. In other words, checking the executable bit\n  of a directory mounted on a SAMBA share is not reliable (and not needed).\n\nAs cygwin handles an UNC path so well, Git can support them better.\n- Introduce cygwin_offset_1st_component() which keeps the leading \"//\",\n  similar to what Git for Windows does.\n- Move CYGWIN out of the POSIX in the tests for path normalization in t0060.\n- Use cygwin_access() with a relaxed test for the executable bit on\n  a directory pointed out by an UNC path.\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n compat/cygwin.c       | 29 +++++++++++++++++++++++++++++\n compat/cygwin.h       |  7 +++++++\n config.mak.uname      |  1 +\n git-compat-util.h     |  3 +++\n t/t0060-path-utils.sh |  2 ++\n 5 files changed, 42 insertions(+)\n create mode 100644 compat/cygwin.c\n create mode 100644 compat/cygwin.h\n\ndiff --git a/compat/cygwin.c b/compat/cygwin.c\nnew file mode 100644\nindex 0000000..d98e877\n--- /dev/null\n+++ b/compat/cygwin.c\n@@ -0,0 +1,29 @@\n+#include \"../git-compat-util.h\"\n+#include \"../cache.h\"\n+\n+int cygwin_offset_1st_component(const char *path)\n+{\n+\tconst char *pos = path;\n+\t/* unc paths */\n+\tif (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {\n+\t\t/* skip server name */\n+\t\tpos = strchr(pos + 2, '/');\n+\t\tif (!pos)\n+\t\t\treturn 0; /* Error: malformed unc path */\n+\n+\t\tdo {\n+\t\t\tpos++;\n+\t\t} while (*pos && pos[0] != '/');\n+\t}\n+\treturn pos + is_dir_sep(*pos) - path;\n+}\n+\n+#undef access\n+int cygwin_access(const char *filename, int mode)\n+{\n+\t/* the execute bit does not work on SAMBA drives */\n+\tif (filename[0] == '/' && filename[1] == '/' )\n+\t\treturn access(filename, mode & ~X_OK);\n+\telse\n+\t\treturn access(filename, mode);\n+}\ndiff --git a/compat/cygwin.h b/compat/cygwin.h\nnew file mode 100644\nindex 0000000..efa12ad\n--- /dev/null\n+++ b/compat/cygwin.h\n@@ -0,0 +1,7 @@\n+int cygwin_access(const char *filename, int mode);\n+#undef access\n+#define access cygwin_access\n+\n+\n+int cygwin_offset_1st_component(const char *path);\n+#define offset_1st_component cygwin_offset_1st_component\ndiff --git a/config.mak.uname b/config.mak.uname\nindex adfb90b..551e465 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -184,6 +184,7 @@ ifeq ($(uname_O),Cygwin)\n \tUNRELIABLE_FSTAT = UnfortunatelyYes\n \tSPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield\n \tOBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo\n+\tCOMPAT_OBJS += compat/cygwin.o\n endif\n ifeq ($(uname_S),FreeBSD)\n \tNEEDS_LIBICONV = YesPlease\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 047172d..db9c22d 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -189,6 +189,9 @@\n #include <sys/sysctl.h>\n #endif\n \n+#if defined(__CYGWIN__)\n+#include \"compat/cygwin.h\"\n+#endif\n #if defined(__MINGW32__)\n /* pull in Windows compatibility stuff */\n #include \"compat/mingw.h\"\ndiff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh\nindex 444b5a4..7ea2bb5 100755\n--- a/t/t0060-path-utils.sh\n+++ b/t/t0060-path-utils.sh\n@@ -70,6 +70,8 @@ ancestor() {\n case $(uname -s) in\n *MINGW*)\n \t;;\n+*CYGWIN*)\n+\t;;\n *)\n \ttest_set_prereq POSIX\n \t;;\n-- \n2.10.0\n\n"},{"id":"323435","messageId":"xmqqefu4vwn0.fsf@gitster.mtv.corp.google.com","threadId":"46278","inReplyTo":"20170628162958.519-1-tboegi@web.de","subject":"Re: [PATCH/RFC v1 1/1] cygwin: Allow pushing to UNC paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-06-28T17:40:19Z","receivedAt":"2017-06-28T17:40:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> cygwin can use an UNC path like //server/share/repo\n> $ cd //server/share/dir\n> $ mkdir test\n> $ cd test\n> $ git init --bare\n>\n> However, when we try to push from a local Git repository to this repo,\n> there are 2 problems:\n> - Git converts the leading \"//\" into a single \"/\".\n> - The remote repo is not accepted because setup.c calls\n>   access(getenv(DB_ENVIRONMENT), X_OK)\n>   and this call fails. In other words, checking the executable bit\n>   of a directory mounted on a SAMBA share is not reliable (and not needed).\n>\n> As cygwin handles an UNC path so well, Git can support them better.\n> - Introduce cygwin_offset_1st_component() which keeps the leading \"//\",\n>   similar to what Git for Windows does.\n> - Move CYGWIN out of the POSIX in the tests for path normalization in t0060.\n> - Use cygwin_access() with a relaxed test for the executable bit on\n>   a directory pointed out by an UNC path.\n\nThanks.\n\nThe offset-1st-component thing looks like a right thing to do.\n\nI think the reason why you marked this as RFC is because you found\nthe \"access\" bit a bit iffy?  If so, I share the feeling.  If it\nwere called only from the codepath in setup.c::is_git_directory(),\nit may be OK, but I suspect that there are other places that do care\nabout access() for other reasons in the codebase, and I am not sure\nif it is safe to change the behaviour of access() like this.\n\nStepping back a bit.\n\nThe implementation of is_git_directory() wants to ensure that the\ntop level of the object database (i.e.  $GIT_OBJECT_DIRECTORY or\n$GIT_DIR/objects) and the reference store (i.e. $GIT_DIR/refs) can\nbe \"executed\".  But what it really wants to see is that it is a\ndirectory we can search.  If we had a regular file that is executable,\nit would happily say \"Yes!\", even though that is clearly bogus and\nnot a Git repository.\n\nSo perhaps we would want a bit higher-level abstraction API\nimplemented as:\n\n\tint is_searchable_directory(const char *path)\n\t{\n\t\tstruct stat st;\n\n\t        return (!stat(path, &st) && S_ISDIR(st.st_mode));\n\t}\n\non Cygwin (as SMB share may not give you correct access(2)), and\n\n\tint is_searchable_directory(const char *path)\n\t{\n\t\tstruct stat st;\n\n\t        return (!stat(path, &st) && \n\t\t\tS_ISDIR(st.st_mode) &&\n\t\t\t!access(path, X_OK));\n\t}\n\nelsewhere, or something like that, and use that in the\nimplementation of is_git_directory()?\n\nI dunno.  I see compat/mingw.c discards X_OK the same way you did,\nso perhaps your version is a right solution at least in the shorter\nterm anyway.  \n\nRegardless, I think that we would want to make sure that the thing\nis a directory where is_git_directory() uses access(2).  But that\ncould be an orthogonal issue.\n\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> ---\n>  compat/cygwin.c       | 29 +++++++++++++++++++++++++++++\n>  compat/cygwin.h       |  7 +++++++\n>  config.mak.uname      |  1 +\n>  git-compat-util.h     |  3 +++\n>  t/t0060-path-utils.sh |  2 ++\n>  5 files changed, 42 insertions(+)\n>  create mode 100644 compat/cygwin.c\n>  create mode 100644 compat/cygwin.h\n>\n> diff --git a/compat/cygwin.c b/compat/cygwin.c\n> new file mode 100644\n> index 0000000..d98e877\n> --- /dev/null\n> +++ b/compat/cygwin.c\n> @@ -0,0 +1,29 @@\n> +#include \"../git-compat-util.h\"\n> +#include \"../cache.h\"\n> +\n> +int cygwin_offset_1st_component(const char *path)\n> +{\n> +\tconst char *pos = path;\n> +\t/* unc paths */\n> +\tif (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {\n> +\t\t/* skip server name */\n> +\t\tpos = strchr(pos + 2, '/');\n> +\t\tif (!pos)\n> +\t\t\treturn 0; /* Error: malformed unc path */\n> +\n> +\t\tdo {\n> +\t\t\tpos++;\n> +\t\t} while (*pos && pos[0] != '/');\n> +\t}\n> +\treturn pos + is_dir_sep(*pos) - path;\n> +}\n> +\n> +#undef access\n> +int cygwin_access(const char *filename, int mode)\n> +{\n> +\t/* the execute bit does not work on SAMBA drives */\n> +\tif (filename[0] == '/' && filename[1] == '/' )\n> +\t\treturn access(filename, mode & ~X_OK);\n> +\telse\n> +\t\treturn access(filename, mode);\n> +}\n> diff --git a/compat/cygwin.h b/compat/cygwin.h\n> new file mode 100644\n> index 0000000..efa12ad\n> --- /dev/null\n> +++ b/compat/cygwin.h\n> @@ -0,0 +1,7 @@\n> +int cygwin_access(const char *filename, int mode);\n> +#undef access\n> +#define access cygwin_access\n> +\n> +\n> +int cygwin_offset_1st_component(const char *path);\n> +#define offset_1st_component cygwin_offset_1st_component\n> diff --git a/config.mak.uname b/config.mak.uname\n> index adfb90b..551e465 100644\n> --- a/config.mak.uname\n> +++ b/config.mak.uname\n> @@ -184,6 +184,7 @@ ifeq ($(uname_O),Cygwin)\n>  \tUNRELIABLE_FSTAT = UnfortunatelyYes\n>  \tSPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield\n>  \tOBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo\n> +\tCOMPAT_OBJS += compat/cygwin.o\n>  endif\n>  ifeq ($(uname_S),FreeBSD)\n>  \tNEEDS_LIBICONV = YesPlease\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 047172d..db9c22d 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -189,6 +189,9 @@\n>  #include <sys/sysctl.h>\n>  #endif\n>  \n> +#if defined(__CYGWIN__)\n> +#include \"compat/cygwin.h\"\n> +#endif\n>  #if defined(__MINGW32__)\n>  /* pull in Windows compatibility stuff */\n>  #include \"compat/mingw.h\"\n> diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh\n> index 444b5a4..7ea2bb5 100755\n> --- a/t/t0060-path-utils.sh\n> +++ b/t/t0060-path-utils.sh\n> @@ -70,6 +70,8 @@ ancestor() {\n>  case $(uname -s) in\n>  *MINGW*)\n>  \t;;\n> +*CYGWIN*)\n> +\t;;\n>  *)\n>  \ttest_set_prereq POSIX\n>  \t;;\n"},{"id":"323673","messageId":"20170701125057.16169-1-tboegi@web.de","threadId":"46278","inReplyTo":"20170628162958.519-1-tboegi@web.de","subject":"[PATCH v2 1/2] Check DB_ENVIRONMENT using is_directory()","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2017-07-01T12:50:57Z","receivedAt":"2017-07-01T12:51:06Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nIn setup.c is_git_directory() checks a Git directory using access(X_OK).\nThis does not check, if path is a file or a directory.\nCheck path with is_directory() instead.\n---\nAfter all the discussions (and lots of tests) I found that this patch\nworks for my setup.\nAll in all could the error reporting be improvved for is_git_directory(),\nas there may be \"access denied\", or \"not a directory\" or others, but\nthat is for another day.\n\nsetup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 358fbc2..5a7ee2e 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -321,7 +321,7 @@ int is_git_directory(const char *suspect)\n \n \t/* Check non-worktree-related signatures */\n \tif (getenv(DB_ENVIRONMENT)) {\n-\t\tif (access(getenv(DB_ENVIRONMENT), X_OK))\n+\t\tif (!is_directory(getenv(DB_ENVIRONMENT)))\n \t\t\tgoto done;\n \t}\n \telse {\n-- \n2.10.0\n\n"},{"id":"323674","messageId":"20170701125059.16210-1-tboegi@web.de","threadId":"46278","inReplyTo":"20170628162958.519-1-tboegi@web.de","subject":"[PATCH v2 2/2] cygwin: Allow pushing to UNC paths","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2017-07-01T12:50:59Z","receivedAt":"2017-07-01T12:51:12Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\n cygwin can use an UNC path like //server/share/repo\n $ cd //server/share/dir\n $ mkdir test\n $ cd test\n $ git init --bare\n\n However, when we try to push from a local Git repository to this repo,\n there is a problem: Git converts the leading \"//\" into a single \"/\".\n\n As cygwin handles an UNC path so well, Git can support them better:\n - Introduce cygwin_offset_1st_component() which keeps the leading \"//\",\n   similar to what Git for Windows does.\n - Move CYGWIN out of the POSIX in the tests for path normalization in t0060.\n---\n config.mak.uname      | 1 +\n git-compat-util.h     | 3 +++\n t/t0060-path-utils.sh | 2 ++\n 3 files changed, 6 insertions(+)\n\ndiff --git a/config.mak.uname b/config.mak.uname\nindex adfb90b..551e465 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -184,6 +184,7 @@ ifeq ($(uname_O),Cygwin)\n \tUNRELIABLE_FSTAT = UnfortunatelyYes\n \tSPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield\n \tOBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo\n+\tCOMPAT_OBJS += compat/cygwin.o\n endif\n ifeq ($(uname_S),FreeBSD)\n \tNEEDS_LIBICONV = YesPlease\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 047172d..db9c22d 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -189,6 +189,9 @@\n #include <sys/sysctl.h>\n #endif\n \n+#if defined(__CYGWIN__)\n+#include \"compat/cygwin.h\"\n+#endif\n #if defined(__MINGW32__)\n /* pull in Windows compatibility stuff */\n #include \"compat/mingw.h\"\ndiff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh\nindex 444b5a4..7ea2bb5 100755\n--- a/t/t0060-path-utils.sh\n+++ b/t/t0060-path-utils.sh\n@@ -70,6 +70,8 @@ ancestor() {\n case $(uname -s) in\n *MINGW*)\n \t;;\n+*CYGWIN*)\n+\t;;\n *)\n \ttest_set_prereq POSIX\n \t;;\n-- \n2.10.0\n\n"},{"id":"323687","messageId":"xmqqr2y0nk88.fsf@gitster.mtv.corp.google.com","threadId":"46278","inReplyTo":"20170701125057.16169-1-tboegi@web.de","subject":"Re: [PATCH v2 1/2] Check DB_ENVIRONMENT using is_directory()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-01T17:24:39Z","receivedAt":"2017-07-01T17:24:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> In setup.c is_git_directory() checks a Git directory using access(X_OK).\n> This does not check, if path is a file or a directory.\n> Check path with is_directory() instead.\n> ---\n> After all the discussions (and lots of tests) I found that this patch\n> works for my setup.\n> All in all could the error reporting be improvved for is_git_directory(),\n> as there may be \"access denied\", or \"not a directory\" or others, but\n> that is for another day.\n\nWouldn't this be a slight regression, though?  \n\nWe used to ignore an unsearchable directory but now we blindly say\n\"ah, it is a directory\".\n\nChecking is_directory() in addition to the existing access() would\nbe making a progress by fixing one bug (i.e. we no longer are\nconfused by an executable file there); skipping that access() based\non the filesystem quirks can be left for another day, of course.\n\n> setup.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/setup.c b/setup.c\n> index 358fbc2..5a7ee2e 100644\n> --- a/setup.c\n> +++ b/setup.c\n> @@ -321,7 +321,7 @@ int is_git_directory(const char *suspect)\n>  \n>  \t/* Check non-worktree-related signatures */\n>  \tif (getenv(DB_ENVIRONMENT)) {\n> -\t\tif (access(getenv(DB_ENVIRONMENT), X_OK))\n> +\t\tif (!is_directory(getenv(DB_ENVIRONMENT)))\n>  \t\t\tgoto done;\n>  \t}\n>  \telse {\n"},{"id":"323751","messageId":"20170703144137.27176-1-tboegi@web.de","threadId":"46278","inReplyTo":"xmqqr2y0nk88.fsf@gitster.mtv.corp.google.com","subject":"[PATCH v3 1/1] cygwin: Allow pushing to UNC paths","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2017-07-03T14:41:37Z","receivedAt":"2017-07-03T14:41:59Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\n cygwin can use an UNC path like //server/share/repo\n $ cd //server/share/dir\n $ mkdir test\n $ cd test\n $ git init --bare\n\n However, when we try to push from a local Git repository to this repo,\n there is a problem: Git converts the leading \"//\" into a single \"/\".\n\n As cygwin handles an UNC path so well, Git can support them better:\n - Introduce cygwin_offset_1st_component() which keeps the leading \"//\",\n   similar to what Git for Windows does.\n - Move CYGWIN out of the POSIX in the tests for path normalization in t0060\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n\nI think I skip all the changing in setup.c and cygwin_access() for the\nmoment:\n- It is not clear, what is a regression and what is an improvement\n- It may be a problem that could be solved in cygwin itself\n- I was able to push a an UNC path on a Windows server\n  when the domain controller was reachable.\n\n\ncompat/cygwin.c       | 19 +++++++++++++++++++\n compat/cygwin.h       |  2 ++\n config.mak.uname      |  1 +\n git-compat-util.h     |  3 +++\n t/t0060-path-utils.sh |  2 ++\n 5 files changed, 27 insertions(+)\n create mode 100644 compat/cygwin.c\n create mode 100644 compat/cygwin.h\n\ndiff --git a/compat/cygwin.c b/compat/cygwin.c\nnew file mode 100644\nindex 0000000..b9862d6\n--- /dev/null\n+++ b/compat/cygwin.c\n@@ -0,0 +1,19 @@\n+#include \"../git-compat-util.h\"\n+#include \"../cache.h\"\n+\n+int cygwin_offset_1st_component(const char *path)\n+{\n+\tconst char *pos = path;\n+\t/* unc paths */\n+\tif (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {\n+\t\t/* skip server name */\n+\t\tpos = strchr(pos + 2, '/');\n+\t\tif (!pos)\n+\t\t\treturn 0; /* Error: malformed unc path */\n+\n+\t\tdo {\n+\t\t\tpos++;\n+\t\t} while (*pos && pos[0] != '/');\n+\t}\n+\treturn pos + is_dir_sep(*pos) - path;\n+}\ndiff --git a/compat/cygwin.h b/compat/cygwin.h\nnew file mode 100644\nindex 0000000..8e52de4\n--- /dev/null\n+++ b/compat/cygwin.h\n@@ -0,0 +1,2 @@\n+int cygwin_offset_1st_component(const char *path);\n+#define offset_1st_component cygwin_offset_1st_component\ndiff --git a/config.mak.uname b/config.mak.uname\nindex adfb90b..551e465 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -184,6 +184,7 @@ ifeq ($(uname_O),Cygwin)\n \tUNRELIABLE_FSTAT = UnfortunatelyYes\n \tSPARSE_FLAGS = -isystem /usr/include/w32api -Wno-one-bit-signed-bitfield\n \tOBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo\n+\tCOMPAT_OBJS += compat/cygwin.o\n endif\n ifeq ($(uname_S),FreeBSD)\n \tNEEDS_LIBICONV = YesPlease\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 047172d..db9c22d 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -189,6 +189,9 @@\n #include <sys/sysctl.h>\n #endif\n \n+#if defined(__CYGWIN__)\n+#include \"compat/cygwin.h\"\n+#endif\n #if defined(__MINGW32__)\n /* pull in Windows compatibility stuff */\n #include \"compat/mingw.h\"\ndiff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh\nindex 444b5a4..7ea2bb5 100755\n--- a/t/t0060-path-utils.sh\n+++ b/t/t0060-path-utils.sh\n@@ -70,6 +70,8 @@ ancestor() {\n case $(uname -s) in\n *MINGW*)\n \t;;\n+*CYGWIN*)\n+\t;;\n *)\n \ttest_set_prereq POSIX\n \t;;\n-- \n2.10.0\n\n"},{"id":"323868","messageId":"xmqqinj6h9i2.fsf@gitster.mtv.corp.google.com","threadId":"46278","inReplyTo":"20170703144137.27176-1-tboegi@web.de","subject":"Re: [PATCH v3 1/1] cygwin: Allow pushing to UNC paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-05T21:14:13Z","receivedAt":"2017-07-05T21:14:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n>  cygwin can use an UNC path like //server/share/repo\n>  $ cd //server/share/dir\n>  $ mkdir test\n>  $ cd test\n>  $ git init --bare\n>\n>  However, when we try to push from a local Git repository to this repo,\n>  there is a problem: Git converts the leading \"//\" into a single \"/\".\n>\n>  As cygwin handles an UNC path so well, Git can support them better:\n>  - Introduce cygwin_offset_1st_component() which keeps the leading \"//\",\n>    similar to what Git for Windows does.\n>  - Move CYGWIN out of the POSIX in the tests for path normalization in t0060\n>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> ---\n>\n> I think I skip all the changing in setup.c and cygwin_access() for the\n> moment:\n> - It is not clear, what is a regression and what is an improvement\n> - It may be a problem that could be solved in cygwin itself\n> - I was able to push a an UNC path on a Windows server\n>   when the domain controller was reachable.\n\nOK.  \n\nIt certainly makes it simpler to improve things one at a time ;-)\n\n> diff --git a/compat/cygwin.h b/compat/cygwin.h\n> new file mode 100644\n> index 0000000..8e52de4\n> --- /dev/null\n> +++ b/compat/cygwin.h\n> @@ -0,0 +1,2 @@\n> +int cygwin_offset_1st_component(const char *path);\n> +#define offset_1st_component cygwin_offset_1st_component\n\nI originally found this somewhat iffy, but decided to take it as-is.\nBut we may want to fix it (and the original sin that brought this\nfile into this shape) later.\n\nThe reason of \"iffy\"-ness I felt were twofold:\n\n - This header file is only two lines long and is designed to be\n   included at a single place (git-compat-util.h).  It might be\n   better to inline its contents directly there, if we do not expect\n   it to grow aggressively in the future.\n\n - If it is to be a header file on its own, it should have the\n   standard double-inclusion guard\n\n    #ifndef COMPAT_CYGWIN_H\n    #define COMPAT_CYGWIN_H\n\t...\n    #endif /* COMPAT_CYGWIN_H */\n\n  around it.\n\nI see this was modeled after existing compat/mingw.h, which is\nsufficiently large that it deserves to be its own header, but then\nit should have the double-inclusion guard around it.  \n\nI am neutral between inlining the contents of cygwin.h to where it\nis included and keeping the organization this patch proposes.  If we\nanticipate futher development on Cygwin, perhaps having the header\nas a separate file, even if it starts small, makes sense, so I do\nnot mind it.\n\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 047172d..db9c22d 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -189,6 +189,9 @@\n>  #include <sys/sysctl.h>\n>  #endif\n>  \n> +#if defined(__CYGWIN__)\n> +#include \"compat/cygwin.h\"\n> +#endif\n>  #if defined(__MINGW32__)\n>  /* pull in Windows compatibility stuff */\n>  #include \"compat/mingw.h\"\n\n\nThanks.\n"}]}