{"thread":{"id":"37181","subject":"Bug in get_pwd_cwd() in Windows?","startedAt":"2014-07-21T14:13:32Z","lastAt":"2014-07-23T12:40:21Z","messageCount":4,"participants":["Duy Nguyen","René Scharfe","Karsten Blees"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"246455","messageId":"CACsJy8BY8pyuZ0eY7qK86RGUh8Vp9FVE55TskcQhBTrwwPowEQ@mail.gmail.com","threadId":"37181","inReplyTo":null,"subject":"Bug in get_pwd_cwd() in Windows?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-07-21T14:13:32Z","receivedAt":"2014-07-21T14:13:32Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This function tests if $PWD is the same as getcwd() using st_dev and\nst_ino. But on Windows these fields are always zero\n(mingw.c:do_lstat). If cwd is moved away, I think falling back to $PWD\nis wrong. I don't understand the use of $PWD in the first place.\n1b9a946 (Use nonrelative paths instead of absolute paths for cloned\nrepositories - 2008-06-05) does not explain much.\n-- \nDuy\n"},{"id":"246517","messageId":"53CEBD13.5040004@web.de","threadId":"37181","inReplyTo":"CACsJy8BY8pyuZ0eY7qK86RGUh8Vp9FVE55TskcQhBTrwwPowEQ@mail.gmail.com","subject":"Re: Bug in get_pwd_cwd() in Windows?","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-07-22T19:35:47Z","receivedAt":"2014-07-22T19:35:47Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 21.07.2014 16:13, schrieb Duy Nguyen:\n> This function tests if $PWD is the same as getcwd() using st_dev and\n> st_ino. But on Windows these fields are always zero\n> (mingw.c:do_lstat). If cwd is moved away, I think falling back to $PWD\n> is wrong. I don't understand the use of $PWD in the first place.\n> 1b9a946 (Use nonrelative paths instead of absolute paths for cloned\n> repositories - 2008-06-05) does not explain much.\n\nThe commit message reads:\n\n   Particularly for the \"alternates\" file, if one will be created, we\n   want a path that doesn't depend on the current directory, but we want\n   to retain any symlinks in the path as given and any in the user's view\n   of the current directory when the path was given.\n\nThe intent of the patch seems to be to prefer $PWD if it points to the \nsame directory as the one returned by getcwd() in order to preserve \"the \nuser's view\".  That's why it introduces make_nonrelative_path() (now \ncalled absolute_path()), in contrast to make_absolute_path() (now called \nreal_path()).\n\nI imagine it's useful e.g. if your home is accessed through a symlink:\n\n\t/home/foo -> /some/boring/mountpoint\n\nThen real_path(\"bar\") would give you \"/some/boring/mountpoint/bar\", \nwhile absolute_path(\"bar\") returned \"/home/foo/bar\".  Not resolving \nsymlinks keeps the path friendly in this case.  And it keeps working \neven after the user's home is migrated to /a/bigger/partition and \n/home/foo is updated accordingly.\n\nRené\n"},{"id":"246552","messageId":"CACsJy8Ch6FvWp-pOOG4-kDVmb+kyav7oromH8EpeEesPj7B9Yg@mail.gmail.com","threadId":"37181","inReplyTo":"53CEBD13.5040004@web.de","subject":"Re: Bug in get_pwd_cwd() in Windows?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-07-23T11:53:30Z","receivedAt":"2014-07-23T11:53:30Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jul 23, 2014 at 2:35 AM, René Scharfe <l.s.r@web.de> wrote:\n> Am 21.07.2014 16:13, schrieb Duy Nguyen:\n>\n>> This function tests if $PWD is the same as getcwd() using st_dev and\n>> st_ino. But on Windows these fields are always zero\n>> (mingw.c:do_lstat). If cwd is moved away, I think falling back to $PWD\n>> is wrong. I don't understand the use of $PWD in the first place.\n>> 1b9a946 (Use nonrelative paths instead of absolute paths for cloned\n>> repositories - 2008-06-05) does not explain much.\n>\n>\n> The commit message reads:\n>\n>   Particularly for the \"alternates\" file, if one will be created, we\n>   want a path that doesn't depend on the current directory, but we want\n>   to retain any symlinks in the path as given and any in the user's view\n>   of the current directory when the path was given.\n>\n> The intent of the patch seems to be to prefer $PWD if it points to the same\n> directory as the one returned by getcwd() in order to preserve \"the user's\n> view\".  That's why it introduces make_nonrelative_path() (now called\n> absolute_path()), in contrast to make_absolute_path() (now called\n> real_path()).\n>\n> I imagine it's useful e.g. if your home is accessed through a symlink:\n>\n>         /home/foo -> /some/boring/mountpoint\n>\n> Then real_path(\"bar\") would give you \"/some/boring/mountpoint/bar\", while\n> absolute_path(\"bar\") returned \"/home/foo/bar\".  Not resolving symlinks keeps\n> the path friendly in this case.  And it keeps working even after the user's\n> home is migrated to /a/bigger/partition and /home/foo is updated\n> accordingly.\n\nIf it's saved back, then yes it's useful. And I think that's the case\nin clone.c. I was tempted to remove this code (because it only works\nif you stand at worktree's root dir anyway, else cwd is moved) but I\nguess we can just disable this code on Windows only instead.\n-- \nDuy\n"},{"id":"246556","messageId":"53CFAD35.1080604@gmail.com","threadId":"37181","inReplyTo":"CACsJy8Ch6FvWp-pOOG4-kDVmb+kyav7oromH8EpeEesPj7B9Yg@mail.gmail.com","subject":"Re: Bug in get_pwd_cwd() in Windows?","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-07-23T12:40:21Z","receivedAt":"2014-07-23T12:40:21Z","isPatch":false,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 23.07.2014 13:53, schrieb Duy Nguyen:\n> On Wed, Jul 23, 2014 at 2:35 AM, René Scharfe <l.s.r@web.de> wrote:\n>> Am 21.07.2014 16:13, schrieb Duy Nguyen:\n>>\n>>> This function tests if $PWD is the same as getcwd() using st_dev and\n>>> st_ino. But on Windows these fields are always zero\n>>> (mingw.c:do_lstat). If cwd is moved away, I think falling back to $PWD\n>>> is wrong. I don't understand the use of $PWD in the first place.\n>>> 1b9a946 (Use nonrelative paths instead of absolute paths for cloned\n>>> repositories - 2008-06-05) does not explain much.\n>>\n>>\n>> The commit message reads:\n>>\n>>   Particularly for the \"alternates\" file, if one will be created, we\n>>   want a path that doesn't depend on the current directory, but we want\n>>   to retain any symlinks in the path as given and any in the user's view\n>>   of the current directory when the path was given.\n>>\n>> The intent of the patch seems to be to prefer $PWD if it points to the same\n>> directory as the one returned by getcwd() in order to preserve \"the user's\n>> view\".  That's why it introduces make_nonrelative_path() (now called\n>> absolute_path()), in contrast to make_absolute_path() (now called\n>> real_path()).\n>>\n>> I imagine it's useful e.g. if your home is accessed through a symlink:\n>>\n>>         /home/foo -> /some/boring/mountpoint\n>>\n>> Then real_path(\"bar\") would give you \"/some/boring/mountpoint/bar\", while\n>> absolute_path(\"bar\") returned \"/home/foo/bar\".  Not resolving symlinks keeps\n>> the path friendly in this case.  And it keeps working even after the user's\n>> home is migrated to /a/bigger/partition and /home/foo is updated\n>> accordingly.\n> \n> If it's saved back, then yes it's useful. And I think that's the case\n> in clone.c. I was tempted to remove this code (because it only works\n> if you stand at worktree's root dir anyway, else cwd is moved) but I\n> guess we can just disable this code on Windows only instead.\n> \n\nIt is disabled on Windows as of 7d092adc get_pwd_cwd(): Do not trust st_dev/st_ino blindly\n"}]}