error: move ParseError
authorMatt Mackall <mpm@selenic.com>
Sun, 11 Jan 2009 23:04:24 -0600
changeset 7636 e3f8c6d6b72e635a08a4d87362e7a630c8d4cfcf
parent 7635 d22c437247452f84125d33ddd3e036d12a583667
child 7637 1d54e2f6c0b7d1581c3b216784465e044764a237
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
error: move ParseError
hgext/rebase.py
mercurial/dispatch.py
mercurial/error.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -8,17 +8,17 @@
 '''move sets of revisions to a different ancestor
 
 This extension lets you rebase changesets in an existing Mercurial repository.
 
 For more information:
 http://www.selenic.com/mercurial/wiki/index.cgi/RebaseProject
 '''
 
-from mercurial import util, repair, merge, cmdutil, dispatch, commands
+from mercurial import util, repair, merge, cmdutil, commands, error
 from mercurial import extensions, ancestor
 from mercurial.commands import templateopts
 from mercurial.node import nullrev
 from mercurial.i18n import _
 import os, errno
 
 def rebasemerge(repo, rev, first=False):
     'return the correct ancestor'
@@ -62,41 +62,41 @@ def rebase(ui, repo, **opts):
         srcf = opts.get('source', None)
         basef = opts.get('base', None)
         contf = opts.get('continue')
         abortf = opts.get('abort')
         collapsef = opts.get('collapse', False)
         extrafn = opts.get('extrafn')
         if opts.get('keepbranches', None):
             if extrafn:
-                raise dispatch.ParseError('rebase',
-                        _('cannot use both keepbranches and extrafn'))
+                raise error.ParseError(
+                    'rebase', _('cannot use both keepbranches and extrafn'))
             def extrafn(ctx, extra):
                 extra['branch'] = ctx.branch()
 
         if contf or abortf:
             if contf and abortf:
-                raise dispatch.ParseError('rebase',
-                                    _('cannot use both abort and continue'))
+                raise error.ParseError('rebase',
+                                       _('cannot use both abort and continue'))
             if collapsef:
-                raise dispatch.ParseError('rebase',
-                        _('cannot use collapse with continue or abort'))
+                raise error.ParseError(
+                    'rebase', _('cannot use collapse with continue or abort'))
 
             if (srcf or basef or destf):
-                raise dispatch.ParseError('rebase',
+                raise error.ParseError('rebase',
                     _('abort and continue do not allow specifying revisions'))
 
             originalwd, target, state, collapsef, external = restorestatus(repo)
             if abortf:
                 abort(repo, originalwd, target, state)
                 return
         else:
             if srcf and basef:
-                raise dispatch.ParseError('rebase', _('cannot specify both a '
-                                                        'revision and a base'))
+                raise error.ParseError('rebase', _('cannot specify both a '
+                                                   'revision and a base'))
             cmdutil.bail_if_changed(repo)
             result = buildstate(repo, destf, srcf, basef, collapsef)
             if result:
                 originalwd, target, state, external = result
             else: # Empty state built, nothing to rebase
                 repo.ui.status(_('nothing to rebase\n'))
                 return
 
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -7,19 +7,16 @@
 
 from i18n import _
 from repo import RepoError
 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
 import util, commands, hg, lock, fancyopts, extensions, hook, error
 import cmdutil
 import ui as _ui
 
-class ParseError(Exception):
-    """Exception raised on errors in parsing the command line."""
-
 def run():
     "run the command in sys.argv"
     sys.exit(dispatch(sys.argv[1:]))
 
 def dispatch(args):
     "run the command specified in args"
     try:
         u = _ui.ui(traceback='--traceback' in args)
@@ -47,17 +44,17 @@ def _runcatch(ui, args):
                 ui.flush()
         except:
             # enter the debugger when we hit an exception
             if '--debugger' in args:
                 pdb.post_mortem(sys.exc_info()[2])
             ui.print_exc()
             raise
 
-    except ParseError, inst:
+    except error.ParseError, inst:
         if inst.args[0]:
             ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
             commands.help_(ui, inst.args[0])
         else:
             ui.warn(_("hg: %s\n") % inst.args[1])
             commands.help_(ui, 'shortlist')
     except cmdutil.AmbiguousCommand, inst:
         ui.warn(_("hg: command '%s' is ambiguous:\n    %s\n") %
@@ -162,17 +159,17 @@ def _findrepo(p):
 
 def _parse(ui, args):
     options = {}
     cmdoptions = {}
 
     try:
         args = fancyopts.fancyopts(args, commands.globalopts, options)
     except fancyopts.getopt.GetoptError, inst:
-        raise ParseError(None, inst)
+        raise error.ParseError(None, inst)
 
     if args:
         cmd, args = args[0], args[1:]
         aliases, i = cmdutil.findcmd(cmd, commands.table,
                                      ui.config("ui", "strict"))
         cmd = aliases[0]
         defaults = ui.config("defaults", cmd)
         if defaults:
@@ -184,17 +181,17 @@ def _parse(ui, args):
 
     # combine global options into local
     for o in commands.globalopts:
         c.append((o[0], o[1], options[o[1]], o[3]))
 
     try:
         args = fancyopts.fancyopts(args, c, cmdoptions)
     except fancyopts.getopt.GetoptError, inst:
-        raise ParseError(cmd, inst)
+        raise error.ParseError(cmd, inst)
 
     # separate global options back out
     for o in commands.globalopts:
         n = o[1]
         options[n] = cmdoptions[n]
         del cmdoptions[n]
 
     return (cmd, cmd and i[0] or None, args, options, cmdoptions)
@@ -370,17 +367,17 @@ def _dispatch(ui, args):
               result = ret)
     return ret
 
 def _runcommand(ui, options, cmd, cmdfunc):
     def checkargs():
         try:
             return cmdfunc()
         except util.SignatureError:
-            raise ParseError(cmd, _("invalid arguments"))
+            raise error.ParseError(cmd, _("invalid arguments"))
 
     if options['profile']:
         import hotshot, hotshot.stats
         prof = hotshot.Profile("hg.prof")
         try:
             try:
                 return prof.runcall(checkargs)
             except:
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -19,8 +19,11 @@ class LookupError(RevlogError, KeyError)
         self.name = name
         if isinstance(name, str) and len(name) == 20:
             from node import short
             name = short(name)
         RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
 
     def __str__(self):
         return RevlogError.__str__(self)
+
+class ParseError(Exception):
+    """Exception raised on errors in parsing the command line."""