[PATCH 1 of 3 evolve-ext] evolve: add function to deprecate an alias

Olle Lundberg olle.lundberg at gmail.com
Thu Apr 3 18:12:33 CDT 2014


# HG changeset patch
# User Olle Lundberg <geek at nerd.sh>
# Date 1396564256 -7200
#      Fri Apr 04 00:30:56 2014 +0200
# Node ID a9f23a90d373622bbf9d44d929ecbdd3c02d6a3e
# 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 --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -872,10 +872,42 @@
      _('record the specified date in metadata'), _('DATE')),
     ('u', 'user', '',
      _('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
 
     This commands search the repo for prune markers without parent information.


More information about the Mercurial-devel mailing list