Skip to content

Commit 89b6531

Browse files
committed
path: use forward slashes for XDG config on windows
Windows uses backslashes as directory separators. A previous patch [1] converted backslashes to forward slashes in the `config --show-origin` output on Windows. However, we missed the XDG config path which still uses backslashes. To reproduce the issue on Windows: 1. Populate `$XDG_CONFIG_HOME/git/config`. For example, [xdg] foo = bar 2. Ensure some other file is being sourced for config, e.g. system. 3. Run `git config --list --show-origin`. The XDG path contains backslashes, while the other paths contain forward slashes: 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 For the same reasons as in [1], > All supported Windows versions also accept the forward slash in > most circumstances. > Our tests expect forward slashes. > Relative paths are generated by Git using forward slashes. We should be consistent and use forward slashes in the XDG path as well. There are several places to insert a call to `convert_slashes(path)`. I chose `cleanup_path()` because the name suggests some form of normalisation and it is already called in the relevant code paths. Discard the constness of `cleanup_path()` to modifying the path in place. It calls `skip_prefix(..., const char **out)`, which sets `**out` to some point in the original string. Hence, it seems we can safely cast `char**` to `const char**`` for this purpose. But please correct me if I'm wrong! [1]: https://lore.kernel.org/git/8beb1c208e33e1de8f272caa22fb7a0b662ca4cc.1458730457.git.johannes.schindelin@gmx.de/ Suggested-by: Johannes Schindelin <[email protected]> Signed-off-by: Delilah Ashley Wu <[email protected]>
1 parent a483264 commit 89b6531

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)