[PATCH 1 of 2] ui: add normpathfn() to get a conversion function for ui.slash
Patrick Mezard
patrick at mezard.eu
Mon Aug 20 19:51:03 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1345491923 -7200
# Node ID 461b362c4778512578087e422ce3cdb4bc5ea3f7
# Parent a10f7eeb2588ae469b996288b0d2554ccbe409da
ui: add normpathfn() to get a conversion function for ui.slash
v2:
- Rename ui.normpathfn() into ui.normslashfn()
- Make it return only a callable, identity by default.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2438,9 +2438,7 @@
items = list(repo.walk(m))
if not items:
return
- f = lambda fn: fn
- if ui.configbool('ui', 'slash') and os.sep != '/':
- f = lambda fn: util.normpath(fn)
+ f = ui.normslashfn()
fmt = 'f %%-%ds %%-%ds %%s' % (
max([len(abs) for abs in items]),
max([len(m.rel(abs)) for abs in items]))
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -132,8 +132,8 @@
return ignore.ignore(self._root, files, self._ui.warn)
@propertycache
- def _slash(self):
- return self._ui.configbool('ui', 'slash') and os.sep != '/'
+ def _slashfn(self):
+ return self._ui.normslashfn(defaultfn=None)
@propertycache
def _checklink(self):
@@ -201,8 +201,8 @@
if cwd is None:
cwd = self.getcwd()
path = util.pathto(self._root, cwd, f)
- if self._slash:
- return util.normpath(path)
+ if self._slashfn:
+ return self._slashfn(path)
return path
def __getitem__(self, key):
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -759,3 +759,11 @@
ui.write(ui.label(s, 'label')).
'''
return msg
+
+ def normslashfn(self, defaultfn=lambda fn: fn):
+ '''Return a path separator normalizing function, depending on
+ the ui.slash setting. Default to identity.
+ '''
+ if self.configbool('ui', 'slash') and os.sep != '/':
+ return util.normpath
+ return defaultfn
More information about the Mercurial-devel
mailing list