{"thread":{"id":"35688","subject":"[PATCH v2] safe_create_leading_directories(): on Windows, \\ can separate path components","startedAt":"2014-01-18T23:40:44Z","lastAt":"2014-01-21T19:35:27Z","messageCount":3,"participants":["Michael Haggerty","Sebastian Schuberth","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"233359","messageId":"1390088444-11439-1-git-send-email-mhagger@alum.mit.edu","threadId":"35688","inReplyTo":null,"subject":"[PATCH v2] safe_create_leading_directories(): on Windows, \\ can separate path components","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-01-18T23:40:44Z","receivedAt":"2014-01-18T23:40:44Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"When cloning to a directory \"C:\\foo\\bar\" from Windows' cmd.exe where\n\"foo\" does not exist yet, Git would throw an error like\n\n    fatal: could not create work tree dir 'c:\\foo\\bar'.: No such file or directory\n\nFix this by not hard-coding a platform specific directory separator\ninto safe_create_leading_directories().\n\nThis patch, including its entire commit message, is derived from a\npatch by Sebastian Schuberth.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\nThis patch applies on top of v3 of mh/safe-create-leading-directories.\n\nThe only logical change from Sebastian's patch is that this version\nrestores the original slash character rather than always restoring it\nto '/' (as suggested by Junio).\n\nPlease note that I have merely adapted Sebastian's patch to apply on\ntop of my changes.  I do not have an opinion about whether slashes\nshould rather be normalized before they are passed to this function.\nAnd I cannot test the patch under Windows (though it passes the test\nsuite under Linux).\n\n sha1_file.c | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 8b0849f..6e8c05d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -112,17 +112,21 @@ enum scld_error safe_create_leading_directories(char *path)\n \n \twhile (ret == SCLD_OK && next_component) {\n \t\tstruct stat st;\n-\t\tchar *slash = strchr(next_component, '/');\n+\t\tchar *slash = next_component, slash_character;\n \n-\t\tif (!slash)\n+\t\twhile (*slash && !is_dir_sep(*slash))\n+\t\t\tslash++;\n+\n+\t\tif (!*slash)\n \t\t\tbreak;\n \n \t\tnext_component = slash + 1;\n-\t\twhile (*next_component == '/')\n+\t\twhile (is_dir_sep(*next_component))\n \t\t\tnext_component++;\n \t\tif (!*next_component)\n \t\t\tbreak;\n \n+\t\tslash_character = *slash;\n \t\t*slash = '\\0';\n \t\tif (!stat(path, &st)) {\n \t\t\t/* path exists */\n@@ -148,7 +152,7 @@ enum scld_error safe_create_leading_directories(char *path)\n \t\t} else if (adjust_shared_perm(path)) {\n \t\t\tret = SCLD_PERMS;\n \t\t}\n-\t\t*slash = '/';\n+\t\t*slash = slash_character;\n \t}\n \treturn ret;\n }\n-- \n1.8.5.2\n"},{"id":"233389","messageId":"CAHGBnuMmutYqwZNw+VoZi=R_LaS_fowZrqaU2+JMYN53q6XQ2Q@mail.gmail.com","threadId":"35688","inReplyTo":"1390088444-11439-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH v2] safe_create_leading_directories(): on Windows, \\ can separate path components","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2014-01-19T20:26:38Z","receivedAt":"2014-01-19T20:26:38Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On Sun, Jan 19, 2014 at 12:40 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:\n\n> This patch applies on top of v3 of mh/safe-create-leading-directories.\n>\n> The only logical change from Sebastian's patch is that this version\n> restores the original slash character rather than always restoring it\n> to '/' (as suggested by Junio).\n\nThanks Michael. This is very similar to Junio's current merge conflict\nresultion in pu between your original series and my patch (c2fec83). I\nlike this patch of yours slightly better, however, as it uses a\n\"while\" instead of a \"for\" loop and the more conclusive\n\"slash_character\" than the \"was_slash\" variable name.\n\n-- \nSebastian Schuberth\n"},{"id":"233452","messageId":"xmqqmwipuo00.fsf@gitster.dls.corp.google.com","threadId":"35688","inReplyTo":"CAHGBnuMmutYqwZNw+VoZi=R_LaS_fowZrqaU2+JMYN53q6XQ2Q@mail.gmail.com","subject":"Re: [PATCH v2] safe_create_leading_directories(): on Windows, \\ can separate path components","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-21T19:35:27Z","receivedAt":"2014-01-21T19:35:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sebastian Schuberth <sschuberth@gmail.com> writes:\n\n> On Sun, Jan 19, 2014 at 12:40 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:\n>\n>> This patch applies on top of v3 of mh/safe-create-leading-directories.\n>>\n>> The only logical change from Sebastian's patch is that this version\n>> restores the original slash character rather than always restoring it\n>> to '/' (as suggested by Junio).\n>\n> Thanks Michael. This is very similar to Junio's current merge conflict\n> resultion in pu between your original series and my patch (c2fec83). I\n> like this patch of yours slightly better, however, as it uses a\n> \"while\" instead of a \"for\" loop and the more conclusive\n> \"slash_character\" than the \"was_slash\" variable name.\n\nYeah, I agree this patch that uses more descriptive names is a much\nmore desirable end-result than the tentative merge in 'pu'.\n"}]}