changeset 1517:b582dbc16165

Canonicalize command when using aliases or prefix matching. This makes the norepo check and the help and version command work when not using the canonical name.
author Thomas Arendsen Hein <thomas@intevation.de>
date Mon, 07 Nov 2005 18:39:25 +0100
parents b254243b7159
children ac4ca6bf2383
files mercurial/commands.py
diffstat 1 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Nov 04 11:37:45 2005 -0800
+++ b/mercurial/commands.py	Mon Nov 07 18:39:25 2005 +0100
@@ -387,7 +387,7 @@
         if with_version:
             show_version(ui)
             ui.write('\n')
-        key, i = find(cmd)
+        aliases, i = find(cmd)
         # synopsis
         ui.write("%s\n\n" % i[2])
 
@@ -399,9 +399,8 @@
 
         if not ui.quiet:
             # aliases
-            aliases = ', '.join(key.split('|')[1:])
-            if aliases:
-                ui.write(_("\naliases: %s\n") % aliases)
+            if len(aliases) > 1:
+                ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
 
             # options
             if i[1]:
@@ -2374,17 +2373,20 @@
           " debugindex debugindexdot paths")
 
 def find(cmd):
-    choice = []
+    """Return (aliases, command table entry) for command string."""
+    choice = None
     for e in table.keys():
         aliases = e.lstrip("^").split("|")
         if cmd in aliases:
-            return e, table[e]
+            return aliases, table[e]
         for a in aliases:
             if a.startswith(cmd):
-                choice.append(e)
-    if len(choice) == 1:
-        e = choice[0]
-        return e, table[e]
+                if choice:
+                    raise UnknownCommand(cmd)
+                else:
+                    choice = aliases, table[e]
+    if choice:
+        return choice
 
     raise UnknownCommand(cmd)
 
@@ -2422,7 +2424,8 @@
 
             cmd, args = args[0], args[1:]
 
-        i = find(cmd)[1]
+        aliases, i = find(cmd)
+        cmd = aliases[0]
         c = list(i[1])
     else:
         cmd = None