safe_create_leading_directories(): on Windows, \ can separate path components
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(). This patch, including its entire commit message, is derived from a patch by Sebastian Schuberth. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 19, 2014 at 00:40 UTC
0f5274033ecb0262dc77e4ed48fdb1ab07181bd8
1 file changed
+8
-4
sha1_file.c
+8
-4
@@ -112,17 +112,21 @@ enum scld_error safe_create_leading_directories(char *path)
112
113
while (ret == SCLD_OK && next_component) {
114
struct stat st;
115
- char *slash = strchr(next_component, '/');
115
+ char *slash = next_component, slash_character;
116
117
- if (!slash)
117
+ while (*slash && !is_dir_sep(*slash))
118
+ slash++;
119
+
120
+ if (!*slash)
121
break;
122
123
next_component = slash + 1;
121
- while (*next_component == '/')
124
+ while (is_dir_sep(*next_component))
125
next_component++;
126
if (!*next_component)
127
break;
128
129
+ slash_character = *slash;
130
*slash = '\0';
131
if (!stat(path, &st)) {
132
/* path exists */
@@ -148,7 +152,7 @@ enum scld_error safe_create_leading_directories(char *path)
152
} else if (adjust_shared_perm(path)) {
153
ret = SCLD_PERMS;
154
}
151
- *slash = '/';
155
+ *slash = slash_character;
156
}
157
return ret;
158
}