Skip to content

Commit 561d5c1

Browse files
kbleesdscho
authored andcommitted
trim_last_path_component(): avoid hard-coding the directory separator
Currently, this function hard-codes the directory separator as the forward slash. However, on Windows the backslash character is valid, too. And we want to call this function in the upcoming support for symlinks on Windows with the symlink targets (which naturally use the canonical directory separator on Windows, which is _not_ the forward slash). Prepare that function to be useful also in that context. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2c555f5 commit 561d5c1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lockfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ static void trim_last_path_component(struct strbuf *path)
1919
int i = path->len;
2020

2121
/* back up past trailing slashes, if any */
22-
while (i && path->buf[i - 1] == '/')
22+
while (i && is_dir_sep(path->buf[i - 1]))
2323
i--;
2424

2525
/*
2626
* then go backwards until a slash, or the beginning of the
2727
* string
2828
*/
29-
while (i && path->buf[i - 1] != '/')
29+
while (i && !is_dir_sep(path->buf[i - 1]))
3030
i--;
3131

3232
strbuf_setlen(path, i);

0 commit comments

Comments
 (0)