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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Aug 20 03:33:31 CDT 2012


At Mon, 20 Aug 2012 17:13:26 +0900,
FUJIWARA Katsunori wrote:
> 
> 
> At Mon, 20 Aug 2012 01:52:31 +0200,
> Mads Kiilerich wrote:
> > 
> > Patrick Mezard wrote, On 08/18/2012 04:48 PM:
> > > # HG changeset patch
> > > # User Patrick Mezard <patrick at mezard.eu>
> > > # Date 1345146027 -7200
> > > # Node ID d5e4db676f3058b883426cb9a9a8fda3cdce145a
> > > # Parent  a10f7eeb2588ae469b996288b0d2554ccbe409da
> > > ui: add normpathfn() to get a conversion function for ui.slash
> > 
> > I agree with the general direction of this.
> > 
> > 'normpath' does a lot of normalization - much more than ui.slash should 
> > control according to its documentation. I think it would be better to 
> > introduce 'normslash' functionality which either would do nothing or 
> > replace '\' with '/' and nothing more.
> 
> What about adding "path()" or something like it to "ui" to get path in
> required style ?
> 
>     def path(self, p):
>         if os.sep != '/' and self.configbool('ui', 'slash'):
>             return util.pconvert(p)
>         else:
>             return util.localpath(p)
>
> or, for efficiency in loops:
> 
>     def pathfn(self):
>         if os.sep != '/' and self.configbool('ui', 'slash'):
>             return (lambda x: util.pconvert(x))
>         else:
>             return (lambda x: util.localpath(x))
> 
> and apply returned function on each paths in loops.

Oops, I misunderstand that "normpathfn()" is added to "dirstate" by
Patrick's patch, sorry.

Please ignore my proposal other than careing about "util.localpath()".


> Even if "util.pconvert()" is not required, "util.localpath()" should
> be applied on paths to unify path separators in them.
> 
> For example, in code path below in "commands.locate()", repo-root part
> of "repo.wjoin()" uses '\' as path separator, but "abs" part of it
> uses '/'.
> 
>     for abs in repo[rev].walk(m):
>         if not rev and abs not in repo.dirstate:
>             continue
>         if opts.get('fullpath'):
>             ui.write(repo.wjoin(abs), end)
>         else:
>             ui.write(((pats and m.rel(abs)) or abs), end)
>         ret = 0
> 
> So, in 'fullpath' case, written paths use both '/' and '\' on Windows.
> 
> in non-'fullpath' case, "m.rel(abs)" is fully localpath-ed, but "abs"
> itself uses '/', so path separator is switched by specifying 'pats'.
> 
> I'm just working about this path separator mixing/switching problem of
> "hg locate", but I had forgotten about 'ui.slash' configuration and
> implemented code is not yet tested on Windows.
> 
> So, I'm glad if issue1621 fixing would also care about this path
> separator unification directly or indirectly.
> 
> 
> BTW, are there any reason to use "util.normpath()" instead of
> "util.pconvert()" in "dirstate.pathto()" ? 
> 
>     def pathto(self, f, cwd=None):
>         if cwd is None:
>             cwd = self.getcwd()
>         path = util.pathto(self._root, cwd, f)
>         if self._slash:
>             return util.normpath(path)
>         return path
> 
> 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 ?
> 
> ----------------------------------------------------------------------
> [FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
> 


----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list