changeset 29775:ce6317dcb944

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.
author Jun Wu <quark@fb.com>
date Wed, 10 Aug 2016 15:21:42 +0100
parents 96bd27eb23f0
children 8bf97c4c6c2a
files mercurial/extensions.py
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/extensions.py	Wed Aug 10 15:05:20 2016 +0100
+++ b/mercurial/extensions.py	Wed Aug 10 15:21:42 2016 +0100
@@ -210,11 +210,13 @@
         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 @@
 
     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 @@
     origfn = getattr(container, funcname)
     assert callable(origfn)
     wrap = bind(wrapper, origfn)
-    _updatewrapper(wrap, origfn)
+    _updatewrapper(wrap, origfn, wrapper)
     setattr(container, funcname, wrap)
     return origfn