dirstate: only call lstat once per flags invocation
authorBryan O'Sullivan <bryano@fb.com>
Wed, 03 Apr 2013 11:35:27 -0700
changeset 18869 e8b4b139a545
parent 18868 cafa447a7d3b
child 18870 0f2eb3d16a1a
child 18871 a2d4ab4f575d
dirstate: only call lstat once per flags invocation This makes a big difference to performance in some cases. hg --time locate 'set:symlink()' mozilla-central (70,000 files): before: 2.92 sec after: 2.47 another repo (170,000 files): before: 7.87 sec after: 6.86
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Wed Apr 03 11:35:27 2013 -0700
+++ b/mercurial/dirstate.py	Wed Apr 03 11:35:27 2013 -0700
@@ -154,11 +154,14 @@
     def flagfunc(self, buildfallback):
         if self._checklink and self._checkexec:
             def f(x):
-                p = self._join(x)
-                if os.path.islink(p):
-                    return 'l'
-                if util.isexec(p):
-                    return 'x'
+                try:
+                    st = os.lstat(self._join(x))
+                    if util.statislink(st):
+                        return 'l'
+                    if util.statisexec(st):
+                        return 'x'
+                except OSError:
+                    pass
                 return ''
             return f