changeset 6677:9865e15febd0

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
author Paul Moore <p.f.moore@gmail.com>
date Fri, 06 Jun 2008 19:23:29 +0100
parents 33045179d079
children 76fc270561d1
files mercurial/dirstate.py
diffstat 1 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Fri Jun 06 19:23:23 2008 +0100
+++ b/mercurial/dirstate.py	Fri Jun 06 19:23:29 2008 +0100
@@ -31,6 +31,13 @@
         elif name == '_copymap':
             self._read()
             return self._copymap
+        elif name == '_foldmap':
+            _foldmap = {}
+            for name in self._map:
+                norm = os.path.normcase(os.path.normpath(name))
+                _foldmap[norm] = name
+            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
@@ -320,6 +333,16 @@
         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 = {}
         if "_dirs" in self.__dict__:
@@ -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