git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/5] trim_last_path_component(): avoid hard-coding the directory separator

From
Karsten Blees via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 9, 2026, 20:05 UTC
Message-ID
<9823cbb6df84eedfa40d7120d3949f70d2f960ba.1767989109.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2017.v2.git.1767989109.gitgitgadget@gmail.com>
From: Karsten Blees <karsten.blees@gmail.com>

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 <karsten.blees@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 lockfile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lockfile.c b/lockfile.c
index 1d5ed01682..67082a9caa 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -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);
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Junio C Hamano
Message 19 of 21 in “Last preparations before upstreaming Git for Windows' symlink support”
  1. 0/5 Last preparations before upstreaming Git for Windows' symlink supportJohannes Schindelin via GitGitGadget, Dec 16, 2025
  2. 1/5 mingw: do resolve symlinks in `getcwd()`Johannes Schindelin via GitGitGadget, Dec 16, 2025
  3. Patrick SteinhardtDec 17, 2025
  4. 2/5 init: do parse _all_ core.* settings earlyJohannes Schindelin via GitGitGadget, Dec 16, 2025
  5. Patrick SteinhardtDec 17, 2025
  6. 3/5 strbuf_readlink(): avoid calling `readlink()` twice in corner-casesKarsten Blees via GitGitGadget, Dec 16, 2025
  7. 4/5 strbuf_readlink(): support link targets that exceed PATH_MAXKarsten Blees via GitGitGadget, Dec 16, 2025
  8. Patrick SteinhardtDec 17, 2025
  9. Johannes SchindelinDec 19, 2025
  10. Patrick SteinhardtDec 19, 2025
  11. Junio C HamanoDec 30, 2025
  12. Junio C HamanoDec 17, 2025
  13. 5/5 trim_last_path_component(): avoid hard-coding the directory separatorKarsten Blees via GitGitGadget, Dec 16, 2025
  14. 0/5 Last preparations before upstreaming Git for Windows' symlink supportJohannes Schindelin via GitGitGadget, Jan 9, 2026
  15. 1/5 mingw: do resolve symlinks in `getcwd()`Johannes Schindelin via GitGitGadget, Jan 9, 2026
  16. 2/5 init: do parse _all_ core.* settings earlyJohannes Schindelin via GitGitGadget, Jan 9, 2026
  17. 3/5 strbuf_readlink(): avoid calling `readlink()` twice in corner-casesKarsten Blees via GitGitGadget, Jan 9, 2026
  18. 4/5 strbuf_readlink(): support link targets that exceed 2*PATH_MAXJohannes Schindelin via GitGitGadget, Jan 9, 2026
  19. 5/5 trim_last_path_component(): avoid hard-coding the directory separatorKarsten Blees via GitGitGadget, Jan 9, 2026
  20. Junio C HamanoJan 11, 2026
  21. Patrick SteinhardtJan 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.