Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 1875:2f4a0734c100
Catch other exceptions (e.g. util.Abort) in parse(), too.
This has the benefit of removing duplicate catching of AmbiguousCommand
and UnknownCommand, and keeping all exception handling together.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 10 Mar 2006 11:33:28 +0100 |
parents | 42c76ec7a8d4 |
children | 913397c27cd8 |
comparison
equal
deleted
inserted
replaced
1874:a84829140fb1 | 1875:2f4a0734c100 |
---|---|
2794 u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | 2794 u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
2795 table.update(cmdtable) | 2795 table.update(cmdtable) |
2796 | 2796 |
2797 try: | 2797 try: |
2798 cmd, func, args, options, cmdoptions = parse(u, args) | 2798 cmd, func, args, options, cmdoptions = parse(u, args) |
2799 except ParseError, inst: | 2799 if options["time"]: |
2800 if inst.args[0]: | 2800 def get_times(): |
2801 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | 2801 t = os.times() |
2802 help_(u, inst.args[0]) | 2802 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
2803 else: | 2803 t = (t[0], t[1], t[2], t[3], time.clock()) |
2804 u.warn(_("hg: %s\n") % inst.args[1]) | 2804 return t |
2805 help_(u, 'shortlist') | 2805 s = get_times() |
2806 sys.exit(-1) | 2806 def print_time(): |
2807 except AmbiguousCommand, inst: | 2807 t = get_times() |
2808 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | 2808 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
2809 (inst.args[0], " ".join(inst.args[1]))) | 2809 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
2810 sys.exit(1) | 2810 atexit.register(print_time) |
2811 except UnknownCommand, inst: | 2811 |
2812 u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | 2812 u.updateopts(options["verbose"], options["debug"], options["quiet"], |
2813 help_(u, 'shortlist') | 2813 not options["noninteractive"]) |
2814 sys.exit(1) | 2814 |
2815 | 2815 # enter the debugger before command execution |
2816 if options["time"]: | 2816 if options['debugger']: |
2817 def get_times(): | 2817 pdb.set_trace() |
2818 t = os.times() | 2818 |
2819 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
2820 t = (t[0], t[1], t[2], t[3], time.clock()) | |
2821 return t | |
2822 s = get_times() | |
2823 def print_time(): | |
2824 t = get_times() | |
2825 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
2826 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
2827 atexit.register(print_time) | |
2828 | |
2829 u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
2830 not options["noninteractive"]) | |
2831 | |
2832 # enter the debugger before command execution | |
2833 if options['debugger']: | |
2834 pdb.set_trace() | |
2835 | |
2836 try: | |
2837 try: | 2819 try: |
2838 if options['cwd']: | 2820 if options['cwd']: |
2839 try: | 2821 try: |
2840 os.chdir(options['cwd']) | 2822 os.chdir(options['cwd']) |
2841 except OSError, inst: | 2823 except OSError, inst: |
2899 if options['debugger']: | 2881 if options['debugger']: |
2900 pdb.post_mortem(sys.exc_info()[2]) | 2882 pdb.post_mortem(sys.exc_info()[2]) |
2901 if options['traceback']: | 2883 if options['traceback']: |
2902 traceback.print_exc() | 2884 traceback.print_exc() |
2903 raise | 2885 raise |
2886 except ParseError, inst: | |
2887 if inst.args[0]: | |
2888 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
2889 help_(u, inst.args[0]) | |
2890 else: | |
2891 u.warn(_("hg: %s\n") % inst.args[1]) | |
2892 help_(u, 'shortlist') | |
2893 sys.exit(-1) | |
2894 except AmbiguousCommand, inst: | |
2895 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
2896 (inst.args[0], " ".join(inst.args[1]))) | |
2897 sys.exit(1) | |
2898 except UnknownCommand, inst: | |
2899 u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
2900 help_(u, 'shortlist') | |
2901 sys.exit(1) | |
2904 except hg.RepoError, inst: | 2902 except hg.RepoError, inst: |
2905 u.warn(_("abort: "), inst, "!\n") | 2903 u.warn(_("abort: "), inst, "!\n") |
2906 except revlog.RevlogError, inst: | 2904 except revlog.RevlogError, inst: |
2907 u.warn(_("abort: "), inst, "!\n") | 2905 u.warn(_("abort: "), inst, "!\n") |
2908 except SignalInterrupt: | 2906 except SignalInterrupt: |
2945 if len(tb) > 2: # no | 2943 if len(tb) > 2: # no |
2946 raise | 2944 raise |
2947 u.debug(inst, "\n") | 2945 u.debug(inst, "\n") |
2948 u.warn(_("%s: invalid arguments\n") % cmd) | 2946 u.warn(_("%s: invalid arguments\n") % cmd) |
2949 help_(u, cmd) | 2947 help_(u, cmd) |
2950 except AmbiguousCommand, inst: | |
2951 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
2952 (inst.args[0], " ".join(inst.args[1]))) | |
2953 help_(u, 'shortlist') | |
2954 except UnknownCommand, inst: | |
2955 u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
2956 help_(u, 'shortlist') | |
2957 except SystemExit: | 2948 except SystemExit: |
2958 # don't catch this in the catch-all below | 2949 # don't catch this in the catch-all below |
2959 raise | 2950 raise |
2960 except: | 2951 except: |
2961 u.warn(_("** unknown exception encountered, details follow\n")) | 2952 u.warn(_("** unknown exception encountered, details follow\n")) |