alias: shortcut command matching show shadowing works properly (issue3104) stable 2.0.1
authorMatt Mackall <mpm@selenic.com>
Thu, 01 Dec 2011 15:51:36 -0600
branchstable
changeset 15600 195dbd1cef0c
parent 15599 c6be93a4c378
child 15601 22148c19f150
alias: shortcut command matching show shadowing works properly (issue3104) An alias for 'log' was stored in the same command table as '^log|history'. If the hash function happens to give the latter first, the alias is effectively ignored when matching 'log'.
mercurial/cmdutil.py
tests/test-alias.t
--- a/mercurial/cmdutil.py	Thu Dec 01 20:42:24 2011 +0100
+++ b/mercurial/cmdutil.py	Thu Dec 01 15:51:36 2011 -0600
@@ -23,7 +23,14 @@
     """
     choice = {}
     debugchoice = {}
-    for e in table.keys():
+
+    if cmd in table:
+        # short-circuit exact matches, "log" alias beats "^log|history"
+        keys = [cmd]
+    else:
+        keys = table.keys()
+
+    for e in keys:
         aliases = parsealiases(e)
         found = None
         if cmd in aliases:
--- a/tests/test-alias.t	Thu Dec 01 20:42:24 2011 +0100
+++ b/tests/test-alias.t	Thu Dec 01 15:51:36 2011 -0600
@@ -395,3 +395,11 @@
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
 
+This should show id:
+
+  $ hg --config alias.log='id' log
+  000000000000 tip
+
+This shouldn't:
+
+  $ hg --config alias.log='id' history