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 |
if libdir != '@' 'LIBDIR' '@': | if libdir != '@' 'LIBDIR' '@': | ||||
if not os.path.isabs(libdir): | if not os.path.isabs(libdir): | ||||
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), | libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), | ||||
libdir) | libdir) | ||||
libdir = os.path.abspath(libdir) | libdir = os.path.abspath(libdir) | ||||
sys.path.insert(0, libdir) | sys.path.insert(0, libdir) | ||||
# enable importing on demand to reduce startup time | |||||
try: | try: | ||||
if sys.version_info[0] < 3 or sys.version_info >= (3, 6): | import mercurial.dispatch | ||||
import hgdemandimport; hgdemandimport.enable() | |||||
except ImportError: | except ImportError: | ||||
sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % | sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % | ||||
' '.join(sys.path)) | ' '.join(sys.path)) | ||||
sys.stderr.write("(check your install and PYTHONPATH)\n") | sys.stderr.write("(check your install and PYTHONPATH)\n") | ||||
sys.exit(-1) | 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() | mercurial.dispatch.run() |
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): | |||||
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): | 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: |