]> git.ipfire.org Git - thirdparty/git.git/commitdiff
trim_last_path_component(): avoid hard-coding the directory separator
authorKarsten Blees <blees@dcon.de>
Tue, 16 Dec 2025 15:33:49 +0000 (15:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Dec 2025 23:21:07 +0000 (08:21 +0900)
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 <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c

index 1d5ed0168287464e24d60e30b0cfbce181676535..67082a9caaeb18a10090a08b1bdfb32d5f2c3765 100644 (file)
@@ -19,14 +19,14 @@ static void trim_last_path_component(struct strbuf *path)
        int i = path->len;
 
        /* back up past trailing slashes, if any */
-       while (i && path->buf[i - 1] == '/')
+       while (i && is_dir_sep(path->buf[i - 1]))
                i--;
 
        /*
         * then go backwards until a slash, or the beginning of the
         * string
         */
-       while (i && path->buf[i - 1] != '/')
+       while (i && !is_dir_sep(path->buf[i - 1]))
                i--;
 
        strbuf_setlen(path, i);