# HG changeset patch # User Olle Lundberg # Date 1396564256 -7200 # Node ID 4f21a3279a6063f9b9c1dd406db81aeeb8407d73 # Parent 7de15cfd79f70b171ba30ddb17d19624e5ca83ff evolve: add function to deprecate an alias When cleaning up the UI for evolve we will deprecate old aliases, but still want them to work for a while. This is a helper function that will be called during the extension setup and has the ability map an old alias to a new or canonical one. diff -r 7de15cfd79f7 -r 4f21a3279a60 hgext/evolve.py --- a/hgext/evolve.py Wed Mar 26 00:38:14 2014 +0100 +++ b/hgext/evolve.py Fri Apr 04 00:30:56 2014 +0200 @@ -874,6 +874,38 @@ _('record the specified user in metadata'), _('USER')), ] +def _deprecatealias(oldalias, newalias): + '''Deprecates an alias for a command in favour of another + + Creates a new entry in the command table for the old alias. It creates a + wrapper that has its synopsis set to show that is has been deprecated. + The documentation will be replace with a pointer to the new alias. + If a user invokes the command a deprecation warning will be printed and + the command of the *new* alias will be invoked. + + This function is loosely based on the extensions.wrapcommand function. + ''' + aliases, entry = cmdutil.findcmd(newalias, cmdtable) + for alias, e in cmdtable.iteritems(): + if e is entry: + break + + synopsis = '(DEPRECATED)' + if len(entry) > 2: + fn, opts, _syn = entry + else: + fn, opts, = entry + deprecationwarning = _('%s have been deprecated in favor of %s\n' % ( + oldalias, newalias)) + def newfn(*args, **kwargs): + ui = args[0] + ui.warn(deprecationwarning) + util.checksignature(fn)(*args, **kwargs) + newfn.__doc__ = deprecationwarning + cmdwrapper = command(oldalias, opts, synopsis) + cmdwrapper(newfn) + + @command('debugrecordpruneparents', [], '') def cmddebugrecordpruneparents(ui, repo): """add parents data to prune markers when possible