Patchwork localrepo: get value from the unfiltered caches should check if the attribute existed

login
register
mail settings
Submitter elson.wei@gmail.com
Date Aug. 7, 2013, 2:05 a.m.
Message ID <CA+jbiHFV0AxWA-SAho4BEYMWU8m+PHNsk7ih=V-sJ1XAM9OZfQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/2015/
State Superseded
Headers show

Comments

elson.wei@gmail.com - Aug. 7, 2013, 2:05 a.m.
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@gmail.com>
# Date 1375840998 -28800
#      Wed Aug 07 10:03:18 2013 +0800
# Node ID 291fb3910deee8630b2307ec340fe376f99106a6
# Parent  7a67f75deafc8880b539d3da42a719dab00d7cd6
localrepo.unfilteredpropertycache test




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

> # HG changeset patch
> # User Wei, Elson <elson.wei@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):
>

Patch

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)