Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dispatch.py @ 29795:e3501546f7e4
profiling: add a context manager that no-ops if profiling isn't enabled
And refactor dispatch.py to use it. As you can see, the resulting code
is much simpler.
I was tempted to inline _runcommand as part of writing this series.
However, a number of extensions wrap _runcommand. So keeping it around
is necessary (extensions can't easily wrap runcommand because it calls
hooks before and after command execution).
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 14 Aug 2016 17:51:12 -0700 |
parents | 5d44197c208b |
children | 61a4cdc98307 |
line wrap: on
line diff
--- 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"""