# HG changeset patch # User Jun Wu # Date 2016-08-10 14:21:42 # Node ID ce6317dcb94404929f49184f4b5f532bf0a6e8e2 # Parent 96bd27eb23f0593ccd8671d945a2106844c6cdad extensions: set attributes to wrappers so we can trace them back This patch adds two attributes about the original function and the unbound wrapper. It allows us to get a chain of wrappers. See the next patch. diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -210,11 +210,13 @@ def bind(func, *args): return func(*(args + a), **kw) return closure -def _updatewrapper(wrap, origfn): - '''Copy attributes to wrapper function''' +def _updatewrapper(wrap, origfn, unboundwrapper): + '''Copy and add some useful attributes to wrapper''' wrap.__module__ = getattr(origfn, '__module__') wrap.__doc__ = getattr(origfn, '__doc__') wrap.__dict__.update(getattr(origfn, '__dict__', {})) + wrap._origfunc = origfn + wrap._unboundwrapper = unboundwrapper def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): '''Wrap the command named `command' in table @@ -254,7 +256,7 @@ def wrapcommand(table, command, wrapper, origfn = entry[0] wrap = bind(util.checksignature(wrapper), util.checksignature(origfn)) - _updatewrapper(wrap, origfn) + _updatewrapper(wrap, origfn, wrapper) if docstring is not None: wrap.__doc__ += docstring @@ -303,7 +305,7 @@ def wrapfunction(container, funcname, wr origfn = getattr(container, funcname) assert callable(origfn) wrap = bind(wrapper, origfn) - _updatewrapper(wrap, origfn) + _updatewrapper(wrap, origfn, wrapper) setattr(container, funcname, wrap) return origfn