[PATCH] alias: make shadowing behavior more consistent (issue2054)

Brodie Rao dackze at gmail.com
Tue Feb 23 13:24:05 CST 2010


# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1266952976 18000
# Branch stable
# Node ID 756335bed897077ace28e410df438a8a299b2f90
# Parent  e3eff76552f14981501454cc173411d756a9bf24
alias: make shadowing behavior more consistent (issue2054)

Currently, given an alias like the following:

    [alias]
    summary = summary --remote

The alias might be executed - and it might not - depending on the order
of the cmdtable dict.

This happens because cmdalias gets assigned back to the cmdtable like so:

    cmdtable['summary'] = ...

Yet '^summary|sum' is still in the table, so which one cmdutil.findcmd()
chooses isn't deterministic.

This patch makes cmdalias assign back to '^summary|sum'. It uses the same
cmdtable key lookup that extensions.wrapcommand() does.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -169,7 +169,7 @@ def aliasargs(fn):
 
 class cmdalias(object):
     def __init__(self, name, definition, cmdtable):
-        self.name = name
+        self.name = self.cmd = name
         self.definition = definition
         self.args = []
         self.opts = []
@@ -178,7 +178,11 @@ class cmdalias(object):
         self.badalias = False
 
         try:
-            cmdutil.findcmd(self.name, cmdtable, True)
+            aliases, entry = cmdutil.findcmd(self.name, cmdtable, True)
+            for alias, e in cmdtable.iteritems():
+                if e is entry:
+                    self.cmd = alias
+                    break
             self.shadows = True
         except error.UnknownCommand:
             self.shadows = False
@@ -243,7 +247,7 @@ def addaliases(ui, cmdtable):
     # but only if they have been defined prior to the current definition.
     for alias, definition in ui.configitems('alias'):
         aliasdef = cmdalias(alias, definition, cmdtable)
-        cmdtable[alias] = (aliasdef, aliasdef.opts, aliasdef.help)
+        cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
         if aliasdef.norepo:
             commands.norepo += ' %s' % alias
 


More information about the Mercurial-devel mailing list