[PATCH 1 of 2] repoview: allow methods on the proxy class to be replaced

Matt Harbison mharbison72 at gmail.com
Tue Dec 9 02:31:31 UTC 2014


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1417967576 18000
#      Sun Dec 07 10:52:56 2014 -0500
# Node ID 299fc395d9c4f633a07ef08187f46151ca0ab298
# Parent  b46876c94a935f570ac915ff3d345583c42989bd
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().

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -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):


More information about the Mercurial-devel mailing list