[PATCH] localrepo: get value from the unfiltered caches should check if the attribute existed

elson elson.wei at gmail.com
Tue Aug 6 21:05:55 CDT 2013


Here is the test bench

The output of original version:
>python test.py
Evaluate!
Evaluate!
"1" = 1
Evaluate!
"3" = 3
Evaluate!
"2" = 2


# HG changeset patch
# User Wei, Elson <elson.wei at gmail.com>
# Date 1375840998 -28800
#      Wed Aug 07 10:03:18 2013 +0800
# Node ID 291fb3910deee8630b2307ec340fe376f99106a6
# Parent  7a67f75deafc8880b539d3da42a719dab00d7cd6
localrepo.unfilteredpropertycache test

diff --git a/test.py b/test.py
new file mode 100644
--- /dev/null
+++ b/test.py
@@ -0,0 +1,26 @@
+from mercurial import localrepo
+
+_dict = {"1": 1, "2": 2, "3": 3}
+
+class unfilteredrepo:
+    def __init__(self):
+        pass
+
+class filteredrepo:
+    def __init__(self):
+        self._unfiltered = unfilteredrepo()
+
+    def unfiltered(self):
+        return self._unfiltered
+
+    @localrepo.unfilteredpropertycache
+    def testdict(self):
+        print "Evaluate!"
+        return _dict
+
+if __name__ == "__main__":
+    repo = filteredrepo()
+
+    for k in repo.testdict:
+        v = repo.testdict[k]
+        print "\"%s\" = %d" % (k, v)



2013/8/6 <elson.wei at gmail.com>

> # HG changeset patch
> # User Wei, Elson <elson.wei at gmail.com>
> # Date 1375760701 -28800
> #      Tue Aug 06 11:45:01 2013 +0800
> # Node ID 06e23972c0d2d9420e96dd657db1cc2d30b7fc11
> # Parent  a58251c0568fc5e86089a803ca75f75cc8c01678
> localrepo: get value from the unfiltered caches should check if the
> attribute existed.
>
> If the attribute existed already, it should be returned by getattr().
> Otherwise, it will be evaluated again.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -39,6 +39,8 @@
>      """propertycache that apply to unfiltered repo only"""
>
>      def __get__(self, repo, type=None):
> +        if hasunfilteredcache(repo, self.name):
> +            return getattr(repo.unfiltered(), self.name)
>          return super(unfilteredpropertycache,
> self).__get__(repo.unfiltered())
>
>  class filteredpropertycache(propertycache):
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130807/5cb033aa/attachment.html>


More information about the Mercurial-devel mailing list