Path fun on Windows

Mads Kiilerich mads at kiilerich.com
Wed Jun 6 06:49:50 CDT 2012


On 06/06/12 11:54, Adrian Buehlmann wrote:
> So I'm seeing some other nastyness with paths while trying to enable more tests
> for Windows.

...

It seems to me like one piece of a better handling of windows 
path/filenames would be if Mercurial always used '/' paths internally - 
kind of similar to how all internal paths are 'encoded' (especially when 
we get the VFS layer).

Windows paths should be normalized as early as possible - when parsing 
the command line or when returned from the FS layer. A simple a + '/' + 
b would (almost) always be fine - os.path.join should (almost) never be 
used.

Paths shown to the user could be changed back to '\' in the ui layer if 
ui.slash is false. The current handling of ui.slash is however so 
incomplete and unreliable that we perhaps just could drop it and always 
show '/' paths on windows - that would probably cause less problems than 
fixing ui.slash=false.

I think that consistent use of '/' would make it possible to remove some 
path canonicalizations from the code and make some of the complex code 
simpler, leaving it to focus on handling casing and 'unicode' normalization.

>    rename a single file using absolute paths
>
>      $ hg rename "`pwd`/d1/d11/a1" "`pwd`/d2/c"
>
> Running test-a.t on Windows with MSYS yields:
>
>    --- C:/Users/adi/hgrepos/hg-main/tests\test-a.t
>    +++ C:/Users/adi/hgrepos/hg-main/tests\test-a.t.err
>    @@ -7,3 +7,5 @@
>     rename a single file using absolute paths
>
>       $ hg rename "`pwd`/d1/d11/a1" "`pwd`/d2/c"
>    +  abort: $TESTTMP/d1/d11/a1 not under root
>    +  [255]

I assume it also can be reproduced with plain windows in a command prompt?

> No, we get to yet another MSYS magic: pwd -W
>
> Example chat with sh.exe of MSYS:
>
>    adi at kork /tmp/hgtests.77lj6e
>    $ pwd
>    /tmp/hgtests.77lj6e
>
>    adi at kork /tmp/hgtests.77lj6e
>    $ pwd -W
>    C:/Users/adi/AppData/Local/Temp/hgtests.77lj6e
>
> So what does this have to do with run-tests.py?
>
> run-tests.py does:
>
> 617    if os.getenv('MSYSTEM'):
> 618        script.append('alias pwd="pwd -W"\n')
>
> So, it prepends a clever alias at the cooked skript, which makes sure that
> "pwd" inside a script is in fact "pwd -W".

That hack was a quick way to get something up and running with msys. It 
is possible that there are better ways to do it - especially now when we 
understand msys path mangling better.

/Mads


More information about the Mercurial-devel mailing list