[PATCH 1 of 3] extensions: set attributes to wrappers so we can trace them back

Jun Wu quark at fb.com
Fri Jul 1 08:09:03 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1467370013 -3600
#      Fri Jul 01 11:46:53 2016 +0100
# Node ID 21e49b9facede184e5d262211bd5cc34bddca974
# Parent  7dce56174916e09be39c690278942b4f7567b3f6
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 21e49b9faced
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
@@ -204,11 +204,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
@@ -248,7 +250,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
 
@@ -297,7 +299,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
 


More information about the Mercurial-devel mailing list