<div dir="ltr"><div><div>Here is the test bench<br><br></div>The output of original version:<br>>python test.py<br>Evaluate!<br>Evaluate!<br>"1" = 1<br>Evaluate!<br>"3" = 3<br>Evaluate!<br>"2" = 2<br>
<br></div><div><div><br># HG changeset patch<br># User Wei, Elson <<a href="mailto:elson.wei@gmail.com">elson.wei@gmail.com</a>><br># Date 1375840998 -28800<br>#      Wed Aug 07 10:03:18 2013 +0800<br># Node ID 291fb3910deee8630b2307ec340fe376f99106a6<br>
# Parent  7a67f75deafc8880b539d3da42a719dab00d7cd6<br>localrepo.unfilteredpropertycache test<br><br>diff --git a/test.py b/test.py<br>new file mode 100644<br>--- /dev/null<br>+++ b/test.py<br>@@ -0,0 +1,26 @@<br>+from mercurial import localrepo<br>
+<br>+_dict = {"1": 1, "2": 2, "3": 3}<br>+<br>+class unfilteredrepo:<br>+    def __init__(self):<br>+        pass<br>+<br>+class filteredrepo:<br>+    def __init__(self):<br>+        self._unfiltered = unfilteredrepo()<br>
+<br>+    def unfiltered(self):<br>+        return self._unfiltered<br>+<br>+    @localrepo.unfilteredpropertycache<br>+    def testdict(self):<br>+        print "Evaluate!"<br>+        return _dict<br>+<br>+if __name__ == "__main__":<br>
+    repo = filteredrepo()<br>+<br>+    for k in repo.testdict:<br>+        v = repo.testdict[k]<br>+        print "\"%s\" = %d" % (k, v)<br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/8/6  <span dir="ltr"><<a href="mailto:elson.wei@gmail.com" target="_blank">elson.wei@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# HG changeset patch<br>
# User Wei, Elson <<a href="mailto:elson.wei@gmail.com">elson.wei@gmail.com</a>><br>
# Date 1375760701 -28800<br>
#      Tue Aug 06 11:45:01 2013 +0800<br>
# Node ID 06e23972c0d2d9420e96dd657db1cc2d30b7fc11<br>
# Parent  a58251c0568fc5e86089a803ca75f75cc8c01678<br>
localrepo: get value from the unfiltered caches should check if the attribute existed.<br>
<br>
If the attribute existed already, it should be returned by getattr().<br>
Otherwise, it will be evaluated again.<br>
<br>
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py<br>
--- a/mercurial/localrepo.py<br>
+++ b/mercurial/localrepo.py<br>
@@ -39,6 +39,8 @@<br>
     """propertycache that apply to unfiltered repo only"""<br>
<br>
     def __get__(self, repo, type=None):<br>
+        if hasunfilteredcache(repo, <a href="http://self.name" target="_blank">self.name</a>):<br>
+            return getattr(repo.unfiltered(), <a href="http://self.name" target="_blank">self.name</a>)<br>
         return super(unfilteredpropertycache, self).__get__(repo.unfiltered())<br>
<br>
 class filteredpropertycache(propertycache):<br>
</blockquote></div><br></div></div>