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

Re: Bug in get_pwd_cwd() in Windows?

From
René Scharfe <l.s.r@web.de>
Date
Jul 22, 2014, 19:35 UTC
Message-ID
<53CEBD13.5040004@web.de>
In-Reply-To
<CACsJy8BY8pyuZ0eY7qK86RGUh8Vp9FVE55TskcQhBTrwwPowEQ@mail.gmail.com>
Am 21.07.2014 16:13, schrieb Duy Nguyen:
Show 6 quoted lines
> This function tests if $PWD is the same as getcwd() using st_dev and
> st_ino. But on Windows these fields are always zero
> (mingw.c:do_lstat). If cwd is moved away, I think falling back to $PWD
> is wrong. I don't understand the use of $PWD in the first place.
> 1b9a946 (Use nonrelative paths instead of absolute paths for cloned
> repositories - 2008-06-05) does not explain much.
The commit message reads:
   Particularly for the "alternates" file, if one will be created, we
   want a path that doesn't depend on the current directory, but we want
   to retain any symlinks in the path as given and any in the user's view
   of the current directory when the path was given.

The intent of the patch seems to be to prefer $PWD if it points to the same directory as the one returned by getcwd() in order to preserve "the user's view". That's why it introduces make_nonrelative_path() (now called absolute_path()), in contrast to make_absolute_path() (now called real_path()).

I imagine it's useful e.g. if your home is accessed through a symlink:
	/home/foo -> /some/boring/mountpoint

Then real_path("bar") would give you "/some/boring/mountpoint/bar", while absolute_path("bar") returned "/home/foo/bar". Not resolving symlinks keeps the path friendly in this case. And it keeps working even after the user's home is migrated to /a/bigger/partition and /home/foo is updated accordingly.

René
Previous: Duy NguyenNext: Duy Nguyen
Message 2 of 4 in “Bug in get_pwd_cwd() in Windows?”
  1. Duy NguyenJul 21, 2014
  2. René ScharfeJul 22, 2014
  3. Duy NguyenJul 23, 2014
  4. Karsten BleesJul 23, 2014

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.