dispatch: move runcommand to cmdutil
authorMatt Mackall <mpm@selenic.com>
Mon, 11 Jun 2007 21:09:24 -0500
changeset 4548 c9fcebbfc422
parent 4547 8774d2cafe4d
child 4549 0c61124ad877
dispatch: move runcommand to cmdutil
mercurial/cmdutil.py
mercurial/commands.py
--- a/mercurial/cmdutil.py	Mon Jun 11 21:09:24 2007 -0500
+++ b/mercurial/cmdutil.py	Mon Jun 11 21:09:24 2007 -0500
@@ -11,6 +11,59 @@
 
 revrangesep = ':'
 
+def runcommand(u, options, d):
+    # enter the debugger before command execution
+    if options['debugger']:
+        pdb.set_trace()
+
+    try:
+        try:
+            if options['profile']:
+                import hotshot, hotshot.stats
+                prof = hotshot.Profile("hg.prof")
+                try:
+                    try:
+                        return prof.runcall(d)
+                    except:
+                        try:
+                            u.warn(_('exception raised - generating '
+                                     'profile anyway\n'))
+                        except:
+                            pass
+                        raise
+                finally:
+                    prof.close()
+                    stats = hotshot.stats.load("hg.prof")
+                    stats.strip_dirs()
+                    stats.sort_stats('time', 'calls')
+                    stats.print_stats(40)
+            elif options['lsprof']:
+                try:
+                    from mercurial import lsprof
+                except ImportError:
+                    raise util.Abort(_(
+                        'lsprof not available - install from '
+                        'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
+                p = lsprof.Profiler()
+                p.enable(subcalls=True)
+                try:
+                    return d()
+                finally:
+                    p.disable()
+                    stats = lsprof.Stats(p.getstats())
+                    stats.sort()
+                    stats.pprint(top=10, file=sys.stderr, climit=5)
+            else:
+                return d()
+        finally:
+            u.flush()
+    except:
+        # enter the debugger when we hit an exception
+        if options['debugger']:
+            pdb.post_mortem(sys.exc_info()[2])
+        u.print_exc()
+        raise
+
 def parseurl(url, revs):
     '''parse url#branch, returning url, branch + revs'''
 
--- a/mercurial/commands.py	Mon Jun 11 21:09:24 2007 -0500
+++ b/mercurial/commands.py	Mon Jun 11 21:09:24 2007 -0500
@@ -3306,57 +3306,5 @@
     else:
         d = lambda: func(u, *args, **cmdoptions)
 
-    return runcommand(u, options, d)
-
-def runcommand(u, options, d):
-    # enter the debugger before command execution
-    if options['debugger']:
-        pdb.set_trace()
-
-    try:
-        try:
-            if options['profile']:
-                import hotshot, hotshot.stats
-                prof = hotshot.Profile("hg.prof")
-                try:
-                    try:
-                        return prof.runcall(d)
-                    except:
-                        try:
-                            u.warn(_('exception raised - generating '
-                                     'profile anyway\n'))
-                        except:
-                            pass
-                        raise
-                finally:
-                    prof.close()
-                    stats = hotshot.stats.load("hg.prof")
-                    stats.strip_dirs()
-                    stats.sort_stats('time', 'calls')
-                    stats.print_stats(40)
-            elif options['lsprof']:
-                try:
-                    from mercurial import lsprof
-                except ImportError:
-                    raise util.Abort(_(
-                        'lsprof not available - install from '
-                        'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
-                p = lsprof.Profiler()
-                p.enable(subcalls=True)
-                try:
-                    return d()
-                finally:
-                    p.disable()
-                    stats = lsprof.Stats(p.getstats())
-                    stats.sort()
-                    stats.pprint(top=10, file=sys.stderr, climit=5)
-            else:
-                return d()
-        finally:
-            u.flush()
-    except:
-        # enter the debugger when we hit an exception
-        if options['debugger']:
-            pdb.post_mortem(sys.exc_info()[2])
-        u.print_exc()
-        raise
+    return cmdutil.runcommand(u, options, d)
+