{"thread":{"id":"36699","subject":"[PATCH] Windows: Allow using UNC path for git repository","startedAt":"2014-05-19T13:23:34Z","lastAt":"2014-05-20T19:33:19Z","messageCount":4,"participants":["Stepan Kasal","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"242160","messageId":"20140519132334.GA1435@camelia.ucw.cz","threadId":"36699","inReplyTo":null,"subject":"[PATCH] Windows: Allow using UNC path for git repository","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-05-19T13:23:34Z","receivedAt":"2014-05-19T13:23:34Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Cezary Zawadka <czawadka@gmail.com>\nDate: Tue, 13 Jul 2010 16:17:43 +0200\n\n[efl: moved MinGW-specific part to compat/]\n[jes: fixed compilation on non-Windows]\n\nEric Sunshine fixed mingw_offset_1st_component() to return consistently \"foo\"\nfor UNC \"//machine/share/foo\", cf\nhttp://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0\n\nAuthor: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Cezary Zawadka <czawadka@gmail.com>\nSigned-off-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n\nHello,\nthis is another patch that lived in msysGit for years, at least from\nJul 13, 2010.  It was there in two parts, first sketch by Cezary and\na fix from Eric Sunshine, but I decided to submit the combined\nversion.\n\nLet me note that this patch should not affect any non-Windows\nplatform.  The chnage of offset_1st_component() to a simple macro is\nok, because has_dos_drive_prefix() is 0 there.\n\nRegards,\n  Stepan\n\n cache.h           |  1 -\n compat/mingw.c    | 24 ++++++++++++++++++++++++\n compat/mingw.h    |  2 ++\n git-compat-util.h |  4 ++++\n path.c            |  7 -------\n 5 files changed, 30 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ebe9a40..0961fb5 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -781,7 +781,6 @@ int normalize_path_copy(char *dst, const char *src);\n int longest_ancestor_length(const char *path, struct string_list *prefixes);\n char *strip_path_suffix(const char *path, const char *suffix);\n int daemon_avoid_alias(const char *path);\n-int offset_1st_component(const char *path);\n \n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex e9892f8..a0e13bc 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)\n \terrno = EINVAL;\n \treturn -1;\n }\n+\n+int mingw_offset_1st_component(const char *path)\n+{\n+\tint offset = 0;\n+\tif (has_dos_drive_prefix(path))\n+\t\toffset = 2;\n+\n+\t/* unc paths */\n+\telse if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {\n+\n+\t\t/* skip server name */\n+\t\tchar *pos = strpbrk(path + 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 && !is_dir_sep(*pos));\n+\n+\t\toffset = pos - path;\n+\t}\n+\n+\treturn offset + is_dir_sep(path[offset]);\n+}\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex e033e72..3eaf822 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)\n \treturn ret;\n }\n #define find_last_dir_sep mingw_find_last_dir_sep\n+int mingw_offset_1st_component(const char *path);\n+#define offset_1st_component mingw_offset_1st_component\n #define PATH_SEP ';'\n #define PRIuMAX \"I64u\"\n #define PRId64 \"I64d\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex d493a8c..ec41cfb 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -270,6 +270,10 @@ extern char *gitbasename(char *);\n #define has_dos_drive_prefix(path) 0\n #endif\n \n+#ifndef offset_1st_component\n+#define offset_1st_component(path) (is_dir_sep((path)[0]))\n+#endif\n+\n #ifndef is_dir_sep\n #define is_dir_sep(c) ((c) == '/')\n #endif\ndiff --git a/path.c b/path.c\nindex f9c5062..bc804a3 100644\n--- a/path.c\n+++ b/path.c\n@@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)\n \t\t}\n \t}\n }\n-\n-int offset_1st_component(const char *path)\n-{\n-\tif (has_dos_drive_prefix(path))\n-\t\treturn 2 + is_dir_sep(path[2]);\n-\treturn is_dir_sep(path[0]);\n-}\n-- \n1.9.2.msysgit.0.490.ga07b726\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"242309","messageId":"xmqqy4xwxop7.fsf@gitster.dls.corp.google.com","threadId":"36699","inReplyTo":"20140519132334.GA1435@camelia.ucw.cz","subject":"Re: [PATCH] Windows: Allow using UNC path for git repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-20T18:57:56Z","receivedAt":"2014-05-20T18:57:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stepan Kasal <kasal@ucw.cz> writes:\n\n> From: Cezary Zawadka <czawadka@gmail.com>\n> Date: Tue, 13 Jul 2010 16:17:43 +0200\n>\n> [efl: moved MinGW-specific part to compat/]\n> [jes: fixed compilation on non-Windows]\n>\n> Eric Sunshine fixed mingw_offset_1st_component() to return consistently \"foo\"\n> for UNC \"//machine/share/foo\", cf\n> http://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0\n>\n> Author: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Cezary Zawadka <czawadka@gmail.com>\n> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n> ---\n>\n> Hello,\n> this is another patch that lived in msysGit for years, at least from\n> Jul 13, 2010.  It was there in two parts, first sketch by Cezary and\n> a fix from Eric Sunshine, but I decided to submit the combined\n> version.\n>\n> Let me note that this patch should not affect any non-Windows\n> platform.  The chnage of offset_1st_component() to a simple macro is\n> ok, because has_dos_drive_prefix() is 0 there.\n\nAs I do not think anybody takes the address of the function, I agree\nit should be a no-op for non-Windows platform.\n\nIt would be nice if somebody in the S-o-b chain can double-check\nthat the \"combined\" version is sane.  I didn't read the mingw.c part\ncarefully enough for me to say returning 0 upon error is sane with\nconfidence, for example.\n\nThanks.\n\n> Regards,\n>   Stepan\n>\n>  cache.h           |  1 -\n>  compat/mingw.c    | 24 ++++++++++++++++++++++++\n>  compat/mingw.h    |  2 ++\n>  git-compat-util.h |  4 ++++\n>  path.c            |  7 -------\n>  5 files changed, 30 insertions(+), 8 deletions(-)\n>\n> diff --git a/cache.h b/cache.h\n> index ebe9a40..0961fb5 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -781,7 +781,6 @@ int normalize_path_copy(char *dst, const char *src);\n>  int longest_ancestor_length(const char *path, struct string_list *prefixes);\n>  char *strip_path_suffix(const char *path, const char *suffix);\n>  int daemon_avoid_alias(const char *path);\n> -int offset_1st_component(const char *path);\n>  \n>  /* object replacement */\n>  #define LOOKUP_REPLACE_OBJECT 1\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index e9892f8..a0e13bc 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)\n>  \terrno = EINVAL;\n>  \treturn -1;\n>  }\n> +\n> +int mingw_offset_1st_component(const char *path)\n> +{\n> +\tint offset = 0;\n> +\tif (has_dos_drive_prefix(path))\n> +\t\toffset = 2;\n> +\n> +\t/* unc paths */\n> +\telse if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {\n> +\n> +\t\t/* skip server name */\n> +\t\tchar *pos = strpbrk(path + 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 && !is_dir_sep(*pos));\n> +\n> +\t\toffset = pos - path;\n> +\t}\n> +\n> +\treturn offset + is_dir_sep(path[offset]);\n> +}\n> diff --git a/compat/mingw.h b/compat/mingw.h\n> index e033e72..3eaf822 100644\n> --- a/compat/mingw.h\n> +++ b/compat/mingw.h\n> @@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)\n>  \treturn ret;\n>  }\n>  #define find_last_dir_sep mingw_find_last_dir_sep\n> +int mingw_offset_1st_component(const char *path);\n> +#define offset_1st_component mingw_offset_1st_component\n>  #define PATH_SEP ';'\n>  #define PRIuMAX \"I64u\"\n>  #define PRId64 \"I64d\"\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index d493a8c..ec41cfb 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -270,6 +270,10 @@ extern char *gitbasename(char *);\n>  #define has_dos_drive_prefix(path) 0\n>  #endif\n>  \n> +#ifndef offset_1st_component\n> +#define offset_1st_component(path) (is_dir_sep((path)[0]))\n> +#endif\n> +\n>  #ifndef is_dir_sep\n>  #define is_dir_sep(c) ((c) == '/')\n>  #endif\n> diff --git a/path.c b/path.c\n> index f9c5062..bc804a3 100644\n> --- a/path.c\n> +++ b/path.c\n> @@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)\n>  \t\t}\n>  \t}\n>  }\n> -\n> -int offset_1st_component(const char *path)\n> -{\n> -\tif (has_dos_drive_prefix(path))\n> -\t\treturn 2 + is_dir_sep(path[2]);\n> -\treturn is_dir_sep(path[0]);\n> -}\n> -- \n> 1.9.2.msysgit.0.490.ga07b726\n>\n> -- \n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"242315","messageId":"20140520192132.GA7355@camelia.ucw.cz","threadId":"36699","inReplyTo":"xmqqy4xwxop7.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] Windows: Allow using UNC path for git repository","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-05-20T19:21:32Z","receivedAt":"2014-05-20T19:21:32Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hello,\n\nOn Tue, May 20, 2014 at 11:57:56AM -0700, Junio C Hamano wrote:\n> It would be nice if somebody in the S-o-b chain can double-check\n> that the \"combined\" version is sane.  [...]\n\n\"Combined\" was an unfortunate word.  There was a pair of successive\ncommits in msysgit all the time.  I just decided to submit them\nsquashed together.  I haven't changed the code, just created a new\ncommit message.\n\nThat said, reviewing the function is always useful, of course.\n\nStepan\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"242317","messageId":"xmqqppj8xn28.fsf@gitster.dls.corp.google.com","threadId":"36699","inReplyTo":"20140520192132.GA7355@camelia.ucw.cz","subject":"Re: [PATCH] Windows: Allow using UNC path for git repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-20T19:33:19Z","receivedAt":"2014-05-20T19:33:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stepan Kasal <kasal@ucw.cz> writes:\n\n> Hello,\n>\n> On Tue, May 20, 2014 at 11:57:56AM -0700, Junio C Hamano wrote:\n>> It would be nice if somebody in the S-o-b chain can double-check\n>> that the \"combined\" version is sane.  [...]\n>\n> \"Combined\" was an unfortunate word.  There was a pair of successive\n> commits in msysgit all the time.  I just decided to submit them\n> squashed together.  I haven't changed the code, just created a new\n> commit message.\n>\n> That said, reviewing the function is always useful, of course.\n\nI did mis-read your message.  As the patch shows the current state\nthat exists in msysgit that people are happy about, the function has\nalready been reviewed by stakeholders, and I would be happy to apply\nit.\n\nThanks.\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"}]}