diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -39,7 +39,10 @@ class unfilteredpropertycache(propertyca """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""" diff --git a/tests/test-propertycache.py b/tests/test-propertycache.py --- a/tests/test-propertycache.py +++ b/tests/test-propertycache.py @@ -24,8 +24,19 @@ def testcachedfoobar(repo): calllog.append(val) return val +unficalllog = [] +@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 @@ -92,3 +103,77 @@ print vars(visibleview).get('testcachedf 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 @@ -34,3 +34,51 @@ 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