git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1/RFC 1/1] 'git clone <url> C:\cygwin\home\USER\repo' is working (again)

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 27, 2018, 01:16 UTC
Message-ID
<xmqqtvk3tj45.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181126173252.1558-1-tboegi@web.de>
tboegi@web.de writes:
Show 11 quoted lines
> 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).

Show 14 quoted lines
> 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.

Show 9 quoted lines
>  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.

Show 7 quoted lines
>  		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 ;-)

Show 7 quoted lines
> 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).
Previous: Steven PennyNext: Steven Penny
Message 18 of 56 in “Cygwin Git with Windows paths”
  1. Steven PennyNov 18, 2018
  2. Torsten BögershausenNov 18, 2018
  3. Steven PennyNov 18, 2018
  4. Torsten BögershausenNov 18, 2018
  5. Steven PennyNov 18, 2018
  6. Torsten BögershausenNov 18, 2018
  7. Steven PennyNov 18, 2018
  8. Junio C HamanoNov 19, 2018
  9. Randall S. BeckerNov 19, 2018
  10. Junio C HamanoNov 19, 2018
  11. Torsten BögershausenNov 19, 2018
  12. Steven PennyNov 20, 2018
  13. Torsten BögershausenNov 20, 2018
  14. Steven PennyNov 20, 2018
  15. Randall S. BeckerNov 19, 2018
  16. 1/1 'git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Nov 26, 2018
  17. Steven PennyNov 27, 2018
  18. Junio C HamanoNov 27, 2018
  19. Steven PennyNov 27, 2018
  20. Junio C HamanoNov 27, 2018
  21. Steven PennyNov 27, 2018
  22. Johannes SchindelinNov 27, 2018
  23. Junio C HamanoNov 28, 2018
  24. J.H. van de WaterNov 28, 2018
  25. Johannes SchindelinNov 28, 2018
  26. HouderNov 28, 2018
  27. Johannes SchindelinNov 28, 2018
  28. Achim GratzNov 27, 2018
  29. Johannes SchindelinNov 27, 2018
  30. Junio C HamanoNov 28, 2018
  31. Achim GratzNov 27, 2018
  32. 2/3 offset_1st_component(), dos_drive_prefix() return size_ttboegi@web.de, Dec 7, 2018
  33. 1/3 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 7, 2018
  34. Johannes SchindelinDec 7, 2018
  35. Steven PennyDec 8, 2018
  36. Johannes SchindelinDec 10, 2018
  37. Steven PennyDec 10, 2018
  38. Johannes SchindelinDec 11, 2018
  39. Steven PennyDec 12, 2018
  40. Johannes SixtDec 12, 2018
  41. Steven PennyDec 12, 2018
  42. Junio C HamanoDec 13, 2018
  43. Johannes SchindelinDec 12, 2018
  44. Elijah NewrenDec 12, 2018
  45. Johannes SchindelinDec 12, 2018
  46. 3/3 Refactor mingw_cygwin_offset_1st_component()tboegi@web.de, Dec 7, 2018
  47. Johannes SchindelinDec 7, 2018
  48. 1/1 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 8, 2018
  49. Steven PennyDec 8, 2018
  50. Junio C HamanoDec 9, 2018
  51. Johannes SchindelinDec 10, 2018
  52. Torsten BögershausenDec 11, 2018
  53. Johannes SchindelinDec 11, 2018
  54. Torsten BögershausenDec 11, 2018
  55. 1/1 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 15, 2018
  56. Achim GratzMay 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.