Mercurial > hg-stable
changeset 7215:0ab5f21c390b
extensions: add wrapping functions
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 22 Oct 2008 17:34:50 -0500 |
parents | 0e8a9530d323 |
children | 292fb2ad2846 |
files | mercurial/extensions.py |
diffstat | 1 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/extensions.py Wed Oct 22 17:34:37 2008 -0500 +++ b/mercurial/extensions.py Wed Oct 22 17:34:50 2008 -0500 @@ -6,7 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. import imp, os -import util +import util, cmdutil from i18n import _ _extensions = {} @@ -87,3 +87,28 @@ if ui.print_exc(): return 1 +def wrapcommand(table, command, wrapper): + aliases, entry = cmdutil.findcmd(command, table) + for alias, e in table.iteritems(): + if e is entry: + key = alias + break + + origfn = entry[0] + def wrap(*args, **kwargs): + return wrapper(origfn, *args, **kwargs) + + wrap.__doc__ = getattr(origfn, '__doc__') + + newentry = list(entry) + newentry[0] = wrap + table[key] = tuple(newentry) + return entry + +def wrapfunction(container, funcname, wrapper): + def wrap(*args, **kwargs): + return wrapper(origfn, *args, **kwargs) + + origfn = getattr(container, funcname) + setattr(container, funcname, wrap) + return origfn