mercurial/commands.py
changeset 527 58790c83ce52
parent 526 55af04e26bad
child 528 648386fabf9c
child 541 abaea35387a8
equal deleted inserted replaced
526:55af04e26bad 527:58790c83ce52
   816     opts = [('v', 'verbose', None, 'verbose'),
   816     opts = [('v', 'verbose', None, 'verbose'),
   817             ('d', 'debug', None, 'debug'),
   817             ('d', 'debug', None, 'debug'),
   818             ('q', 'quiet', None, 'quiet'),
   818             ('q', 'quiet', None, 'quiet'),
   819             ('p', 'profile', None, 'profile'),
   819             ('p', 'profile', None, 'profile'),
   820             ('R', 'repository', "", 'repository root directory'),
   820             ('R', 'repository', "", 'repository root directory'),
       
   821             ('', 'traceback', None, 'print traceback on exception'),
   821             ('y', 'noninteractive', None, 'run non-interactively'),
   822             ('y', 'noninteractive', None, 'run non-interactively'),
   822             ('', 'version', None, 'output version information and exit'),
   823             ('', 'version', None, 'output version information and exit'),
   823             ]
   824             ]
   824 
   825 
   825     args = fancyopts.fancyopts(args, opts, options,
   826     args = fancyopts.fancyopts(args, opts, options,
   853         u.warn("hg %s: %s\n" % (cmd, inst))
   854         u.warn("hg %s: %s\n" % (cmd, inst))
   854         help(u, cmd)
   855         help(u, cmd)
   855         sys.exit(-1)
   856         sys.exit(-1)
   856 
   857 
   857     try:
   858     try:
   858         if cmd not in norepo.split():
   859         try:
   859             path = options["repository"] or ""
   860             if cmd not in norepo.split():
   860             repo = hg.repository(ui=u, path=path)
   861                 path = options["repository"] or ""
   861             d = lambda: i[0](u, repo, *args, **cmdoptions)
   862                 repo = hg.repository(ui=u, path=path)
   862         else:
   863                 d = lambda: i[0](u, repo, *args, **cmdoptions)
   863             d = lambda: i[0](u, *args, **cmdoptions)
   864             else:
   864 
   865                 d = lambda: i[0](u, *args, **cmdoptions)
   865         if options['profile']:
   866 
   866             import hotshot, hotshot.stats
   867             if options['profile']:
   867             prof = hotshot.Profile("hg.prof")
   868                 import hotshot, hotshot.stats
   868             r = prof.runcall(d)
   869                 prof = hotshot.Profile("hg.prof")
   869             prof.close()
   870                 r = prof.runcall(d)
   870             stats = hotshot.stats.load("hg.prof")
   871                 prof.close()
   871             stats.strip_dirs()
   872                 stats = hotshot.stats.load("hg.prof")
   872             stats.sort_stats('time', 'calls')
   873                 stats.strip_dirs()
   873             stats.print_stats(40)
   874                 stats.sort_stats('time', 'calls')
   874             return r
   875                 stats.print_stats(40)
   875         else:
   876                 return r
   876             return d()
   877             else:
       
   878                 return d()
       
   879         except:
       
   880             if options['traceback']:
       
   881                 traceback.print_exc()
       
   882             raise
   877     except util.CommandError, inst:
   883     except util.CommandError, inst:
   878         u.warn("abort: %s\n" % inst.args)
   884         u.warn("abort: %s\n" % inst.args)
   879     except hg.RepoError, inst:
   885     except hg.RepoError, inst:
   880         u.warn("abort: ", inst, "!\n")
   886         u.warn("abort: ", inst, "!\n")
   881     except SignalInterrupt:
   887     except SignalInterrupt: