mercurial/extensions.py
changeset 32722 de09138bf0f5
parent 32417 f40dc6f7c12f
child 32724 ea1c2eb7abd3
--- a/mercurial/extensions.py	Wed Apr 26 16:05:22 2017 +0200
+++ b/mercurial/extensions.py	Thu Jun 08 10:44:53 2017 -0400
@@ -308,6 +308,25 @@
     table[key] = tuple(newentry)
     return entry
 
+def wrapfilecache(cls, propname, wrapper):
+    """Wraps a filecache property.
+
+    These can't be wrapped using the normal wrapfunction.
+    """
+    assert callable(wrapper)
+    for currcls in cls.__mro__:
+        if propname in currcls.__dict__:
+            origfn = currcls.__dict__[propname].func
+            assert callable(origfn)
+            def wrap(*args, **kwargs):
+                return wrapper(origfn, *args, **kwargs)
+            currcls.__dict__[propname].func = wrap
+            break
+
+    if currcls is object:
+        raise AttributeError(
+            _("type '%s' has no property '%s'") % (cls, propname))
+
 def wrapfunction(container, funcname, wrapper):
     '''Wrap the function named funcname in container