Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 4550:6ed91894261e
dispatch: hoist debugging hook to runcatch
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 11 Jun 2007 21:09:24 -0500 |
parents | 0c61124ad877 |
children | 61e33f1d44a8 |
comparison
equal
deleted
inserted
replaced
4549:0c61124ad877 | 4550:6ed91894261e |
---|---|
27 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | 27 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
28 num = getattr(signal, name, None) | 28 num = getattr(signal, name, None) |
29 if num: signal.signal(num, catchterm) | 29 if num: signal.signal(num, catchterm) |
30 | 30 |
31 try: | 31 try: |
32 return dispatch(u, args) | 32 try: |
33 # enter the debugger before command execution | |
34 if '--debugger' in args: | |
35 pdb.set_trace() | |
36 try: | |
37 return dispatch(u, args) | |
38 finally: | |
39 u.flush() | |
40 except: | |
41 # enter the debugger when we hit an exception | |
42 if '--debugger' in args: | |
43 pdb.post_mortem(sys.exc_info()[2]) | |
44 u.print_exc() | |
45 raise | |
46 | |
33 except ParseError, inst: | 47 except ParseError, inst: |
34 if inst.args[0]: | 48 if inst.args[0]: |
35 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | 49 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
36 commands.help_(u, inst.args[0]) | 50 commands.help_(u, inst.args[0]) |
37 else: | 51 else: |
279 d = lambda: func(u, *args, **cmdoptions) | 293 d = lambda: func(u, *args, **cmdoptions) |
280 | 294 |
281 return runcommand(u, options, d) | 295 return runcommand(u, options, d) |
282 | 296 |
283 def runcommand(u, options, d): | 297 def runcommand(u, options, d): |
284 # enter the debugger before command execution | 298 if options['profile']: |
285 if options['debugger']: | 299 import hotshot, hotshot.stats |
286 pdb.set_trace() | 300 prof = hotshot.Profile("hg.prof") |
287 | |
288 try: | |
289 try: | 301 try: |
290 if options['profile']: | 302 try: |
291 import hotshot, hotshot.stats | 303 return prof.runcall(d) |
292 prof = hotshot.Profile("hg.prof") | 304 except: |
293 try: | 305 try: |
294 try: | 306 u.warn(_('exception raised - generating ' |
295 return prof.runcall(d) | 307 'profile anyway\n')) |
296 except: | 308 except: |
297 try: | 309 pass |
298 u.warn(_('exception raised - generating ' | 310 raise |
299 'profile anyway\n')) | |
300 except: | |
301 pass | |
302 raise | |
303 finally: | |
304 prof.close() | |
305 stats = hotshot.stats.load("hg.prof") | |
306 stats.strip_dirs() | |
307 stats.sort_stats('time', 'calls') | |
308 stats.print_stats(40) | |
309 elif options['lsprof']: | |
310 try: | |
311 from mercurial import lsprof | |
312 except ImportError: | |
313 raise util.Abort(_( | |
314 'lsprof not available - install from ' | |
315 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) | |
316 p = lsprof.Profiler() | |
317 p.enable(subcalls=True) | |
318 try: | |
319 return d() | |
320 finally: | |
321 p.disable() | |
322 stats = lsprof.Stats(p.getstats()) | |
323 stats.sort() | |
324 stats.pprint(top=10, file=sys.stderr, climit=5) | |
325 else: | |
326 return d() | |
327 finally: | 311 finally: |
328 u.flush() | 312 prof.close() |
329 except: | 313 stats = hotshot.stats.load("hg.prof") |
330 # enter the debugger when we hit an exception | 314 stats.strip_dirs() |
331 if options['debugger']: | 315 stats.sort_stats('time', 'calls') |
332 pdb.post_mortem(sys.exc_info()[2]) | 316 stats.print_stats(40) |
333 u.print_exc() | 317 elif options['lsprof']: |
334 raise | 318 try: |
319 from mercurial import lsprof | |
320 except ImportError: | |
321 raise util.Abort(_( | |
322 'lsprof not available - install from ' | |
323 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) | |
324 p = lsprof.Profiler() | |
325 p.enable(subcalls=True) | |
326 try: | |
327 return d() | |
328 finally: | |
329 p.disable() | |
330 stats = lsprof.Stats(p.getstats()) | |
331 stats.sort() | |
332 stats.pprint(top=10, file=sys.stderr, climit=5) | |
333 else: | |
334 return d() | |
335 | 335 |
336 def bail_if_changed(repo): | 336 def bail_if_changed(repo): |
337 modified, added, removed, deleted = repo.status()[:4] | 337 modified, added, removed, deleted = repo.status()[:4] |
338 if modified or added or removed or deleted: | 338 if modified or added or removed or deleted: |
339 raise util.Abort(_("outstanding uncommitted changes")) | 339 raise util.Abort(_("outstanding uncommitted changes")) |