diff mbox series

[v2,3/3] Refactor mingw_cygwin_offset_1st_component()

Message ID 20181207170500.9078-1-tboegi@web.de (mailing list archive)
State New, archived
Headers show
Series [v1/RFC,1/1] 'git clone <url> C:\cygwin\home\USER\repo' is working (again) | expand

Commit Message

Torsten Bögershausen Dec. 7, 2018, 5:05 p.m. UTC
From: Torsten Bögershausen <tboegi@web.de>

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 <johannes.schindelin@gmx.de>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 compat/mingw-cygwin.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Johannes Schindelin Dec. 7, 2018, 10:18 p.m. UTC | #1
Hi Torsten,

On Fri, 7 Dec 2018, tboegi@web.de wrote:

> 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 */

This comment is still useful (and now even more correct), and should stay.

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

Why remove this empty line? It structures the code quite nicely.

The rest looks correct to me,
Johannes

>  	return pos + is_dir_sep(*pos) - path;
>  }
> -- 
> 2.19.0.271.gfe8321ec05
> 
>
diff mbox series

Patch

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