Mercurial > hg
comparison mercurial/dispatch.py @ 26587:56b2bcea2529
error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.
For great justice.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 08 Oct 2015 12:55:45 -0700 |
parents | 4b0fc75f9403 |
children | 77850d2a161c |
comparison
equal
deleted
inserted
replaced
26586:d51c658d3f04 | 26587:56b2bcea2529 |
---|---|
98 req.ui.fin = req.fin | 98 req.ui.fin = req.fin |
99 if req.fout: | 99 if req.fout: |
100 req.ui.fout = req.fout | 100 req.ui.fout = req.fout |
101 if req.ferr: | 101 if req.ferr: |
102 req.ui.ferr = req.ferr | 102 req.ui.ferr = req.ferr |
103 except util.Abort as inst: | 103 except error.Abort as inst: |
104 ferr.write(_("abort: %s\n") % inst) | 104 ferr.write(_("abort: %s\n") % inst) |
105 if inst.hint: | 105 if inst.hint: |
106 ferr.write(_("(%s)\n") % inst.hint) | 106 ferr.write(_("(%s)\n") % inst.hint) |
107 return -1 | 107 return -1 |
108 except error.ParseError as inst: | 108 except error.ParseError as inst: |
251 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | 251 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
252 try: | 252 try: |
253 # check if the command is in a disabled extension | 253 # check if the command is in a disabled extension |
254 # (but don't check for extensions themselves) | 254 # (but don't check for extensions themselves) |
255 commands.help_(ui, inst.args[0], unknowncmd=True) | 255 commands.help_(ui, inst.args[0], unknowncmd=True) |
256 except (error.UnknownCommand, util.Abort): | 256 except (error.UnknownCommand, error.Abort): |
257 suggested = False | 257 suggested = False |
258 if len(inst.args) == 2: | 258 if len(inst.args) == 2: |
259 sim = _getsimilar(inst.args[1], inst.args[0]) | 259 sim = _getsimilar(inst.args[1], inst.args[0]) |
260 if sim: | 260 if sim: |
261 ui.warn(_('(did you mean one of %s?)\n') % | 261 ui.warn(_('(did you mean one of %s?)\n') % |
264 if not suggested: | 264 if not suggested: |
265 commands.help_(ui, 'shortlist') | 265 commands.help_(ui, 'shortlist') |
266 except error.InterventionRequired as inst: | 266 except error.InterventionRequired as inst: |
267 ui.warn("%s\n" % inst) | 267 ui.warn("%s\n" % inst) |
268 return 1 | 268 return 1 |
269 except util.Abort as inst: | 269 except error.Abort as inst: |
270 ui.warn(_("abort: %s\n") % inst) | 270 ui.warn(_("abort: %s\n") % inst) |
271 if inst.hint: | 271 if inst.hint: |
272 ui.warn(_("(%s)\n") % inst.hint) | 272 ui.warn(_("(%s)\n") % inst.hint) |
273 except ImportError as inst: | 273 except ImportError as inst: |
274 ui.warn(_("abort: %s!\n") % inst) | 274 ui.warn(_("abort: %s!\n") % inst) |
396 def replacer(m): | 396 def replacer(m): |
397 num = int(m.group(1)) - 1 | 397 num = int(m.group(1)) - 1 |
398 nums.append(num) | 398 nums.append(num) |
399 if num < len(givenargs): | 399 if num < len(givenargs): |
400 return givenargs[num] | 400 return givenargs[num] |
401 raise util.Abort(_('too few arguments for command alias')) | 401 raise error.Abort(_('too few arguments for command alias')) |
402 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd) | 402 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd) |
403 givenargs = [x for i, x in enumerate(givenargs) | 403 givenargs = [x for i, x in enumerate(givenargs) |
404 if i not in nums] | 404 if i not in nums] |
405 args = shlex.split(cmd) | 405 args = shlex.split(cmd) |
406 return args + givenargs | 406 return args + givenargs |
523 # check if the command is in a disabled extension | 523 # check if the command is in a disabled extension |
524 cmd, ext = extensions.disabledcmd(ui, self.cmdname)[:2] | 524 cmd, ext = extensions.disabledcmd(ui, self.cmdname)[:2] |
525 hint = _("'%s' is provided by '%s' extension") % (cmd, ext) | 525 hint = _("'%s' is provided by '%s' extension") % (cmd, ext) |
526 except error.UnknownCommand: | 526 except error.UnknownCommand: |
527 pass | 527 pass |
528 raise util.Abort(self.badalias, hint=hint) | 528 raise error.Abort(self.badalias, hint=hint) |
529 if self.shadows: | 529 if self.shadows: |
530 ui.debug("alias '%s' shadows command '%s'\n" % | 530 ui.debug("alias '%s' shadows command '%s'\n" % |
531 (self.name, self.cmdname)) | 531 (self.name, self.cmdname)) |
532 | 532 |
533 if util.safehasattr(self, 'shell'): | 533 if util.safehasattr(self, 'shell'): |
612 if not section or not name: | 612 if not section or not name: |
613 raise IndexError | 613 raise IndexError |
614 ui.setconfig(section, name, value, '--config') | 614 ui.setconfig(section, name, value, '--config') |
615 configs.append((section, name, value)) | 615 configs.append((section, name, value)) |
616 except (IndexError, ValueError): | 616 except (IndexError, ValueError): |
617 raise util.Abort(_('malformed --config option: %r ' | 617 raise error.Abort(_('malformed --config option: %r ' |
618 '(use --config section.name=value)') % cfg) | 618 '(use --config section.name=value)') % cfg) |
619 | 619 |
620 return configs | 620 return configs |
621 | 621 |
622 def _earlygetopt(aliases, args): | 622 def _earlygetopt(aliases, args): |
688 Takes paths in [cwd]/.hg/hgrc into account." | 688 Takes paths in [cwd]/.hg/hgrc into account." |
689 """ | 689 """ |
690 try: | 690 try: |
691 wd = os.getcwd() | 691 wd = os.getcwd() |
692 except OSError as e: | 692 except OSError as e: |
693 raise util.Abort(_("error getting current working directory: %s") % | 693 raise error.Abort(_("error getting current working directory: %s") % |
694 e.strerror) | 694 e.strerror) |
695 path = cmdutil.findrepo(wd) or "" | 695 path = cmdutil.findrepo(wd) or "" |
696 if not path: | 696 if not path: |
697 lui = ui | 697 lui = ui |
698 else: | 698 else: |
811 | 811 |
812 fullargs = args | 812 fullargs = args |
813 cmd, func, args, options, cmdoptions = _parse(lui, args) | 813 cmd, func, args, options, cmdoptions = _parse(lui, args) |
814 | 814 |
815 if options["config"]: | 815 if options["config"]: |
816 raise util.Abort(_("option --config may not be abbreviated!")) | 816 raise error.Abort(_("option --config may not be abbreviated!")) |
817 if options["cwd"]: | 817 if options["cwd"]: |
818 raise util.Abort(_("option --cwd may not be abbreviated!")) | 818 raise error.Abort(_("option --cwd may not be abbreviated!")) |
819 if options["repository"]: | 819 if options["repository"]: |
820 raise util.Abort(_( | 820 raise error.Abort(_( |
821 "option -R has to be separated from other options (e.g. not -qR) " | 821 "option -R has to be separated from other options (e.g. not -qR) " |
822 "and --repository may only be abbreviated as --repo!")) | 822 "and --repository may only be abbreviated as --repo!")) |
823 | 823 |
824 if options["encoding"]: | 824 if options["encoding"]: |
825 encoding.encoding = options["encoding"] | 825 encoding.encoding = options["encoding"] |
882 repo.ui.ferr = ui.ferr | 882 repo.ui.ferr = ui.ferr |
883 else: | 883 else: |
884 try: | 884 try: |
885 repo = hg.repository(ui, path=path) | 885 repo = hg.repository(ui, path=path) |
886 if not repo.local(): | 886 if not repo.local(): |
887 raise util.Abort(_("repository '%s' is not local") % path) | 887 raise error.Abort(_("repository '%s' is not local") % path) |
888 repo.ui.setconfig("bundle", "mainreporoot", repo.root, 'repo') | 888 repo.ui.setconfig("bundle", "mainreporoot", repo.root, 'repo') |
889 except error.RequirementError: | 889 except error.RequirementError: |
890 raise | 890 raise |
891 except error.RepoError: | 891 except error.RepoError: |
892 if rpath and rpath[-1]: # invalid -R path | 892 if rpath and rpath[-1]: # invalid -R path |
934 format = 'text' | 934 format = 'text' |
935 | 935 |
936 try: | 936 try: |
937 from . import lsprof | 937 from . import lsprof |
938 except ImportError: | 938 except ImportError: |
939 raise util.Abort(_( | 939 raise error.Abort(_( |
940 'lsprof not available - install from ' | 940 'lsprof not available - install from ' |
941 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) | 941 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
942 p = lsprof.Profiler() | 942 p = lsprof.Profiler() |
943 p.enable(subcalls=True) | 943 p.enable(subcalls=True) |
944 try: | 944 try: |
958 | 958 |
959 def flameprofile(ui, func, fp): | 959 def flameprofile(ui, func, fp): |
960 try: | 960 try: |
961 from flamegraph import flamegraph | 961 from flamegraph import flamegraph |
962 except ImportError: | 962 except ImportError: |
963 raise util.Abort(_( | 963 raise error.Abort(_( |
964 'flamegraph not available - install from ' | 964 'flamegraph not available - install from ' |
965 'https://github.com/evanhempel/python-flamegraph')) | 965 'https://github.com/evanhempel/python-flamegraph')) |
966 # developer config: profiling.freq | 966 # developer config: profiling.freq |
967 freq = ui.configint('profiling', 'freq', default=1000) | 967 freq = ui.configint('profiling', 'freq', default=1000) |
968 filter_ = None | 968 filter_ = None |
983 | 983 |
984 def statprofile(ui, func, fp): | 984 def statprofile(ui, func, fp): |
985 try: | 985 try: |
986 import statprof | 986 import statprof |
987 except ImportError: | 987 except ImportError: |
988 raise util.Abort(_( | 988 raise error.Abort(_( |
989 'statprof not available - install using "easy_install statprof"')) | 989 'statprof not available - install using "easy_install statprof"')) |
990 | 990 |
991 freq = ui.configint('profiling', 'freq', default=1000) | 991 freq = ui.configint('profiling', 'freq', default=1000) |
992 if freq > 0: | 992 if freq > 0: |
993 statprof.reset(freq) | 993 statprof.reset(freq) |