[PATCH 3 of 3] Add a normalize() method to dirstate

Paul Moore p.f.moore at gmail.com
Tue Jun 3 11:55:34 CDT 2008


# HG changeset patch
# User "Paul Moore <p.f.moore at gmail.com>"
# Date 1211629656 -3600
# Node ID 59d7def0c2b137dbfd40d644af28ef97216a3388
# Parent  025ba311a38a094fac501ccf81c5aaa62e895466
Add a normalize() method to dirstate

This method returns the normalised form of a path. This is
  - the form in the dirstate, if available, or
  - the form on disk, if available, or
  - the form passed on the command line
normalize() is called on the type-'f' result of statwalk.

This fixes issues 910 and 1092

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -31,6 +31,13 @@
         elif name == '_copymap':
             self._read()
             return self._copymap
+        elif name == '_foldmap':
+            _foldmap = {}
+            for name, value in self._map.items():
+                norm = os.path.normcase(os.path.normpath(name))
+                _foldmap[norm] = value
+            self._foldmap = _foldmap
+            return self._foldmap
         elif name == '_branch':
             try:
                 self._branch = (self._opener("branch").read().strip()
@@ -69,6 +76,12 @@
         elif name == '_folding':
             self._folding = not util.checkfolding(self._join('.hg'))
             return self._folding
+        elif name == 'normalize':
+            if self._folding:
+                self.normalize = self._normalize
+            else:
+                self.normalize = lambda x: x
+            return self.normalize
         else:
             raise AttributeError, name
 
@@ -167,7 +180,7 @@
             dmap[f] = e # we hold onto e[4] because making a subtuple is slow
 
     def invalidate(self):
-        for a in "_map _copymap _branch _pl _dirs _ignore".split():
+        for a in "_map _copymap _foldmap _branch _pl _dirs _ignore".split():
             if a in self.__dict__:
                 delattr(self, a)
         self._dirty = False
@@ -319,6 +332,16 @@
             del self._map[f]
         except KeyError:
             self._ui.warn(_("not in dirstate: %s\n") % f)
+
+    def _normalize(self, path):
+        normpath = os.path.normcase(os.path.normpath(path))
+        if normpath in self._foldmap:
+            return self._foldmap[normpath]
+        elif os.path.exists(path):
+            self._foldmap[normpath] = util.fspath(path, self._root)
+            return self._foldmap[normpath]
+        else:
+            return path
 
     def clear(self):
         self._map = {}
@@ -561,7 +584,7 @@
                 known[nf] = 1
                 if match(nf):
                     if supported(ff, st.st_mode, verbose=True):
-                        yield 'f', nf, st
+                        yield 'f', self.normalize(nf), st
                     elif ff in dc:
                         yield 'm', nf, st
 


More information about the Mercurial-devel mailing list