Patchwork D8352: extensions: don't crash if __file__ not defined

login
register
mail settings
Submitter phabricator
Date April 1, 2020, 3:29 a.m.
Message ID <differential-rev-PHID-DREV-nbqiyjia44nmo2zqil32-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45954/
State New
Headers show

Comments

phabricator - April 1, 2020, 3:29 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This attribute isn't present in PyOxidizer when loading modules
  from memory.
  
  Before, this code was crashing under PyOxidizer. After, it simply
  yields unexpected results. This still isn't great (we need a better
  mechanism to discover extensions when modules aren't loaded from
  the filesystem). But it is strictly better since we no longer
  get tracebacks.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/extensions.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - April 1, 2020, 8:17 a.m.
This revision now requires changes to proceed.
marmoute added inline comments.
marmoute requested changes to this revision.

INLINE COMMENTS

> extensions.py:709
>  
> +    # __file__ not always present.
> +    if not util.safehasattr(hgext, "__file__"):

Maybe mention that the result if "wrong" here? If I understand you commit message fine, this change does not make this code work as expected. It only prevent a crash. If I got this right, it would be useful to mention it in the comment.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8352/new/

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

To: indygreg, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -706,6 +706,10 @@ 
     '''find paths of disabled extensions. returns a dict of {name: path}'''
     import hgext
 
+    # __file__ not always present.
+    if not util.safehasattr(hgext, "__file__"):
+        return {}
+
     extpath = os.path.dirname(
         os.path.abspath(pycompat.fsencode(hgext.__file__))
     )