repoview: allow methods on the proxy class to be replaced
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 07 Dec 2014 10:52:56 -0500
changeset 23502 ced3ecfc2e57
parent 23499 b46876c94a93
child 23503 ca54fb3d71ce
repoview: allow methods on the proxy class to be replaced It doesn't seem to be a common idiom for repo instances, but the status() method is replaced in largefiles' purge() override. Since __setattr__ is implemented in repoview to setattr() on the unfiltered repo, the replacement method wouldn't get called unless it was invoked with the unfiltered repo, because the filtered repo remains unchanged. Since this doesn't seem to be commonly used, I didn't bother to filter out methods that perhaps shouldn't be replaced, such as changelog().
mercurial/repoview.py
--- a/mercurial/repoview.py	Wed Nov 26 23:23:33 2014 -0800
+++ b/mercurial/repoview.py	Sun Dec 07 10:52:56 2014 -0500
@@ -6,6 +6,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import types
 import copy
 import error
 import phases
@@ -310,6 +311,10 @@
         return getattr(self._unfilteredrepo, attr)
 
     def __setattr__(self, attr, value):
+        # Allow method replacement on filtered repos, like status() in
+        # largefiles' purge override
+        if type(value) == types.FunctionType:
+            object.__setattr__(self, attr, value)
         return setattr(self._unfilteredrepo, attr, value)
 
     def __delattr__(self, attr):