[PATCH 2 of 4] extensions: improving iteration on paths for disabled extensions

Cédric Duval cedricduval at free.fr
Sun Jun 21 09:40:09 CDT 2009


# HG changeset patch
# User Cédric Duval <cedricduval at free.fr>
# Date 1245594909 -7200
# Node ID 3760529b6e07abccabb6900f9fa93d18ff3ae324
# Parent  69c98c3a44e313d8dd767239f603d27ae2e2079c
extensions: improving iteration on paths for disabled extensions

 - using list comprehension instead of filter()
 - checking path only when that makes sense
 - checking into _order instead of try: find()

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -141,8 +141,9 @@
     exts = {}
     maxlength = 0
 
-    for dir in filter(os.path.isdir,
-                      (os.path.join(pd, 'hgext') for pd in pathdirs())):
+    for dir in [ os.path.join(pd, 'hgext') for pd in pathdirs() ]:
+        if not os.path.isdir(dir):
+            continue
         for e in os.listdir(dir):
             if e.endswith('.py'):
                 name = e.rsplit('.', 1)[0]
@@ -150,18 +151,13 @@
             else:
                 name = e
                 path = os.path.join(dir, e, '__init__.py')
+                if not os.path.exists(path):
+                    continue
 
-            if name in exts or name == '__init__' or not os.path.exists(path):
+            if name in exts or name in _order or name == 'init':
                 continue
 
             try:
-                find(name)
-            except KeyError:
-                pass
-            else:
-                continue # enabled extension
-
-            try:
                 file = open(path)
             except IOError:
                 continue



More information about the Mercurial-devel mailing list