Patchwork D8750: extensions: make `hg nonexistent` not crash with PyOxidizer

login
register
mail settings
Submitter phabricator
Date July 14, 2020, 8:18 p.m.
Message ID <differential-rev-PHID-DREV-hy6zofbk44cukg6w6aa6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46747/
State Superseded
Headers show

Comments

phabricator - July 14, 2020, 8:18 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  When running `hg nonexistent`, we try to look for extensions that
  provide that command. We do that by looking for files in the
  `hgext.__file__` directory. However, PyOxidizer doesn't provide a
  `__file__`, so we crash when running with PyOxidizer.
  
  We should be able to look for the command in built-in extensions, but
  we seem to already have code for skipping the scan when running in a
  frozen binary, so I just modified that code instead.
  
  By the way, it also seems like we should be able to search for
  extensions in the `hgext3rd` module, but we don't do that yet either
  (before or after this patch).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8750

AFFECTED FILES
  mercurial/extensions.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -706,12 +706,17 @@ 
     '''find paths of disabled extensions. returns a dict of {name: path}'''
     import hgext
 
-    extpath = os.path.dirname(
-        os.path.abspath(pycompat.fsencode(hgext.__file__))
-    )
-    try:  # might not be a filesystem path
-        files = os.listdir(extpath)
-    except OSError:
+    # 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__'):
+        extpath = os.path.dirname(
+            os.path.abspath(pycompat.fsencode(hgext.__file__))
+        )
+        try:
+            files = os.listdir(extpath)
+        except OSError:
+            return {}
+    else:
         return {}
 
     exts = {}