( )⚙ D1024 hgweb: do not import uuid immediately to avoid its side effect

This is an archive of the discontinued Mercurial Phabricator instance.

hgweb: do not import uuid immediately to avoid its side effect
ClosedPublic

Authored by quark on Oct 12 2017, 1:02 AM.

Details

Summary

With hgdemandimport disabled (chg's case), import uuid has an immediate
side effect calling ctypes.util.find_library trying to locate the
libuuid library. This happens at import time before dispatch.run().
The call trace is like:

File "hg/hg", line 54, in <module>
  from mercurial import (
File "hg/mercurial/dispatch.py", line 24, in <module>
  from . import (
File "hg/mercurial/commands.py", line 23, in <module>
  from . import (
File "hg/mercurial/help.py", line 33, in <module>
  from .hgweb import (
File "hg/mercurial/hgweb/__init__.py", line 20, in <module>
  from . import (
File "hg/mercurial/hgweb/hgweb_mod.py", line 14, in <module>
  from .common import (
File "hg/mercurial/hgweb/common.py", line 15, in <module>
  import uuid
File "/usr/lib64/python2.7/uuid.py", line 404, in <module>
  lib = ctypes.CDLL(ctypes.util.find_library(libname))

The problem is, ctypes.util.find_library will execute
sh -c '/sbin/ldconfig -p 2>/dev/null' on Python <= 2.7.12. The output of
sh may pollute the terminal:

shell-init: error retrieving current directory: getcwd: cannot access
parent directories: No such file or directory

This patch moves import uuid so its side-effect can only happen after the
cwd check in dispatch._getlocal. Therefore the terminal won't be
polluted by importing uuid.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

quark created this revision.Oct 12 2017, 1:02 AM
quark updated this revision to Diff 2613.Oct 12 2017, 1:04 AM
av6 accepted this revision.Oct 12 2017, 7:16 AM
This revision is now accepted and ready to land.Oct 12 2017, 7:16 AM
yuja added a subscriber: yuja.Oct 13 2017, 9:39 AM
yuja added inline comments.
tests/test-dispatch.t
64

Replaced with #if rmcwd

This revision was automatically updated to reflect the committed changes.