|
1 """test behavior of propertycache and unfiltered propertycache |
|
2 |
|
3 The repoview overlay is quite complexe. We test the behavior of |
|
4 property cache of both localrepo and repoview to prevent |
|
5 regression.""" |
|
6 |
|
7 import os, subprocess |
|
8 import mercurial.localrepo |
|
9 import mercurial.repoview |
|
10 import mercurial.util |
|
11 import mercurial.hg |
|
12 import mercurial.ui as uimod |
|
13 |
|
14 |
|
15 # create some special property cache that trace they call |
|
16 |
|
17 calllog = [] |
|
18 @mercurial.util.propertycache |
|
19 def testcachedfoobar(repo): |
|
20 name = repo.filtername |
|
21 if name is None: |
|
22 name = '' |
|
23 val = len(name) |
|
24 calllog.append(val) |
|
25 return val |
|
26 |
|
27 #plug them on repo |
|
28 mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar |
|
29 |
|
30 |
|
31 # create an empty repo. and instanciate it. It is important to run |
|
32 # those test on the real object to detect regression. |
|
33 repopath = os.path.join(os.environ['TESTTMP'], 'repo') |
|
34 subprocess.check_call(['hg', 'init', repopath]) |
|
35 ui = uimod.ui() |
|
36 repo = mercurial.hg.repository(ui, path=repopath).unfiltered() |
|
37 |
|
38 |
|
39 print '' |
|
40 print '=== property cache ===' |
|
41 print '' |
|
42 print 'calllog:', calllog |
|
43 print 'cached value (unfiltered):', |
|
44 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
45 |
|
46 print '' |
|
47 print '= first access on unfiltered, should do a call' |
|
48 print 'access:', repo.testcachedfoobar |
|
49 print 'calllog:', calllog |
|
50 print 'cached value (unfiltered):', |
|
51 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
52 |
|
53 print '' |
|
54 print '= second access on unfiltered, should not do call' |
|
55 print 'access', repo.testcachedfoobar |
|
56 print 'calllog:', calllog |
|
57 print 'cached value (unfiltered):', |
|
58 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
59 |
|
60 print '' |
|
61 print '= first access on "visible" view, should do a call' |
|
62 visibleview = repo.filtered('visible') |
|
63 print 'cached value ("visible" view):', |
|
64 print vars(visibleview).get('testcachedfoobar', 'NOCACHE') |
|
65 print 'access:', visibleview.testcachedfoobar |
|
66 print 'calllog:', calllog |
|
67 print 'cached value (unfiltered):', |
|
68 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
69 print 'cached value ("visible" view):', |
|
70 print vars(visibleview).get('testcachedfoobar', 'NOCACHE') |
|
71 |
|
72 print '' |
|
73 print '= second access on "visible view", should not do call' |
|
74 print 'access:', visibleview.testcachedfoobar |
|
75 print 'calllog:', calllog |
|
76 print 'cached value (unfiltered):', |
|
77 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
78 print 'cached value ("visible" view):', |
|
79 print vars(visibleview).get('testcachedfoobar', 'NOCACHE') |
|
80 |
|
81 print '' |
|
82 print '= no effect on other view' |
|
83 immutableview = repo.filtered('immutable') |
|
84 print 'cached value ("immutable" view):', |
|
85 print vars(immutableview).get('testcachedfoobar', 'NOCACHE') |
|
86 print 'access:', immutableview.testcachedfoobar |
|
87 print 'calllog:', calllog |
|
88 print 'cached value (unfiltered):', |
|
89 print vars(repo).get('testcachedfoobar', 'NOCACHE') |
|
90 print 'cached value ("visible" view):', |
|
91 print vars(visibleview).get('testcachedfoobar', 'NOCACHE') |
|
92 print 'cached value ("immutable" view):', |
|
93 print vars(immutableview).get('testcachedfoobar', 'NOCACHE') |
|
94 |