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

[PATCH v2 0/5] Last preparations before upstreaming Git for Windows' symlink support

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 9, 2026, 20:05 UTC
Message-ID
<pull.2017.v2.git.1767989109.gitgitgadget@gmail.com>
In-Reply-To
<pull.2017.git.1765899229.gitgitgadget@gmail.com>

After preparing Git's test suite for the upcoming support for symlinks on Windows, this patch series touches up a couple of code paths that might not seem to be related at first, but need to be adjusted for the symlink support to work as expected.

This is based on js/test-symlink-windows.
Changes since v1:
 * Fixed Karsten's email address
 * Instead of allowing unlimited symlink target lengths, it is now increased
   from 2*PATH_MAX to 32,767.
Johannes Schindelin (3):
  mingw: do resolve symlinks in `getcwd()`
  init: do parse _all_ core.* settings early
  strbuf_readlink(): support link targets that exceed 2*PATH_MAX
Karsten Blees (2):
  strbuf_readlink(): avoid calling `readlink()` twice in corner-cases
  trim_last_path_component(): avoid hard-coding the directory separator
 compat/mingw.c | 18 +++++++-----------
 environment.c  |  4 ++--
 environment.h  |  2 ++
 lockfile.c     |  4 ++--
 setup.c        |  2 +-
 strbuf.c       |  8 ++++----
 6 files changed, 18 insertions(+), 20 deletions(-)
base-commit: ef6dd000ad813fc34a05c4b9055578df13a2eaa6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2017%2Fdscho%2Flast-preparations-before-mingw-symlinks-support-next-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2017/dscho/last-preparations-before-mingw-symlinks-support-next-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2017
Range-diff vs v1:
 1:  1928738b464 = 1:  eb95a74d6eb mingw: do resolve symlinks in `getcwd()`
 2:  31497b01988 = 2:  9fee7bd16f5 init: do parse _all_ core.* settings early
 3:  dba281027a8 ! 3:  7fe463d68aa strbuf_readlink(): avoid calling `readlink()` twice in corner-cases
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          strbuf_readlink(): avoid calling `readlink()` twice in corner-cases
     @@ Commit message
      
          Use `hint + 1` as buffer size to prevent this.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## strbuf.c ##
 4:  db1feb2293d ! 4:  accb6d5f0ae strbuf_readlink(): support link targets that exceed PATH_MAX
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>
      
       ## Commit message ##
     -    strbuf_readlink(): support link targets that exceed PATH_MAX
     +    strbuf_readlink(): support link targets that exceed 2*PATH_MAX
      
          The `strbuf_readlink()` function refuses to read link targets that
     -    exceed PATH_MAX (even if a sufficient size was specified by the caller).
     +    exceed 2*PATH_MAX (even if a sufficient size was specified by the
     +    caller).
      
     -    As some platforms (*cough* Windows *cough*) support longer paths, remove
     -    this restriction (similar to `strbuf_getcwd()`).
     +    The reason that that limit is 2*PATH_MAX instead of PATH_MAX is that
     +    the symlink targets do not need to be normalized. After running
     +    `ln -s a/../a/../a/../a/../b c`, the target of the symlink `c` will not
     +    be normalized to `b` but instead be much longer. As such, symlink
     +    targets' lengths can far exceed PATH_MAX.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    They are frequently much longer than 2*PATH_MAX on Windows, which
     +    actually supports paths up to 32,767 characters, but sets PATH_MAX to
     +    260 for backwards compatibility. For full details, see
     +    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
     +
     +    Let's just hard-code the limit used by `strbuf_readlink()` to 32,767 and
     +    make it independent of the current platform's PATH_MAX.
     +
     +    Based-on-a-patch-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## strbuf.c ##
     @@ strbuf.c: ssize_t strbuf_write(struct strbuf *sb, FILE *f)
       }
       
      -#define STRBUF_MAXLINK (2*PATH_MAX)
     --
     ++#define STRBUF_MAXLINK (32767)
     + 
       int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
       {
     - 	size_t oldalloc = sb->alloc;
     -@@ strbuf.c: int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
     - 	if (hint < 32)
     - 		hint = 32;
     - 
     --	while (hint < STRBUF_MAXLINK) {
     -+	for (;;) {
     - 		ssize_t len;
     - 
     - 		strbuf_grow(sb, hint + 1);
 5:  3521180e0f7 ! 5:  9823cbb6df8 trim_last_path_component(): avoid hard-coding the directory separator
     @@
       ## Metadata ##
     -Author: Karsten Blees <blees@dcon.de>
     +Author: Karsten Blees <karsten.blees@gmail.com>
      
       ## Commit message ##
          trim_last_path_component(): avoid hard-coding the directory separator
     @@ Commit message
      
          Prepare that function to be useful also in that context.
      
     -    Signed-off-by: Karsten Blees <blees@dcon.de>
     +    Signed-off-by: Karsten Blees <karsten.blees@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## lockfile.c ##
-- 
gitgitgadget
Previous: Karsten Blees via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 14 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.