Changeset View
Changeset View
Standalone View
Standalone View
mercurial/dispatch.py
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Line(s) | def dispatch(req): | ||||
"""run the command specified in req.args; returns an integer status code""" | """run the command specified in req.args; returns an integer status code""" | ||||
err = None | err = None | ||||
try: | try: | ||||
status = _rundispatch(req) | status = _rundispatch(req) | ||||
except error.StdioError as e: | except error.StdioError as e: | ||||
err = e | err = e | ||||
status = -1 | status = -1 | ||||
# Somehow we have to catcht he exception here; catching it inside | |||||
# _flushstdio() doesn't work. | |||||
try: | |||||
ret = _flushstdio(req.ui, err) | ret = _flushstdio(req.ui, err) | ||||
if ret and not status: | if ret and not status: | ||||
status = ret | status = ret | ||||
except BaseException: | |||||
pass | |||||
return status | return status | ||||
def _rundispatch(req): | def _rundispatch(req): | ||||
with tracing.log('dispatch._rundispatch'): | with tracing.log('dispatch._rundispatch'): | ||||
if req.ferr: | if req.ferr: | ||||
ferr = req.ferr | ferr = req.ferr | ||||
elif req.ui: | elif req.ui: | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | with tracing.log('dispatch._rundispatch'): | ||||
# SIGPIPE was raised. we cannot print anything in this case. | # SIGPIPE was raised. we cannot print anything in this case. | ||||
pass | pass | ||||
except IOError as inst: | except IOError as inst: | ||||
if inst.errno != errno.EPIPE: | if inst.errno != errno.EPIPE: | ||||
raise | raise | ||||
ret = -1 | ret = -1 | ||||
finally: | finally: | ||||
duration = util.timer() - starttime | duration = util.timer() - starttime | ||||
try: | |||||
req.ui.flush() # record blocked times | req.ui.flush() # record blocked times | ||||
except BaseException: | |||||
pass | |||||
if req.ui.logblockedtimes: | if req.ui.logblockedtimes: | ||||
req.ui._blockedtimes[b'command_duration'] = duration * 1000 | req.ui._blockedtimes[b'command_duration'] = duration * 1000 | ||||
req.ui.log( | req.ui.log( | ||||
b'uiblocked', | b'uiblocked', | ||||
b'ui blocked ms\n', | b'ui blocked ms\n', | ||||
**pycompat.strkwargs(req.ui._blockedtimes) | **pycompat.strkwargs(req.ui._blockedtimes) | ||||
) | ) | ||||
return_code = ret & 255 | return_code = ret & 255 | ||||
req.ui.log( | req.ui.log( | ||||
b"commandfinish", | b"commandfinish", | ||||
b"%s exited %d after %0.2f seconds\n", | b"%s exited %d after %0.2f seconds\n", | ||||
msg, | msg, | ||||
return_code, | return_code, | ||||
duration, | duration, | ||||
return_code=return_code, | return_code=return_code, | ||||
duration=duration, | duration=duration, | ||||
canonical_command=req.canonical_command, | canonical_command=req.canonical_command, | ||||
) | ) | ||||
try: | try: | ||||
req._runexithandlers() | req._runexithandlers() | ||||
except: # exiting, so no re-raises | except: # exiting, so no re-raises | ||||
ret = ret or -1 | ret = ret or -1 | ||||
# do flush again since ui.log() and exit handlers may write to ui | # do flush again since ui.log() and exit handlers may write to ui | ||||
try: | |||||
req.ui.flush() | req.ui.flush() | ||||
except BaseException: | |||||
pass | |||||
return ret | return ret | ||||
def _runcatch(req): | def _runcatch(req): | ||||
with tracing.log('dispatch._runcatch'): | with tracing.log('dispatch._runcatch'): | ||||
def catchterm(*args): | def catchterm(*args): | ||||
raise error.SignalInterrupt | raise error.SignalInterrupt | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | with tracing.log('dispatch._runcatch'): | ||||
) | ) | ||||
% debugger | % debugger | ||||
) | ) | ||||
with demandimport.deactivated(): | with demandimport.deactivated(): | ||||
debugtrace[debugger]() | debugtrace[debugger]() | ||||
try: | try: | ||||
return _dispatch(req) | return _dispatch(req) | ||||
finally: | finally: | ||||
ui.flush() | try: | ||||
ui.flush() # record blocked times | |||||
except BaseException: | |||||
pass | |||||
except: # re-raises | except: # re-raises | ||||
# enter the debugger when we hit an exception | # enter the debugger when we hit an exception | ||||
if req.earlyoptions[b'debugger']: | if req.earlyoptions[b'debugger']: | ||||
traceback.print_exc() | traceback.print_exc() | ||||
debugmortem[debugger](sys.exc_info()[2]) | debugmortem[debugger](sys.exc_info()[2]) | ||||
raise | raise | ||||
return _callcatch(ui, _runcatchfunc) | return _callcatch(ui, _runcatchfunc) | ||||
▲ Show 20 Lines • Show All 920 Lines • Show Last 20 Lines |