[PATCH 1 of 7 VFS] subrepo: use vfs.readdir instead of os.listdir to avoid expensive stat calls

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Apr 10 15:54:23 UTC 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1428680829 -32400
#      Sat Apr 11 00:47:09 2015 +0900
# Node ID 17c9d35176133223e44820d39b30146d06048b1f
# Parent  e0e28e910fa3797fd0aa4f818e9b33c5bcbf0e53
subrepo: use vfs.readdir instead of os.listdir to avoid expensive stat calls

"kind" information given from "vfs.readdir()" makes expensive stat
calls "os.path.isdir()" and "os.path.islink()" useless.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1632,11 +1632,11 @@ class gitsubrepo(abstractsubrepo):
         # local-only history
         self.ui.note(_('removing subrepo %s\n') % self._relpath)
         self._gitcommand(['config', 'core.bare', 'true'])
-        for f in os.listdir(self._abspath):
+        for f, kind in self.wvfs.readdir():
             if f == '.git':
                 continue
             path = os.path.join(self._abspath, f)
-            if os.path.isdir(path) and not os.path.islink(path):
+            if kind == stat.S_IFDIR:
                 shutil.rmtree(path)
             else:
                 os.remove(path)


More information about the Mercurial-devel mailing list