[PATCH] distat: fix performance regression from issue 1286

Petr Kodl petrkodl at gmail.com
Mon Sep 8 15:18:38 CDT 2008


# HG changeset patch
# User Petr Kodl <petrkodl at gmail.com>
# Date 1220905070 14400
# Node ID a7c7ac0b887ada0040b4645069467ae088c4094c
# Parent  cf9fc0ea03258aede94f6ba98ae936d4b5d030b4
distat: fix performance regression from issue 1286

diff -r cf9fc0ea0325 -r a7c7ac0b887a mercurial/dirstate.py
--- a/mercurial/dirstate.py	Mon Sep 08 16:14:47 2008 -0400
+++ b/mercurial/dirstate.py	Mon Sep 08 16:17:50 2008 -0400
@@ -43,7 +43,7 @@
         elif name == '_foldmap':
             _foldmap = {}
             for name in self._map:
-                norm = os.path.normcase(os.path.normpath(name))
+                norm = os.path.normcase(name)
                 _foldmap[norm] = name
             self._foldmap = _foldmap
             return self._foldmap
@@ -94,7 +94,9 @@
             if self._checkcase:
                 self.normalize = self._normalize
             else:
-                self.normalize = lambda x: x
+                def dummy_normalize(self, path, defaultPath=None): 
+                    return path
+                self.normalize = dummy_normalize
             return self.normalize
         else:
             raise AttributeError(name)
@@ -345,14 +347,16 @@
             del self._map[f]
         except KeyError:
             self._ui.warn(_("not in dirstate: %s\n") % f)
-
-    def _normalize(self, path):
-        norm_path = os.path.normcase(os.path.normpath(path))
-        if norm_path not in self._foldmap:
+    
+    def _normalize(self, path, defaultPath = None):
+        norm_path = os.path.normcase(path)
+        fold_path = self._foldmap.get(norm_path,defaultPath)
+        if fold_path is None:
             if not os.path.exists(os.path.join(self._root, path)):
                 return path
-            self._foldmap[norm_path] = util.fspath(path, self._root)
-        return self._foldmap[norm_path]
+            else:
+                fold_path = self._foldmap.setdefault(norm_path,util.fspath(path, self._root))
+        return fold_path
 
     def clear(self):
         self._map = {}
@@ -502,6 +506,7 @@
                             results[nf] = None
 
         # step 2: visit subdirectories
+        os_sep = os.sep
         while work:
             nd = work.pop()
             if hasattr(match, 'dir'):
@@ -518,7 +523,8 @@
                         and entries[hg][1] == dirkind:
                         continue
             for f, kind, st in entries:
-                nf = normalize(nd and (nd + "/" + f) or f)
+                nf = nd and (nd + os_sep + f) or f
+                nf = normalize(nf,nf)
                 if nf not in results:
                     if kind == dirkind:
                         if not ignore(nf):
@@ -533,7 +539,7 @@
                             results[nf] = st
                     elif nf in dmap and matchfn(nf):
                         results[nf] = None
-
+                        
         # step 3: report unseen items in the dmap hash
         visit = [f for f in dmap if f not in results and match(f)]
         for nf in util.sort(visit):
@@ -598,6 +604,6 @@
                 aadd(fn)
             elif state == 'r':
                 radd(fn)
-
+                
         return (lookup, modified, added, removed, deleted, unknown, ignored,
                 clean)


More information about the Mercurial-devel mailing list