git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: tboegi@web.de
Cc: git@vger.kernel.org, svnpenn@gmail.com
Subject: Re: [PATCH v1/RFC 1/1] 'git clone <url> C:\cygwin\home\USER\repo' is working (again)
Date: Tue, 27 Nov 2018 10:16:42 +0900	[thread overview]
Message-ID: <xmqqtvk3tj45.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20181126173252.1558-1-tboegi@web.de> (tboegi's message of "Mon, 26 Nov 2018 18:32:52 +0100")

tboegi@web.de writes:

> Reported-By: Steven Penny <svnpenn@gmail.com>
> Signed-off-by: Torsten Bögershausen <tboegi@web.de>
> ---
>
> 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(-)

I am hoping that the funny indentation above is merely an accidental
touch on the delete key and not a sign of MUA eating the patch to
make it unapplicable (and making it harder for those who want to
test to test it).

> 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;
> +}

Mental note: this is exactly the same as mingw version.

I wonder if it makes the rest of the code simpler if we stripped
things like /cygdrive/c here exactly the sam way as we strip C:
For that, has_dos_drive_prefix() needs to know /cygdrive/[a-z],
which may not be a bad thing, I guess.  Let's read on.

>  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])) {

When given C:\foo\bar, this strips prefix to leave \foo\bar in pos and
then realizes that it cannot be unc path (because it has dos prefix)
and goes on.  What is returned from the function is "\foo\bar" + 1 -
path, i.e. the offset in the original "C:\foo\bar" string of the
'f' in "foo", i.e. 3.

When given \foo\bar, pos stays the same as path, and it skips the
first backslash and returns the offset in the original string of the
'f' in "foo", i.e. 1.

Both cases return the moreal equivalent --- the offset of the first
component 'foo'.  So this looks correct for these two cases.

>  		/* skip server name */
> -		pos = strchr(pos + 2, '/');
> +		pos = strpbrk(pos + 2, "\\/");

This is to allow \\server\path in addition to //server/path; the
original looked only for '/' with strchr but we now look for either
'/' or '\', whichever comes earlier.  Both helpers return NULL when
they find no separator, so we should be able to handle the returned
pos from here on the same way as the original code.

>  		if (!pos)
>  			return 0; /* Error: malformed unc path */
>  
>  		do {
>  			pos++;
> -		} while (*pos && pos[0] != '/');
> +		} while (*pos && !is_dir_sep(*pos));

And whenever we looked for '/', we consider '\' its equivalent.

>  	}
> +
>  	return pos + is_dir_sep(*pos) - path;
>  }

Looks good so far.

Wait, did I just waste time by not looking at mingw.c version?  I
suspect this would be exactly the same ;-)

> 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)

Metanl note: this also looks the same as mingw version.

> +int cygwin_offset_1st_component(const char *path);
> +#define offset_1st_component cygwin_offset_1st_component
> +

So, my real questions are

 - Is there a point in having cygwin specific variant of these, or
   can we just borrow from mingw version (with some refactoring)?
   Is there a point in doing so (e.g. if mingw plans to move to
   reject forward slashes, attempting to share is pointless).

 - Would it make it better (or worse) to treat the /cygdrive/c thing
   as another way to spell dos-drive-prefix?  If the answer is "it
   is a good idea", then that answers the previous question
   automatically (we cannot gain much by sharing, as mingw side
   won't want to treat /cygdrive/c any differently).


  parent reply	other threads:[~2018-11-27  1:16 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-18 15:21 Cygwin Git with Windows paths Steven Penny
2018-11-18 15:41 ` Torsten Bögershausen
2018-11-18 16:23   ` Steven Penny
2018-11-18 17:15     ` Torsten Bögershausen
2018-11-18 17:34       ` Steven Penny
2018-11-18 18:28         ` Torsten Bögershausen
2018-11-18 19:00           ` Steven Penny
2018-11-19  0:06       ` Junio C Hamano
2018-11-19  2:11         ` Randall S. Becker
2018-11-19  3:33           ` Junio C Hamano
2018-11-19  5:20             ` Torsten Bögershausen
2018-11-20  0:17               ` Steven Penny
2018-11-20 10:36                 ` Torsten Bögershausen
2018-11-20 12:51                   ` Steven Penny
2018-11-19 12:22             ` Randall S. Becker
2018-11-26 17:32 ` [PATCH v1/RFC 1/1] 'git clone <url> C:\cygwin\home\USER\repo' is working (again) tboegi
2018-11-27  0:35   ` Steven Penny
2018-11-27  1:16   ` Junio C Hamano [this message]
2018-11-27  2:49     ` Steven Penny
2018-11-27  5:23       ` Junio C Hamano
2018-11-27  6:20         ` Steven Penny
2018-11-27 12:55         ` Johannes Schindelin
2018-11-28  4:10           ` Junio C Hamano
2018-11-28  5:55             ` J.H. van de Water
2018-11-28  8:46               ` Johannes Schindelin
2018-11-28  9:01                 ` Houder
2018-11-28  9:35                   ` Johannes Schindelin
2018-11-27 20:10     ` Achim Gratz
2018-11-27 12:49   ` Johannes Schindelin
2018-11-28  4:12     ` Junio C Hamano
2018-11-27 20:05   ` Achim Gratz
2018-12-07 17:04 ` [PATCH v2 1/3] git " tboegi
2018-12-07 21:53   ` Johannes Schindelin
2018-12-08  0:49   ` Steven Penny
2018-12-10  8:46     ` Johannes Schindelin
2018-12-10 12:45       ` Steven Penny
2018-12-11 13:39         ` Johannes Schindelin
2018-12-12  0:42           ` Steven Penny
2018-12-12  7:29             ` Johannes Sixt
2018-12-12 12:40               ` Steven Penny
2018-12-13  3:52                 ` Junio C Hamano
2018-12-12 13:33               ` Johannes Schindelin
2018-12-12  3:47     ` Elijah Newren
2018-12-12 13:57       ` Johannes Schindelin
2018-12-07 17:04 ` [PATCH v2 2/3] offset_1st_component(), dos_drive_prefix() return size_t tboegi
2018-12-07 17:05 ` [PATCH v2 3/3] Refactor mingw_cygwin_offset_1st_component() tboegi
2018-12-07 22:18   ` Johannes Schindelin
2018-12-08 15:11 ` [PATCH v3 1/1] git clone <url> C:\cygwin\home\USER\repo' is working (again) tboegi
2018-12-08 16:24   ` Steven Penny
2018-12-09  1:39   ` Junio C Hamano
2018-12-10  8:32   ` Johannes Schindelin
2018-12-11  6:12     ` Torsten Bögershausen
2018-12-11 13:28       ` Johannes Schindelin
2018-12-11 18:55         ` Torsten Bögershausen
2018-12-15  4:33 ` [PATCH v4 " tboegi
2019-05-02  7:48   ` Achim Gratz

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=xmqqtvk3tj45.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=svnpenn@gmail.com \
    --cc=tboegi@web.de \
    /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).