comparison mercurial/dispatch.py @ 12039:18e1e7520b67 stable

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.
author Brodie Rao <brodie@bitheap.org>
date Sat, 21 Aug 2010 22:48:14 -0400
parents 9cbc62f68328
children 529e712cb1ba a4fbbe0fbc38
comparison
equal deleted inserted replaced
12038:9617803b1acb 12039:18e1e7520b67
180 return fn.args 180 return fn.args
181 return [] 181 return []
182 182
183 class cmdalias(object): 183 class cmdalias(object):
184 def __init__(self, name, definition, cmdtable): 184 def __init__(self, name, definition, cmdtable):
185 self.name = name 185 self.name = self.cmd = name
186 self.definition = definition 186 self.definition = definition
187 self.args = [] 187 self.args = []
188 self.opts = [] 188 self.opts = []
189 self.help = '' 189 self.help = ''
190 self.norepo = True 190 self.norepo = True
191 self.badalias = False 191 self.badalias = False
192 192
193 try: 193 try:
194 cmdutil.findcmd(self.name, cmdtable, True) 194 aliases, entry = cmdutil.findcmd(self.name, cmdtable)
195 for alias, e in cmdtable.iteritems():
196 if e is entry:
197 self.cmd = alias
198 break
195 self.shadows = True 199 self.shadows = True
196 except error.UnknownCommand: 200 except error.UnknownCommand:
197 self.shadows = False 201 self.shadows = False
198 202
199 if not self.definition: 203 if not self.definition:
254 # aliases are processed after extensions have been loaded, so they 258 # aliases are processed after extensions have been loaded, so they
255 # may use extension commands. Aliases can also use other alias definitions, 259 # may use extension commands. Aliases can also use other alias definitions,
256 # but only if they have been defined prior to the current definition. 260 # but only if they have been defined prior to the current definition.
257 for alias, definition in ui.configitems('alias'): 261 for alias, definition in ui.configitems('alias'):
258 aliasdef = cmdalias(alias, definition, cmdtable) 262 aliasdef = cmdalias(alias, definition, cmdtable)
259 cmdtable[alias] = (aliasdef, aliasdef.opts, aliasdef.help) 263 cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
260 if aliasdef.norepo: 264 if aliasdef.norepo:
261 commands.norepo += ' %s' % alias 265 commands.norepo += ' %s' % alias
262 266
263 def _parse(ui, args): 267 def _parse(ui, args):
264 options = {} 268 options = {}