changeset 49780:9d8757ddd0ab stable

extensions: process disabled external paths when `hgext` package is in-memory This fixes `hg help -e ambiguous` in test-helpt.t:2055 with the `ambiguous = !./ambiguous.py` configuration, when `hgext` is not in the filesystem (e.g. pyoxidizer builds with in-memory resources, or TortoiseHg with py2exe), but the disabled external extension is. Now instead of aborting with a suggestion to try `--keyword`, the help command prints text for the extension.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 07 Dec 2022 11:26:07 -0500
parents 7d6c8943353a
children f4a363b25859
files mercurial/extensions.py
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/extensions.py	Mon Dec 05 15:14:33 2022 -0500
+++ b/mercurial/extensions.py	Wed Dec 07 11:26:07 2022 -0500
@@ -729,6 +729,8 @@
     '''find paths of disabled extensions. returns a dict of {name: path}'''
     import hgext
 
+    exts = {}
+
     # The hgext might not have a __file__ attribute (e.g. in PyOxidizer) and
     # it might not be on a filesystem even if it does.
     if util.safehasattr(hgext, '__file__'):
@@ -738,23 +740,21 @@
         try:
             files = os.listdir(extpath)
         except OSError:
-            return {}
-    else:
-        return {}
+            pass
+        else:
+            for e in files:
+                if e.endswith(b'.py'):
+                    name = e.rsplit(b'.', 1)[0]
+                    path = os.path.join(extpath, e)
+                else:
+                    name = e
+                    path = os.path.join(extpath, e, b'__init__.py')
+                    if not os.path.exists(path):
+                        continue
+                if name in exts or name in _order or name == b'__init__':
+                    continue
+                exts[name] = path
 
-    exts = {}
-    for e in files:
-        if e.endswith(b'.py'):
-            name = e.rsplit(b'.', 1)[0]
-            path = os.path.join(extpath, e)
-        else:
-            name = e
-            path = os.path.join(extpath, e, b'__init__.py')
-            if not os.path.exists(path):
-                continue
-        if name in exts or name in _order or name == b'__init__':
-            continue
-        exts[name] = path
     for name, path in _disabledextensions.items():
         # If no path was provided for a disabled extension (e.g. "color=!"),
         # don't replace the path we already found by the scan above.