diff -r 5d44197c208b -r e3501546f7e4 mercurial/dispatch.py --- a/mercurial/dispatch.py Sun Aug 14 18:25:22 2016 -0700 +++ b/mercurial/dispatch.py Sun Aug 14 17:51:12 2016 -0700 @@ -898,21 +898,12 @@ repo.close() def _runcommand(ui, options, cmd, cmdfunc): - """Enables the profiler if applicable. - - ``profiling.enabled`` - boolean config that enables or disables profiling - """ - def checkargs(): + """Run a command function, possibly with profiling enabled.""" + with profiling.maybeprofile(ui): try: return cmdfunc() except error.SignatureError: - raise error.CommandError(cmd, _("invalid arguments")) - - if ui.configbool('profiling', 'enabled'): - with profiling.profile(ui): - return checkargs() - else: - return checkargs() + raise error.CommandError(cmd, _('invalid arguments')) def _exceptionwarning(ui): """Produce a warning message for the current active exception"""