Skip to content

Commit c8df6a0

Browse files
committed
cleanup_path: force forward slashes on Windows
Git prefers forward slashes as directory separators across all platforms. On Windows, the backslash is the native directory separator, but all Windows versions supported by Git also accept the forward slash in all but rare circumstances. Our tests expect forward slashes. Git generates relative paths with forward slashes. Forward slashes are more convenient to use in shell scripts. For these reasons, we enforced forward slashes in `interpolate_path()` in 5ca6b7b (config --show-origin: report paths with forward slashes, 2016-03-23). However, other code paths may generate paths containing backslashes. For example, `config --show-origin` prints the XDG config path with mixed slashes on Windows: $ git config --list --show-origin file:C:/Program Files/Git/etc/gitconfig system.foo=bar file:"C:\\Users\\delilah/.config/git/config" xdg.foo=bar file:C:/Users/delilah/.gitconfig home.foo=bar file:.git/config local.foo=bar Let's enforce forward slashes in all code paths that directly or indirectly call `cleanup_path()` by modifying it to use `convert_slashes()` on Windows. Since `convert_slashes()` modifies the path in-place, change the argument and return type of `cleanup_path()` from `const char *` to `char *`. All existing callers of `cleanup_path()` pass `char *` anyways, so this change is compatible. The next patch, config: test home and xdg files in `list --global`, will assert that the XDG config path uses forward slashes. Suggested-by: Johannes Schindelin <[email protected]> Signed-off-by: Delilah Ashley Wu <[email protected]> Reviewed-by: Johannes Schindelin <[email protected]>
1 parent ca2559c commit c8df6a0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

path.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ static struct strbuf *get_pathname(void)
4040
return sb;
4141
}
4242

43-
static const char *cleanup_path(const char *path)
43+
static char *cleanup_path(char *path)
4444
{
4545
/* Clean it up */
46-
if (skip_prefix(path, "./", &path)) {
46+
if (skip_prefix(path, "./", (const char **)&path))
4747
while (*path == '/')
4848
path++;
49-
}
49+
50+
#ifdef GIT_WINDOWS_NATIVE
51+
convert_slashes(path);
52+
#endif
53+
5054
return path;
5155
}
5256

0 commit comments

Comments
 (0)