D419: hg: move part of top-level logic to dispatch.run
quark (Jun Wu)
phabricator at mercurial-scm.org
Wed Aug 16 17:45:14 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This makes the top-level hg script look cleaner.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D419
AFFECTED FILES
hg
mercurial/dispatch.py
CHANGE DETAILS
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -75,6 +75,8 @@
def run():
"run the command in sys.argv"
+ _enabledemandimport()
+ _setbinary()
req = request(pycompat.sysargv[1:])
err = None
try:
@@ -92,6 +94,16 @@
req.ui.ferr.flush()
sys.exit(status & 255)
+def _enabledemandimport():
+ """enable importing on demand to reduce startup time"""
+ if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
+ import hgdemandimport; hgdemandimport.enable()
+
+def _setbinary():
+ """use binary mode for standard streams"""
+ for fp in (sys.stdin, sys.stdout, sys.stderr):
+ util.setbinary(fp)
+
def _getsimilar(symbols, value):
sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()
# The cutoff for similarity here is pretty arbitrary. It should
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -26,20 +26,12 @@
libdir = os.path.abspath(libdir)
sys.path.insert(0, libdir)
-# enable importing on demand to reduce startup time
try:
- if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
- import hgdemandimport; hgdemandimport.enable()
+ import mercurial.dispatch
except ImportError:
sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
' '.join(sys.path))
sys.stderr.write("(check your install and PYTHONPATH)\n")
sys.exit(-1)
-import mercurial.util
-import mercurial.dispatch
-
-for fp in (sys.stdin, sys.stdout, sys.stderr):
- mercurial.util.setbinary(fp)
-
mercurial.dispatch.run()
To: quark, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list