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

Brodie Rao brodie at bitheap.org
Sat Aug 21 21:52:20 CDT 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1282445294 14400
# Branch stable
# Node ID d79b5967d4b8c6d52bee62982c5775027ac37b9d
# Parent  b20211b307b39ed2dbfbe992d94d0f1a24e63e13
alias: make shadowing behavior more consistent (issue2054)

Currently, given an alias like the following:

    [alias]
    summary = summary --remote

The alias might be executed - or 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 -r b20211b307b3 -r d79b5967d4b8 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sat Aug 21 10:44:57 2010 -0500
+++ b/mercurial/dispatch.py	Sat Aug 21 22:48:14 2010 -0400
@@ -182,7 +182,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 = []
@@ -191,7 +191,11 @@ class cmdalias(object):
         self.badalias = False
 
         try:
-            cmdutil.findcmd(self.name, cmdtable, True)
+            aliases, entry = cmdutil.findcmd(self.name, cmdtable)
+            for alias, e in cmdtable.iteritems():
+                if e is entry:
+                    self.cmd = alias
+                    break
             self.shadows = True
         except error.UnknownCommand:
             self.shadows = False
@@ -256,7 +260,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