[PATCH 2 of 2 STABLE] repoview: have unfilteredpropertycache using the underlying cache

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Mon Sep 30 07:53:33 CDT 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1380543794 -7200
#      Mon Sep 30 14:23:14 2013 +0200
# Branch stable
# Node ID bcb07b3b0ee1cff0340bec93fa125881e77c927d
# Parent  365d4888627295bb0368d658224cb9900fdcb6f7
repoview: have unfilteredpropertycache using the underlying cache

A  `unfilteredpropertycache` is a kind of `propertycache` used on `localrepo` to
unsure it will always be run against unfiltered repo and stored only once.

As the cached value is never stored in the repoview instance, the descriptor
will always be called. Before this patch such calls always result in a call to
the `__get__` method of the `propertycache` on the unfiltered repo. That was
recomputing a new value on every access through a repoview.

We can't prevent the repoview's `unfilteredpropertycache` to get called on every
access. In that case the new code makes a standard attribute access to the
property. If a value is cached it will be used.

The `propertycache` test file have been augmented with test about this issue.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -37,11 +37,14 @@ class storecache(repofilecache):
 
 class unfilteredpropertycache(propertycache):
     """propertycache that apply to unfiltered repo only"""
 
     def __get__(self, repo, type=None):
-        return super(unfilteredpropertycache, self).__get__(repo.unfiltered())
+        unfi = repo.unfiltered()
+        if unfi is repo:
+            return super(unfilteredpropertycache, self).__get__(unfi)
+        return getattr(unfi, self.name)
 
 class filteredpropertycache(propertycache):
     """propertycache that must take filtering in account"""
 
     def cachevalue(self, obj, value):
diff --git a/tests/test-propertycache.py b/tests/test-propertycache.py
--- a/tests/test-propertycache.py
+++ b/tests/test-propertycache.py
@@ -22,12 +22,23 @@ def testcachedfoobar(repo):
         name = ''
     val = len(name)
     calllog.append(val)
     return val
 
+unficalllog = []
+ at mercurial.localrepo.unfilteredpropertycache
+def testcachedunfifoobar(repo):
+    name = repo.filtername
+    if name is None:
+        name = ''
+    val = 100 + len(name)
+    unficalllog.append(val)
+    return val
+
 #plug them on repo
 mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar
+mercurial.localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
 
 
 # create an empty repo. and instanciate it. It is important to run
 # those test on the real object to detect regression.
 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
@@ -90,5 +101,79 @@ print vars(repo).get('testcachedfoobar',
 print 'cached value ("visible" view):',
 print vars(visibleview).get('testcachedfoobar', 'NOCACHE')
 print 'cached value ("immutable" view):',
 print vars(immutableview).get('testcachedfoobar', 'NOCACHE')
 
+# unfiltered property cache test
+print ''
+print ''
+print '=== unfiltered property cache ==='
+print ''
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= first access on unfiltered, should do a call'
+print 'access (unfiltered):', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= second access on unfiltered, should not do call'
+print 'access (unfiltered):', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= access on view should use the unfiltered cache'
+print 'access (unfiltered):      ', repo.testcachedunfifoobar
+print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
+print 'access ("immutable" view):', immutableview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= even if we clear the unfiltered cache'
+del repo.__dict__['testcachedunfifoobar']
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'unficalllog:', unficalllog
+print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'access ("immutable" view):', immutableview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'access (unfiltered):      ', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
diff --git a/tests/test-propertycache.py.out b/tests/test-propertycache.py.out
--- a/tests/test-propertycache.py.out
+++ b/tests/test-propertycache.py.out
@@ -32,5 +32,53 @@ cached value ("immutable" view): NOCACHE
 access: 9
 calllog: [0, 7, 9]
 cached value (unfiltered): 0
 cached value ("visible" view): 7
 cached value ("immutable" view): 9
+
+
+=== unfiltered property cache ===
+
+unficalllog: []
+cached value (unfiltered):       NOCACHE
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE
+
+= first access on unfiltered, should do a call
+access (unfiltered): 100
+unficalllog: [100]
+cached value (unfiltered):       100
+
+= second access on unfiltered, should not do call
+access (unfiltered): 100
+unficalllog: [100]
+cached value (unfiltered):       100
+
+= access on view should use the unfiltered cache
+access (unfiltered):       100
+access ("visible" view):   100
+access ("immutable" view): 100
+unficalllog: [100]
+cached value (unfiltered):       100
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE
+
+= even if we clear the unfiltered cache
+cached value (unfiltered):       NOCACHE
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE
+unficalllog: [100]
+access ("visible" view):   100
+unficalllog: [100, 100]
+cached value (unfiltered):       100
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE
+access ("immutable" view): 100
+unficalllog: [100, 100]
+cached value (unfiltered):       100
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE
+access (unfiltered):       100
+unficalllog: [100, 100]
+cached value (unfiltered):       100
+cached value ("visible" view):   NOCACHE
+cached value ("immutable" view): NOCACHE


More information about the Mercurial-devel mailing list