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

Patrick Mezard patrick at mezard.eu
Sat Aug 18 09:48:06 CDT 2012


# 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

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.normpathfn()[0]
     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,11 @@
         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):
+        fn, normalizing = self._ui.normpathfn()
+        if normalizing:
+            return fn
+        return None
 
     @propertycache
     def _checklink(self):
@@ -201,8 +204,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,13 @@
         ui.write(ui.label(s, 'label')).
         '''
         return msg
+
+    def normpathfn(self):
+        '''Return (fn, normalizing) where fn is identity if normalizing
+        is False, or a function taking a path and converting its native
+        separators to forward slashes. The behaviour is driven by
+        ui.slash.
+        '''
+        if self.configbool('ui', 'slash') and os.sep != '/':
+            return util.normpath, True
+        return (lambda p: p), False


More information about the Mercurial-devel mailing list