changeset 7213:b4c035057d34

findcmd: have dispatch look up strict flag
author Matt Mackall <mpm@selenic.com>
date Wed, 22 Oct 2008 17:34:08 -0500
parents 402d317778d3
children 0e8a9530d323
files hgext/alias.py hgext/color.py hgext/mq.py hgext/rebase.py mercurial/cmdutil.py mercurial/commands.py mercurial/dispatch.py
diffstat 7 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/alias.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/hgext/alias.py	Wed Oct 22 17:34:08 2008 -0500
@@ -43,7 +43,7 @@
             return
 
         try:
-            self._cmd = findcmd(self._ui, self._target, commands.table)[1]
+            self._cmd = findcmd(self._target, commands.table, False)[1]
             if self._cmd == self:
                 raise RecursiveCommand()
             if self._target in commands.norepo.split(' '):
--- a/hgext/color.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/hgext/color.py	Wed Oct 22 17:34:08 2008 -0500
@@ -198,7 +198,7 @@
 
 def _cmdtableitem(ui, cmd, table):
     '''Return key, value from table for cmd, or None if not found.'''
-    aliases, entry = cmdutil.findcmd(ui, cmd, table)
+    aliases, entry = cmdutil.findcmd(cmd, table)
     for candidatekey, candidateentry in table.iteritems():
         if candidateentry is entry:
             return candidatekey, entry
--- a/hgext/mq.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/hgext/mq.py	Wed Oct 22 17:34:08 2008 -0500
@@ -2368,7 +2368,7 @@
 
 def uisetup(ui):
     # override import to disallow importing over patch
-    importalias, importcmd = cmdutil.findcmd(ui, 'import', commands.table)
+    importalias, importcmd = cmdutil.findcmd('import', commands.table)
     for alias, cmd in commands.table.iteritems():
         if cmd is importcmd:
             importkey = alias
--- a/hgext/rebase.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/hgext/rebase.py	Wed Oct 22 17:34:08 2008 -0500
@@ -370,7 +370,7 @@
 def uisetup(ui):
     'Replace pull with a decorator to provide --rebase option'
     # cribbed from color.py
-    aliases, entry = cmdutil.findcmd(ui, 'pull', commands.table)
+    aliases, entry = cmdutil.findcmd('pull', commands.table)
     for candidatekey, candidateentry in commands.table.iteritems():
         if candidateentry is entry:
             cmdkey, cmdentry = candidatekey, entry
--- a/mercurial/cmdutil.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/mercurial/cmdutil.py	Wed Oct 22 17:34:08 2008 -0500
@@ -18,7 +18,7 @@
 class AmbiguousCommand(Exception):
     """Exception raised if command shortcut matches more than one command."""
 
-def findpossible(ui, cmd, table):
+def findpossible(cmd, table, strict=False):
     """
     Return cmd -> (aliases, command table entry)
     for each matching command.
@@ -31,7 +31,7 @@
         found = None
         if cmd in aliases:
             found = cmd
-        elif not ui.config("ui", "strict"):
+        elif not strict:
             for a in aliases:
                 if a.startswith(cmd):
                     found = a
@@ -47,9 +47,9 @@
 
     return choice
 
-def findcmd(ui, cmd, table):
+def findcmd(cmd, table, strict=True):
     """Return (aliases, command table entry) for command string."""
-    choice = findpossible(ui, cmd, table)
+    choice = findpossible(cmd, table, strict)
 
     if cmd in choice:
         return choice[cmd]
--- a/mercurial/commands.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/mercurial/commands.py	Wed Oct 22 17:34:08 2008 -0500
@@ -655,7 +655,7 @@
         options = []
         otables = [globalopts]
         if cmd:
-            aliases, entry = cmdutil.findcmd(ui, cmd, table)
+            aliases, entry = cmdutil.findcmd(cmd, table, False)
             otables.append(entry[1])
         for t in otables:
             for o in t:
@@ -665,7 +665,7 @@
         ui.write("%s\n" % "\n".join(options))
         return
 
-    ui.write("%s\n" % "\n".join(util.sort(cmdutil.findpossible(ui, cmd, table))))
+    ui.write("%s\n" % "\n".join(util.sort(cmdutil.findpossible(cmd, table))))
 
 def debugfsinfo(ui, path = "."):
     file('.debugfsinfo', 'w').write('')
@@ -1272,7 +1272,7 @@
             ui.write('\n')
 
         try:
-            aliases, i = cmdutil.findcmd(ui, name, table)
+            aliases, i = cmdutil.findcmd(name, table, False)
         except cmdutil.AmbiguousCommand, inst:
             select = lambda c: c.lstrip('^').startswith(inst.args[0])
             helplist(_('list of commands:\n\n'), select)
--- a/mercurial/dispatch.py	Wed Oct 22 17:00:05 2008 -0500
+++ b/mercurial/dispatch.py	Wed Oct 22 17:34:08 2008 -0500
@@ -171,7 +171,8 @@
 
     if args:
         cmd, args = args[0], args[1:]
-        aliases, i = cmdutil.findcmd(ui, cmd, commands.table)
+        aliases, i = cmdutil.findcmd(cmd, commands.table,
+                                     ui.config("ui","strict"))
         cmd = aliases[0]
         defaults = ui.config("defaults", cmd)
         if defaults: