This makes the top-level hg script look cleaner.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Lint Skipped |
Unit Tests Skipped |
hg | ||
---|---|---|
30 | I thought demandimport was per module, non-recursive. It's obviously recursive. Will change. |
self.ui.warn(('error in exit handlers:\n')) | self.ui.warn(('error in exit handlers:\n')) | ||||
self.ui.traceback(force=True) | self.ui.traceback(force=True) | ||||
finally: | finally: | ||||
if exc is not None: | if exc is not None: | ||||
raise exc | raise exc | ||||
def run(): | def run(): | ||||
"run the command in sys.argv" | "run the command in sys.argv" | ||||
_enabledemandimport() | |||||
_setbinary() | |||||
req = request(pycompat.sysargv[1:]) | req = request(pycompat.sysargv[1:]) | ||||
err = None | err = None | ||||
try: | try: | ||||
status = (dispatch(req) or 0) & 255 | status = (dispatch(req) or 0) & 255 | ||||
except error.StdioError as err: | except error.StdioError as err: | ||||
status = -1 | status = -1 | ||||
if util.safehasattr(req.ui, 'fout'): | if util.safehasattr(req.ui, 'fout'): | ||||
try: | try: | ||||
req.ui.fout.flush() | req.ui.fout.flush() | ||||
except IOError as err: | except IOError as err: | ||||
status = -1 | status = -1 | ||||
if util.safehasattr(req.ui, 'ferr'): | if util.safehasattr(req.ui, 'ferr'): | ||||
if err is not None and err.errno != errno.EPIPE: | if err is not None and err.errno != errno.EPIPE: | ||||
req.ui.ferr.write('abort: %s\n' % err.strerror) | req.ui.ferr.write('abort: %s\n' % err.strerror) | ||||
req.ui.ferr.flush() | req.ui.ferr.flush() | ||||
sys.exit(status & 255) | 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): | |||||
demandimport.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): | def _getsimilar(symbols, value): | ||||
sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | ||||
# The cutoff for similarity here is pretty arbitrary. It should | # The cutoff for similarity here is pretty arbitrary. It should | ||||
# probably be investigated and tweaked. | # probably be investigated and tweaked. | ||||
return [s for s in symbols if sim(s) > 0.6] | return [s for s in symbols if sim(s) > 0.6] | ||||
def _reportsimilar(write, similar): | def _reportsimilar(write, similar): | ||||
if len(similar) == 1: | if len(similar) == 1: |
This makes the import of dispatch non-lazy, right?