From patchwork Mon Nov 26 17:32:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Torsten_B=C3=B6gershausen?= X-Patchwork-Id: 10698855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17D3F15A8 for ; Mon, 26 Nov 2018 17:32:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 018C92A289 for ; Mon, 26 Nov 2018 17:32:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E89002A2BC; Mon, 26 Nov 2018 17:32:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 638D92A289 for ; Mon, 26 Nov 2018 17:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726355AbeK0E1n (ORCPT ); Mon, 26 Nov 2018 23:27:43 -0500 Received: from mout.web.de ([212.227.15.4]:33757 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbeK0E1n (ORCPT ); Mon, 26 Nov 2018 23:27:43 -0500 Received: from tor.lan ([195.198.252.176]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MgO9u-1g4rei25x8-00Ngay; Mon, 26 Nov 2018 18:32:54 +0100 From: tboegi@web.de To: git@vger.kernel.org, svnpenn@gmail.com Cc: =?utf-8?q?Torsten_B=C3=B6gershausen?= Subject: [PATCH v1/RFC 1/1] 'git clone C:\cygwin\home\USER\repo' is working (again) Date: Mon, 26 Nov 2018 18:32:52 +0100 Message-Id: <20181126173252.1558-1-tboegi@web.de> X-Mailer: git-send-email 2.19.0.271.gfe8321ec05 In-Reply-To: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> References: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:V5+QvHfvWW6a+yOYqs04s4ln0nohnNRl6GoKNlJfxRPFNsVbp5w a2RqqC0ammfCtKoOY1TnmuGAKIixGpRGj3EMnQ7rHbVG8nTk4SdXbJBBYo1PgKqu2QXeR2W HFQuBT3TDZlZwuTUk6xZ37izT73XslRiq9cOQ0qm09teiEeRVQETkUTpHhTIAf7or3uKTh2 xLP68FhpkTMwu5kc36E4g== X-UI-Out-Filterresults: notjunk:1;V03:K0:h3w+pMjaR1w=:5PPZ+MBHkbyRh3AZ813oTi gviHn6MbHeBV2wmBKlc7hSB2amFAgiMKAwaTMXNVe74t2oaUB0jQNEGKGQzaV0+V7o98LLwi+ LeHAjgl5cDiMufaMkBdVZjuWOmvENy7dqbTiazRBkzNXPQYSAD/P9hT+H0dDz6WWkKJ1xdHa4 CHvKzanOmh2YWG5sFOmePyM+RGOlHhWXHc//9qumKIa4W6rnGVe1L9BbBkHB6B+wSSnzQJIMD dkYyu9km6WtRNQ9/F9X2yRMZK70eu9R/TwWcUReatPkZDYpLwl0+a5Ax4RW627PRBBCfHqKyp xImRFj7cuBvMo0JG/msHYLqo4M7fblRaJp6F/IjoW8lSzSPN/O/+zUt3xA+XpRsCEiUdE74h1 8YORhpyi4U3A0W1xJfopeUqM1xc3VA6jxIwDi0g10yAPLcmcFzBSiGFsCsXxPRXpAYJt3nqC9 X1LBVT7LGC7e4HVnaKf/BN+Qd3Z/2/VR6wtepK9L8rWdPvzlijRAoE/9tFCJKeZ+D6tMFUJj+ +HVvl9fimlrgwvHtp/j2v+io/J+1IH3BS68ds1k09hJFRH9WRDR8iawz7khKuwKNgBH0AGIYt DPzwbqKcqH6FiAtmAuKf/kHtSwF3HBnJ1kaXbeokbhW17D46p4kbwON/dusR0Bk5yE3E1rlYq ydf8Vi+MrUBo9E00SuAsVyWEoPUo9kD2nSZbRSL09wIwxKDPjVNhGUka6qLVjttNZgSyQ4qRM Juv6OpS3Q0QZnmos4fjng1nqppXJRYthrpMymzznGbgEeTUTgq4LONs2rf4DLSiE2A02KWxr0 qUyPam0yL33sZiK3IYhcf7PFVcyxqbWfavTfednotbonjUqpuu1UGNc+4cdd/cDnAhQ3go2+g dKOgJqqCfffQV3VrMpYFiH1b3vplJNqNoTOo8eNoDMXHx281X7wo03xTJLTW+c Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Torsten Bögershausen A regression for cygwin users was introduced with commit 05b458c, "real_path: resolve symlinks by hand". In the the commit message we read: The current implementation of real_path uses chdir() in order to resolve symlinks. Unfortunately this isn't thread-safe as chdir() affects a process as a whole... The old (and non-thread-save) OS calls chdir()/pwd() had been replaced by a string operation. The cygwin layer "knows" that "C:\cygwin" is an absolute path, but the new string operation does not. "git clone C:\cygwin\home\USER\repo" fails like this: fatal: Invalid path '/home/USER/repo/C:\cygwin\home\USER\repo' The solution is to implement has_dos_drive_prefix(), skip_dos_drive_prefix() is_dir_sep(), offset_1st_component() and convert_slashes() for cygwin in the same way as it is done in 'Git for Windows' in compat/mingw.[ch] Reported-By: Steven Penny Signed-off-by: Torsten Bögershausen --- This is the first vesion of a patch. Is there a chance that you test it ? abspath.c | 2 +- compat/cygwin.c | 18 ++++++++++++++---- compat/cygwin.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/abspath.c b/abspath.c index 9857985329..77a281f789 100644 --- a/abspath.c +++ b/abspath.c @@ -55,7 +55,7 @@ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining) strbuf_reset(resolved); strbuf_add(resolved, remaining->buf, offset); -#ifdef GIT_WINDOWS_NATIVE +#if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__) convert_slashes(resolved->buf); #endif strbuf_remove(remaining, 0, offset); diff --git a/compat/cygwin.c b/compat/cygwin.c index b9862d606d..c4a10cb5a1 100644 --- a/compat/cygwin.c +++ b/compat/cygwin.c @@ -1,19 +1,29 @@ #include "../git-compat-util.h" #include "../cache.h" +int cygwin_skip_dos_drive_prefix(char **path) +{ + int ret = has_dos_drive_prefix(*path); + *path += ret; + return ret; +} + int cygwin_offset_1st_component(const char *path) { - const char *pos = path; + char *pos = (char *)path; + /* unc paths */ - if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) { + if (!skip_dos_drive_prefix(&pos) && + is_dir_sep(pos[0]) && is_dir_sep(pos[1])) { /* skip server name */ - pos = strchr(pos + 2, '/'); + pos = strpbrk(pos + 2, "\\/"); if (!pos) return 0; /* Error: malformed unc path */ do { pos++; - } while (*pos && pos[0] != '/'); + } while (*pos && !is_dir_sep(*pos)); } + return pos + is_dir_sep(*pos) - path; } diff --git a/compat/cygwin.h b/compat/cygwin.h index 8e52de4644..46f29c0a90 100644 --- a/compat/cygwin.h +++ b/compat/cygwin.h @@ -1,2 +1,34 @@ +#define has_dos_drive_prefix(path) \ + (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) + + +int cygwin_offset_1st_component(const char *path); +#define offset_1st_component cygwin_offset_1st_component + + +#define has_dos_drive_prefix(path) \ + (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) +int cygwin_skip_dos_drive_prefix(char **path); +#define skip_dos_drive_prefix cygwin_skip_dos_drive_prefix +static inline int cygwin_is_dir_sep(int c) +{ + return c == '/' || c == '\\'; +} +#define is_dir_sep cygwin_is_dir_sep +static inline char *cygwin_find_last_dir_sep(const char *path) +{ + char *ret = NULL; + for (; *path; ++path) + if (is_dir_sep(*path)) + ret = (char *)path; + return ret; +} +static inline void convert_slashes(char *path) +{ + for (; *path; path++) + if (*path == '\\') + *path = '/'; +} +#define find_last_dir_sep cygwin_find_last_dir_sep int cygwin_offset_1st_component(const char *path); #define offset_1st_component cygwin_offset_1st_component From patchwork Fri Dec 7 17:04:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Torsten_B=C3=B6gershausen?= X-Patchwork-Id: 10718579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB7541731 for ; Fri, 7 Dec 2018 17:05:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94B77291D3 for ; Fri, 7 Dec 2018 17:05:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 831AD2E0B4; Fri, 7 Dec 2018 17:05:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC4BF291D3 for ; Fri, 7 Dec 2018 17:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726095AbeLGRFC (ORCPT ); Fri, 7 Dec 2018 12:05:02 -0500 Received: from mout.web.de ([212.227.15.14]:46441 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeLGRFB (ORCPT ); Fri, 7 Dec 2018 12:05:01 -0500 Received: from tor.lan ([195.198.252.176]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LilMD-1h3Xyj0Bcj-00d1Qs; Fri, 07 Dec 2018 18:05:00 +0100 From: tboegi@web.de To: git@vger.kernel.org, svnpenn@gmail.com Cc: =?utf-8?q?Torsten_B=C3=B6gershausen?= Subject: [PATCH v2 2/3] offset_1st_component(), dos_drive_prefix() return size_t Date: Fri, 7 Dec 2018 18:04:58 +0100 Message-Id: <20181207170458.9036-1-tboegi@web.de> X-Mailer: git-send-email 2.19.0.271.gfe8321ec05 In-Reply-To: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> References: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:KVxW49Od9hRlRHUbc7+XLCzLzLjl1xWkmQ1C/sfz96PSz39KXbm LR22wCM0nnizx8hrK1AnwsVfnnyEvYNWzIVVc9GD55sE1JS6CtiHKv2pIrAbofkr8UD3bp3 j5fAVSBKGQLCTVlIkrmf6qfREAtSpJ5Spo2XUu2UNlub4hShZjES+NVqghV75EG3757bKI/ Ws9SfGAvguKYhgi5oGPxA== X-UI-Out-Filterresults: notjunk:1;V03:K0:DCJWnKghJHY=:ybSDDojNgFpsm1fnyIUfCP qqvBw47Awe90TnP+6LzHIhaM8U0T+BN33kx/9aSsnYAV0dzA2PHUc0DEcRwMLrMDpPn9X+WOn d0nu6vZpCDCFYy29A+PUegBZkaLBo5Ql8BpQJ/V/VkuVtZ1kFk2KlVq3suywL0x/MNYF0GXmk OemJlk2FJoErXJermjKhWBWlm9GsVyX82fPfy8wa4ZwXc3cuaEZbLU5wis/xoV69yduBn1tcp dm0FlWbHsdWI4IcWd/OSPJuERX5FC9aG5cBUINcYYsUbE3t5SvJZt/Ptqn1fGJipWnc1stlrg 1ZBlgO3VE72LirgABqzipyXMkd1ZQ2XxoKO1G1unnIOV05NP7OnaXg6eLBsnFyfYrmbGI5+Pw 575bT0YdBuCM4u5KgG0ArR1WCoyR6V99J4aKY7zSe21Vx3U/kzsGicG2EINPRcs6EInTGpCr0 otNInuSyQmO5qIK362lwLnLsfqx/wnX7jjUc1LZIs1p9rjW7wJMWpqhHmUcnQKLQSW0fRrTm/ WheAleAYGLVxEedL/I5upMgoUdzSg1QfmUYnlIMlc5wIrnxxZgeBmFa+KdWLy1lX283lEOWWX DupKWAM/UlgYMCmQXTAhpAecYvlVimtdUAGWj5DJjRFmycMWHVou/W631M1fjgOKU5vzAb4XT 0XqcohaxyEXovX8TgS0p6J0d4iwQ3u2cfT2MviPTJj/TY3u83ik8U+ucyodB2nervUnjAkeSR Ur6yEqNUP2bCg5KlJY4YiFGAcdHA1fUMkQqCoAyDbU5vJMfoBIh2cofTGVAL6aOzviqDb8doU sNMULAywXItpm0glyJvtuTQhWVK4C1Ta3sQNbLiC+fGG9TjPfGppLoEDzxY/xHhKXoEiKDzrc qUq9VRBZ45bmXkMbs/UEb1gR0b4KtKkyM9sCUlk5ZGU8SJ3oZW5XSzcY7ygFhz Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Torsten Bögershausen Change the return value for offset_1st_component(), has_dos_drive_prefix() and skip_dos_drive_prefix from int into size_t, which is the natural type for length of data in memory. While at it, remove possible "parameter not used" warnings in for the non-Windows builds in git-compat-util.h Signed-off-by: Torsten Bögershausen --- abspath.c | 2 +- compat/mingw-cygwin.c | 6 +++--- compat/mingw-cygwin.h | 4 ++-- git-compat-util.h | 8 +++++--- setup.c | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/abspath.c b/abspath.c index 9857985329..12055a1d8f 100644 --- a/abspath.c +++ b/abspath.c @@ -51,7 +51,7 @@ static void get_next_component(struct strbuf *next, struct strbuf *remaining) /* copies root part from remaining to resolved, canonicalizing it on the way */ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining) { - int offset = offset_1st_component(remaining->buf); + size_t offset = offset_1st_component(remaining->buf); strbuf_reset(resolved); strbuf_add(resolved, remaining->buf, offset); diff --git a/compat/mingw-cygwin.c b/compat/mingw-cygwin.c index c63d7acb9c..5552c3ac20 100644 --- a/compat/mingw-cygwin.c +++ b/compat/mingw-cygwin.c @@ -1,13 +1,13 @@ #include "../git-compat-util.h" -int mingw_cygwin_skip_dos_drive_prefix(char **path) +size_t mingw_cygwin_skip_dos_drive_prefix(char **path) { - int ret = has_dos_drive_prefix(*path); + size_t ret = has_dos_drive_prefix(*path); *path += ret; return ret; } -int mingw_cygwin_offset_1st_component(const char *path) +size_t mingw_cygwin_offset_1st_component(const char *path) { char *pos = (char *)path; diff --git a/compat/mingw-cygwin.h b/compat/mingw-cygwin.h index 66ccc909ae..0e8a0c9074 100644 --- a/compat/mingw-cygwin.h +++ b/compat/mingw-cygwin.h @@ -1,6 +1,6 @@ #define has_dos_drive_prefix(path) \ (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) -int mingw_cygwin_skip_dos_drive_prefix(char **path); +size_t mingw_cygwin_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix mingw_cygwin_skip_dos_drive_prefix static inline int mingw_cygwin_is_dir_sep(int c) { @@ -16,5 +16,5 @@ static inline char *mingw_cygwin_find_last_dir_sep(const char *path) return ret; } #define find_last_dir_sep mingw_cygwin_find_last_dir_sep -int mingw_cygwin_offset_1st_component(const char *path); +size_t mingw_cygwin_offset_1st_component(const char *path); #define offset_1st_component mingw_cygwin_offset_1st_component diff --git a/git-compat-util.h b/git-compat-util.h index 7ece969b22..65eaaf0d50 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -355,16 +355,18 @@ static inline int noop_core_config(const char *var, const char *value, void *cb) #endif #ifndef has_dos_drive_prefix -static inline int git_has_dos_drive_prefix(const char *path) +static inline size_t git_has_dos_drive_prefix(const char *path) { + (void)path; return 0; } #define has_dos_drive_prefix git_has_dos_drive_prefix #endif #ifndef skip_dos_drive_prefix -static inline int git_skip_dos_drive_prefix(char **path) +static inline size_t git_skip_dos_drive_prefix(char **path) { + (void)path; return 0; } #define skip_dos_drive_prefix git_skip_dos_drive_prefix @@ -379,7 +381,7 @@ static inline int git_is_dir_sep(int c) #endif #ifndef offset_1st_component -static inline int git_offset_1st_component(const char *path) +static inline size_t git_offset_1st_component(const char *path) { return is_dir_sep(path[0]); } diff --git a/setup.c b/setup.c index 1be5037f12..538bc1ff99 100644 --- a/setup.c +++ b/setup.c @@ -29,7 +29,7 @@ static int abspath_part_inside_repo(char *path) size_t len; size_t wtlen; char *path0; - int off; + size_t off; const char *work_tree = get_git_work_tree(); if (!work_tree) @@ -800,7 +800,7 @@ static const char *setup_bare_git_dir(struct strbuf *cwd, int offset, struct repository_format *repo_fmt, int *nongit_ok) { - int root_len; + size_t root_len; if (check_repository_format_gently(".", repo_fmt, nongit_ok)) return NULL; From patchwork Fri Dec 7 17:05:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Torsten_B=C3=B6gershausen?= X-Patchwork-Id: 10718583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCBC113BF for ; Fri, 7 Dec 2018 17:05:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1BB291D3 for ; Fri, 7 Dec 2018 17:05:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C165D2ECC1; Fri, 7 Dec 2018 17:05:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69387291D3 for ; Fri, 7 Dec 2018 17:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726101AbeLGRFF (ORCPT ); Fri, 7 Dec 2018 12:05:05 -0500 Received: from mout.web.de ([212.227.17.12]:33923 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeLGRFE (ORCPT ); Fri, 7 Dec 2018 12:05:04 -0500 Received: from tor.lan ([195.198.252.176]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MfHfy-1godvD3IsM-00OsQc; Fri, 07 Dec 2018 18:05:01 +0100 From: tboegi@web.de To: git@vger.kernel.org, svnpenn@gmail.com Cc: =?utf-8?q?Torsten_B=C3=B6gershausen?= Subject: [PATCH v2 3/3] Refactor mingw_cygwin_offset_1st_component() Date: Fri, 7 Dec 2018 18:05:00 +0100 Message-Id: <20181207170500.9078-1-tboegi@web.de> X-Mailer: git-send-email 2.19.0.271.gfe8321ec05 In-Reply-To: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> References: <5bf18396.1c69fb81.20780.2b1d@mx.google.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:0EqXoxIbKuhxlcwxSGjDUv97UFbcLgyUkV+VWLOGvZwm6tVwSDA ZuI7OEXUkrSYDdcZ0745UIAz0SRuHpSrAuBjMt4imnBIcNZegP8QS7EfkwwFgep28Yz1WfD znAIsIuNhvsn560nf4r2RYaJa1lTJzUfRwha920QRBKeoMX0rjqSZgtZCPmNFrPtSBm1+YF kXX1zEr3jhiVo3yh62lCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:KHEwMmkD3LA=:JqYrpW6OsXbdKgdm0dw5sq norghHVau87uU/FUclB2KyIOtKcLfQUGDCOS/3a6Mw7cNqo7bSt7mMAUJvK9e1jo9zClBIf88 8GnTcLB1g/X/vsM8YohakDOZWccApAAi7NFlE6SYu/0A5wIPNg0VkYciEEXr4Jr1sdQ49K/5h ctmUc0Qy5cacAZ+Z8xjW5pbsSPD/QzBZrQDt+4vAZFqxbzQwZQdSfNmHX7QoFVhj+9DyTtD8t nP0oJEtH6+JAf/bxZHBxF6GF7fICOr/oujbzUw5oGlEs8yv1By3PKpE1ZQoUtFC8HJ33lz7mL eq8nCOy31ExBw4YjaYZRkvl0eMfdPTcvBNp4jhd3YtQ+p2VOzcznqk0mjIned+6mk6w1YXJWK TeWPOsYVuFbe5zF2LlCGp8D1oSr9z12MCgOXNnW9mxFPstx0akgTCwQtXtDEIouWDsCdfexLc 49CToz7nO9AUOctIRzzPLh+xmrptF1kB3akLQvl3lc54R+shrpKTg2Zil4Julh3/Av+G2Yj/B aYoau3cyXuGu2F3QX0YfuplrMEBa0LHOXVu4Sc5KonSgnUoOl53OP3Kub9L8eprrzTJZOiMtm jdRb7IcX6wJ2tkTFabp6yZUeeHLS8bingKzOx9SRPKG5f6LXCj5wGTnDmD2/ylup9D04Hk/jE /S9muEdjZBvyuY4SPcujTPBJFxXYs6AbwxxVTJOz5QLMbr2/1N7NnRpFV4drPcKw0K4+8nU8u 11OTovxEtjFA2ZDDf2nmpsP3pe+59qApTwzt92AW5n8HBXavzv7zmRRTvuMnfmKd0uomCQH9n fvYYWT9KxPJzMep6D75XMvTm4dBcLUyqjpLWylkYXCZ+D5qGXQdLE7JVyw0ryQwVEu230M/OS X2zjmTTiL0N8rtX3rgGJ9atysilBnf6RgroZ4kVS/wfTHbbMBJzZmw6jVQL0CF Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Torsten Bögershausen The Windows version of offset_1st_component() needs to hande 3 cases: - The path is an UNC path, starting with "//" or "\\\\". Skip the servername and the name of the share. - The path is a DOS drive, starting with e.g. "X:" The driver letter and the ':' must be skipped - The path is pointing to a subdirectory somewhere in the path and the directory seperator needs to be skipped ('/' or '\\'). Refactor the code to make it easier to read. Suggested-by: Johannes Schindelin Signed-off-by: Torsten Bögershausen --- compat/mingw-cygwin.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compat/mingw-cygwin.c b/compat/mingw-cygwin.c index 5552c3ac20..c379a72775 100644 --- a/compat/mingw-cygwin.c +++ b/compat/mingw-cygwin.c @@ -10,10 +10,8 @@ size_t mingw_cygwin_skip_dos_drive_prefix(char **path) size_t mingw_cygwin_offset_1st_component(const char *path) { char *pos = (char *)path; - - /* unc paths */ - if (!skip_dos_drive_prefix(&pos) && - is_dir_sep(pos[0]) && is_dir_sep(pos[1])) { + if (is_dir_sep(pos[0]) && is_dir_sep(pos[1])) { + /* unc path */ /* skip server name */ pos = strpbrk(pos + 2, "\\/"); if (!pos) @@ -22,7 +20,8 @@ size_t mingw_cygwin_offset_1st_component(const char *path) do { pos++; } while (*pos && !is_dir_sep(*pos)); + } else { + skip_dos_drive_prefix(&pos); } - return pos + is_dir_sep(*pos) - path; }