Re: [PATCH v2] Fix safe_create_leading_directories() for Windows
Hi, On Thu, 2 Jan 2014, Sebastian Schuberth wrote: When cloning to a directory C:\foo\bar from Windows' cmd.exe where foo does not exist yet, Git would throw an error like fatal: could not create work tree dir 'c:\foo\bar'.: No such file or directory Fix this by not hard-coding a platform specific directory separator into safe_create_leading_directories(). Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de Signed-off-by: Sebastian Schuberth sschube...@gmail.com It would be nice to have links to the original discussion, but I guess that that would not be accepted. Ciao, Dscho -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] Fix safe_create_leading_directories() for Windows
Sebastian Schuberth sschube...@gmail.com writes: When cloning to a directory C:\foo\bar from Windows' cmd.exe where foo does not exist yet, Git would throw an error like fatal: could not create work tree dir 'c:\foo\bar'.: No such file or directory Fix this by not hard-coding a platform specific directory separator into safe_create_leading_directories(). Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de Signed-off-by: Sebastian Schuberth sschube...@gmail.com --- sha1_file.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 760dd60..2114c58 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -110,12 +110,15 @@ int safe_create_leading_directories(char *path) char *pos = path + offset_1st_component(path); struct stat st; - while (pos) { - pos = strchr(pos, '/'); - if (!pos) - break; - while (*++pos == '/') - ; + while (*pos) { + while (!is_dir_sep(*pos)) { + ++pos; + if (!*pos) + break; + } + /* skip consecutive directory separators */ + while (is_dir_sep(*pos)) + ++pos; if (!*pos) break; *--pos = '\0'; This has a bit of conflict with another topic in flight; I think I resolved it correctly, but please double check. The following is how it would apply on top of 'pu'. sha1_file.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 131ca97..9e686eb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -113,11 +113,12 @@ int safe_create_leading_directories(char *path) while (!retval next_component) { struct stat st; - char *slash = strchr(next_component, '/'); - - if (!slash) + char *slash = next_component; + while (!is_dir_sep(*slash)) + ++slash; + if (!*slash) return 0; - while (*(slash + 1) == '/') + while (is_dir_sep(*(slash + 1))) slash++; next_component = slash + 1; if (!*next_component) -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] Fix safe_create_leading_directories() for Windows
Junio C Hamano gits...@pobox.com writes: This has a bit of conflict with another topic in flight; I think I resolved it correctly, but please double check. The following is how it would apply on top of 'pu'. sha1_file.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 131ca97..9e686eb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -113,11 +113,12 @@ int safe_create_leading_directories(char *path) while (!retval next_component) { struct stat st; - char *slash = strchr(next_component, '/'); - - if (!slash) + char *slash = next_component; + while (!is_dir_sep(*slash)) Gaah; we need to check for the end of string here, i.e. while (*slash !is_dir_sep(*slash)) will be what I'll queue on 'pu' for today. + ++slash; + if (!*slash) return 0; - while (*(slash + 1) == '/') + while (is_dir_sep(*(slash + 1))) slash++; next_component = slash + 1; if (!*next_component) -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] Fix safe_create_leading_directories() for Windows
Junio C Hamano gits...@pobox.com writes: Junio C Hamano gits...@pobox.com writes: This has a bit of conflict with another topic in flight; I think I resolved it correctly, but please double check. The following is how it would apply on top of 'pu'. sha1_file.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 131ca97..9e686eb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -113,11 +113,12 @@ int safe_create_leading_directories(char *path) while (!retval next_component) { struct stat st; -char *slash = strchr(next_component, '/'); - -if (!slash) +char *slash = next_component; +while (!is_dir_sep(*slash)) Gaah; we need to check for the end of string here, i.e. while (*slash !is_dir_sep(*slash)) will be what I'll queue on 'pu' for today. +++slash; +if (!*slash) return 0; -while (*(slash + 1) == '/') +while (is_dir_sep(*(slash + 1))) slash++; next_component = slash + 1; if (!*next_component) Another thing I noticed (but I won't fix it up myself today, as I am deep into today's integration cycle already) is that we temporarily replace the slash with NUL and then restore them before we return, but the restoration is done with the slash. If we were to go in the direction of this patch, you may want to update that one to use whatever dir-sep was used in the input string. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html