comparison mercurial/commands.py @ 4548:c9fcebbfc422

dispatch: move runcommand to cmdutil
author Matt Mackall <mpm@selenic.com>
date Mon, 11 Jun 2007 21:09:24 -0500
parents 8774d2cafe4d
children 0c61124ad877
comparison
equal deleted inserted replaced
4547:8774d2cafe4d 4548:c9fcebbfc422
3304 raise 3304 raise
3305 d = lambda: func(u, repo, *args, **cmdoptions) 3305 d = lambda: func(u, repo, *args, **cmdoptions)
3306 else: 3306 else:
3307 d = lambda: func(u, *args, **cmdoptions) 3307 d = lambda: func(u, *args, **cmdoptions)
3308 3308
3309 return runcommand(u, options, d) 3309 return cmdutil.runcommand(u, options, d)
3310 3310
3311 def runcommand(u, options, d):
3312 # enter the debugger before command execution
3313 if options['debugger']:
3314 pdb.set_trace()
3315
3316 try:
3317 try:
3318 if options['profile']:
3319 import hotshot, hotshot.stats
3320 prof = hotshot.Profile("hg.prof")
3321 try:
3322 try:
3323 return prof.runcall(d)
3324 except:
3325 try:
3326 u.warn(_('exception raised - generating '
3327 'profile anyway\n'))
3328 except:
3329 pass
3330 raise
3331 finally:
3332 prof.close()
3333 stats = hotshot.stats.load("hg.prof")
3334 stats.strip_dirs()
3335 stats.sort_stats('time', 'calls')
3336 stats.print_stats(40)
3337 elif options['lsprof']:
3338 try:
3339 from mercurial import lsprof
3340 except ImportError:
3341 raise util.Abort(_(
3342 'lsprof not available - install from '
3343 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
3344 p = lsprof.Profiler()
3345 p.enable(subcalls=True)
3346 try:
3347 return d()
3348 finally:
3349 p.disable()
3350 stats = lsprof.Stats(p.getstats())
3351 stats.sort()
3352 stats.pprint(top=10, file=sys.stderr, climit=5)
3353 else:
3354 return d()
3355 finally:
3356 u.flush()
3357 except:
3358 # enter the debugger when we hit an exception
3359 if options['debugger']:
3360 pdb.post_mortem(sys.exc_info()[2])
3361 u.print_exc()
3362 raise