[PATCH 1 of 2] ui: add normpathfn() to get a conversion function for ui.slash

Mads Kiilerich mads at kiilerich.com
Mon Aug 20 06:39:02 CDT 2012


On 20/08/12 10:13, FUJIWARA Katsunori wrote:
> Even if "util.pconvert()" is not required, "util.localpath()" should
> be applied on paths to unify path separators in them.

I don't necessarily agree on that one. The idea for displaying this kind 
of paths should be to display it in the users preferred style, and it 
should thus not necessarily do other kinds of normalization.

Besides that: pathto is usually used to convert from internal paths to 
paths suitable for displaying. The path we get here will thus already be 
fully normalized.

But in general it seems like we have a huge mess with different kinds of 
paths, and with conversions and normalizations added whereever they for 
some reason turned out to be necessary. It would be nice to have a more 
clear layering and stronger typing of the path types. Using something 
else than plain strings for representing paths could perhaps help 
verifying that ... but would probably also be slower.

> If "os.path.normpath()" invocation is required on Windows,
> "os.path.normpath()" should be also applied on "path" in "NOT
> self._slash" case, shouldn't it ?

I agree that it probably should be that way if ui.slash _really_ should 
make sense.

I would actually like to move in the opposite direction and _always_ use 
'/' as path separator internally, converting from native '\' in the vfs 
layer and in match.match, and only convert to '\' in the ui layer if 
requested by ui.slash.

That will however also raise the question: Who cares about the kind of 
slashes emitted by hg on windows? Paths shown by hg might be used by 
scripts or cut'n'pasted to a commandline, but it will very often be 
internal paths anyway. ui.slash is today buggy and do not work in as 
many places as announced, but do it make sense to 'fix' it and make it 
work 'everywhere'? Wouldn't it be better to abandon it and just always 
use '/' in output?


Btw: Most of the unexpected '\' related problems on windows are caused 
by paths in 'saved backup bundle' or path validation aborts. There is no 
simple clean way to make them adhere to ui.slash. I did some experiments 
in 
https://bitbucket.org/kiilerix/mercurial-crew/src/f7dd765159fe/normslash 
... but didn't like it very much.

/Mads



More information about the Mercurial-devel mailing list