Show More
@@ -1,183 +1,189 b'' | |||||
1 | """test behavior of propertycache and unfiltered propertycache |
|
1 | """test behavior of propertycache and unfiltered propertycache | |
2 |
|
2 | |||
3 | The repoview overlay is quite complex. We test the behavior of |
|
3 | The repoview overlay is quite complex. We test the behavior of | |
4 | property cache of both localrepo and repoview to prevent |
|
4 | property cache of both localrepo and repoview to prevent | |
5 | regression.""" |
|
5 | regression.""" | |
6 |
|
6 | |||
7 | from __future__ import absolute_import, print_function |
|
7 | from __future__ import absolute_import, print_function | |
8 | import os |
|
8 | import os | |
9 | import subprocess |
|
9 | import subprocess | |
10 |
|
10 | |||
11 | from mercurial import ( |
|
11 | from mercurial import ( | |
12 | hg, |
|
12 | hg, | |
13 | localrepo, |
|
13 | localrepo, | |
14 | pycompat, |
|
14 | pycompat, | |
15 | ui as uimod, |
|
15 | ui as uimod, | |
16 | util, |
|
16 | util, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
|
19 | from mercurial.utils import ( | |||
|
20 | procutil, | |||
|
21 | ) | |||
|
22 | ||||
19 | # create some special property cache that trace they call |
|
23 | # create some special property cache that trace they call | |
20 |
|
24 | |||
21 | calllog = [] |
|
25 | calllog = [] | |
22 | @util.propertycache |
|
26 | @util.propertycache | |
23 | def testcachedfoobar(repo): |
|
27 | def testcachedfoobar(repo): | |
24 | name = repo.filtername |
|
28 | name = repo.filtername | |
25 | if name is None: |
|
29 | if name is None: | |
26 | name = '' |
|
30 | name = '' | |
27 | val = len(name) |
|
31 | val = len(name) | |
28 | calllog.append(val) |
|
32 | calllog.append(val) | |
29 | return val |
|
33 | return val | |
30 |
|
34 | |||
31 | unficalllog = [] |
|
35 | unficalllog = [] | |
32 | @localrepo.unfilteredpropertycache |
|
36 | @localrepo.unfilteredpropertycache | |
33 | def testcachedunfifoobar(repo): |
|
37 | def testcachedunfifoobar(repo): | |
34 | name = repo.filtername |
|
38 | name = repo.filtername | |
35 | if name is None: |
|
39 | if name is None: | |
36 | name = '' |
|
40 | name = '' | |
37 | val = 100 + len(name) |
|
41 | val = 100 + len(name) | |
38 | unficalllog.append(val) |
|
42 | unficalllog.append(val) | |
39 | return val |
|
43 | return val | |
40 |
|
44 | |||
41 | #plug them on repo |
|
45 | #plug them on repo | |
42 | localrepo.localrepository.testcachedfoobar = testcachedfoobar |
|
46 | localrepo.localrepository.testcachedfoobar = testcachedfoobar | |
43 | localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar |
|
47 | localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar | |
44 |
|
48 | |||
45 |
|
49 | |||
46 | # Create an empty repo and instantiate it. It is important to run |
|
50 | # Create an empty repo and instantiate it. It is important to run | |
47 | # these tests on the real object to detect regression. |
|
51 | # these tests on the real object to detect regression. | |
48 | repopath = pycompat.fsencode(os.path.join(os.environ['TESTTMP'], 'repo')) |
|
52 | repopath = pycompat.fsencode(os.path.join(os.environ['TESTTMP'], 'repo')) | |
49 | assert subprocess.call(['hg', 'init', repopath]) == 0 |
|
53 | assert subprocess.call(pycompat.rapply(procutil.tonativestr, | |
|
54 | [b'hg', b'init', repopath])) == 0 | |||
|
55 | ||||
50 | ui = uimod.ui.load() |
|
56 | ui = uimod.ui.load() | |
51 | repo = hg.repository(ui, path=repopath).unfiltered() |
|
57 | repo = hg.repository(ui, path=repopath).unfiltered() | |
52 |
|
58 | |||
53 |
|
59 | |||
54 | print('') |
|
60 | print('') | |
55 | print('=== property cache ===') |
|
61 | print('=== property cache ===') | |
56 | print('') |
|
62 | print('') | |
57 | print('calllog:', calllog) |
|
63 | print('calllog:', calllog) | |
58 | print('cached value (unfiltered):', |
|
64 | print('cached value (unfiltered):', | |
59 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
65 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
60 |
|
66 | |||
61 | print('') |
|
67 | print('') | |
62 | print('= first access on unfiltered, should do a call') |
|
68 | print('= first access on unfiltered, should do a call') | |
63 | print('access:', repo.testcachedfoobar) |
|
69 | print('access:', repo.testcachedfoobar) | |
64 | print('calllog:', calllog) |
|
70 | print('calllog:', calllog) | |
65 | print('cached value (unfiltered):', |
|
71 | print('cached value (unfiltered):', | |
66 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
72 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
67 |
|
73 | |||
68 | print('') |
|
74 | print('') | |
69 | print('= second access on unfiltered, should not do call') |
|
75 | print('= second access on unfiltered, should not do call') | |
70 | print('access', repo.testcachedfoobar) |
|
76 | print('access', repo.testcachedfoobar) | |
71 | print('calllog:', calllog) |
|
77 | print('calllog:', calllog) | |
72 | print('cached value (unfiltered):', |
|
78 | print('cached value (unfiltered):', | |
73 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
79 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
74 |
|
80 | |||
75 | print('') |
|
81 | print('') | |
76 | print('= first access on "visible" view, should do a call') |
|
82 | print('= first access on "visible" view, should do a call') | |
77 | visibleview = repo.filtered('visible') |
|
83 | visibleview = repo.filtered('visible') | |
78 | print('cached value ("visible" view):', |
|
84 | print('cached value ("visible" view):', | |
79 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) |
|
85 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) | |
80 | print('access:', visibleview.testcachedfoobar) |
|
86 | print('access:', visibleview.testcachedfoobar) | |
81 | print('calllog:', calllog) |
|
87 | print('calllog:', calllog) | |
82 | print('cached value (unfiltered):', |
|
88 | print('cached value (unfiltered):', | |
83 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
89 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
84 | print('cached value ("visible" view):', |
|
90 | print('cached value ("visible" view):', | |
85 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) |
|
91 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) | |
86 |
|
92 | |||
87 | print('') |
|
93 | print('') | |
88 | print('= second access on "visible view", should not do call') |
|
94 | print('= second access on "visible view", should not do call') | |
89 | print('access:', visibleview.testcachedfoobar) |
|
95 | print('access:', visibleview.testcachedfoobar) | |
90 | print('calllog:', calllog) |
|
96 | print('calllog:', calllog) | |
91 | print('cached value (unfiltered):', |
|
97 | print('cached value (unfiltered):', | |
92 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
98 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
93 | print('cached value ("visible" view):', |
|
99 | print('cached value ("visible" view):', | |
94 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) |
|
100 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) | |
95 |
|
101 | |||
96 | print('') |
|
102 | print('') | |
97 | print('= no effect on other view') |
|
103 | print('= no effect on other view') | |
98 | immutableview = repo.filtered('immutable') |
|
104 | immutableview = repo.filtered('immutable') | |
99 | print('cached value ("immutable" view):', |
|
105 | print('cached value ("immutable" view):', | |
100 | vars(immutableview).get('testcachedfoobar', 'NOCACHE')) |
|
106 | vars(immutableview).get('testcachedfoobar', 'NOCACHE')) | |
101 | print('access:', immutableview.testcachedfoobar) |
|
107 | print('access:', immutableview.testcachedfoobar) | |
102 | print('calllog:', calllog) |
|
108 | print('calllog:', calllog) | |
103 | print('cached value (unfiltered):', |
|
109 | print('cached value (unfiltered):', | |
104 | vars(repo).get('testcachedfoobar', 'NOCACHE')) |
|
110 | vars(repo).get('testcachedfoobar', 'NOCACHE')) | |
105 | print('cached value ("visible" view):', |
|
111 | print('cached value ("visible" view):', | |
106 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) |
|
112 | vars(visibleview).get('testcachedfoobar', 'NOCACHE')) | |
107 | print('cached value ("immutable" view):', |
|
113 | print('cached value ("immutable" view):', | |
108 | vars(immutableview).get('testcachedfoobar', 'NOCACHE')) |
|
114 | vars(immutableview).get('testcachedfoobar', 'NOCACHE')) | |
109 |
|
115 | |||
110 | # unfiltered property cache test |
|
116 | # unfiltered property cache test | |
111 | print('') |
|
117 | print('') | |
112 | print('') |
|
118 | print('') | |
113 | print('=== unfiltered property cache ===') |
|
119 | print('=== unfiltered property cache ===') | |
114 | print('') |
|
120 | print('') | |
115 | print('unficalllog:', unficalllog) |
|
121 | print('unficalllog:', unficalllog) | |
116 | print('cached value (unfiltered): ', |
|
122 | print('cached value (unfiltered): ', | |
117 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
123 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
118 | print('cached value ("visible" view): ', |
|
124 | print('cached value ("visible" view): ', | |
119 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
125 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
120 | print('cached value ("immutable" view):', |
|
126 | print('cached value ("immutable" view):', | |
121 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
127 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) | |
122 |
|
128 | |||
123 | print('') |
|
129 | print('') | |
124 | print('= first access on unfiltered, should do a call') |
|
130 | print('= first access on unfiltered, should do a call') | |
125 | print('access (unfiltered):', repo.testcachedunfifoobar) |
|
131 | print('access (unfiltered):', repo.testcachedunfifoobar) | |
126 | print('unficalllog:', unficalllog) |
|
132 | print('unficalllog:', unficalllog) | |
127 | print('cached value (unfiltered): ', |
|
133 | print('cached value (unfiltered): ', | |
128 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
134 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
129 |
|
135 | |||
130 | print('') |
|
136 | print('') | |
131 | print('= second access on unfiltered, should not do call') |
|
137 | print('= second access on unfiltered, should not do call') | |
132 | print('access (unfiltered):', repo.testcachedunfifoobar) |
|
138 | print('access (unfiltered):', repo.testcachedunfifoobar) | |
133 | print('unficalllog:', unficalllog) |
|
139 | print('unficalllog:', unficalllog) | |
134 | print('cached value (unfiltered): ', |
|
140 | print('cached value (unfiltered): ', | |
135 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
141 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
136 |
|
142 | |||
137 | print('') |
|
143 | print('') | |
138 | print('= access on view should use the unfiltered cache') |
|
144 | print('= access on view should use the unfiltered cache') | |
139 | print('access (unfiltered): ', repo.testcachedunfifoobar) |
|
145 | print('access (unfiltered): ', repo.testcachedunfifoobar) | |
140 | print('access ("visible" view): ', visibleview.testcachedunfifoobar) |
|
146 | print('access ("visible" view): ', visibleview.testcachedunfifoobar) | |
141 | print('access ("immutable" view):', immutableview.testcachedunfifoobar) |
|
147 | print('access ("immutable" view):', immutableview.testcachedunfifoobar) | |
142 | print('unficalllog:', unficalllog) |
|
148 | print('unficalllog:', unficalllog) | |
143 | print('cached value (unfiltered): ', |
|
149 | print('cached value (unfiltered): ', | |
144 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
150 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
145 | print('cached value ("visible" view): ', |
|
151 | print('cached value ("visible" view): ', | |
146 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
152 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
147 | print('cached value ("immutable" view):', |
|
153 | print('cached value ("immutable" view):', | |
148 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
154 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) | |
149 |
|
155 | |||
150 | print('') |
|
156 | print('') | |
151 | print('= even if we clear the unfiltered cache') |
|
157 | print('= even if we clear the unfiltered cache') | |
152 | del repo.__dict__['testcachedunfifoobar'] |
|
158 | del repo.__dict__['testcachedunfifoobar'] | |
153 | print('cached value (unfiltered): ', |
|
159 | print('cached value (unfiltered): ', | |
154 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
160 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
155 | print('cached value ("visible" view): ', |
|
161 | print('cached value ("visible" view): ', | |
156 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
162 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
157 | print('cached value ("immutable" view):', |
|
163 | print('cached value ("immutable" view):', | |
158 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
164 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) | |
159 | print('unficalllog:', unficalllog) |
|
165 | print('unficalllog:', unficalllog) | |
160 | print('access ("visible" view): ', visibleview.testcachedunfifoobar) |
|
166 | print('access ("visible" view): ', visibleview.testcachedunfifoobar) | |
161 | print('unficalllog:', unficalllog) |
|
167 | print('unficalllog:', unficalllog) | |
162 | print('cached value (unfiltered): ', |
|
168 | print('cached value (unfiltered): ', | |
163 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
169 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
164 | print('cached value ("visible" view): ', |
|
170 | print('cached value ("visible" view): ', | |
165 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
171 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
166 | print('cached value ("immutable" view):', |
|
172 | print('cached value ("immutable" view):', | |
167 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
173 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) | |
168 | print('access ("immutable" view):', immutableview.testcachedunfifoobar) |
|
174 | print('access ("immutable" view):', immutableview.testcachedunfifoobar) | |
169 | print('unficalllog:', unficalllog) |
|
175 | print('unficalllog:', unficalllog) | |
170 | print('cached value (unfiltered): ', |
|
176 | print('cached value (unfiltered): ', | |
171 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
177 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
172 | print('cached value ("visible" view): ', |
|
178 | print('cached value ("visible" view): ', | |
173 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
179 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
174 | print('cached value ("immutable" view):', |
|
180 | print('cached value ("immutable" view):', | |
175 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
181 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) | |
176 | print('access (unfiltered): ', repo.testcachedunfifoobar) |
|
182 | print('access (unfiltered): ', repo.testcachedunfifoobar) | |
177 | print('unficalllog:', unficalllog) |
|
183 | print('unficalllog:', unficalllog) | |
178 | print('cached value (unfiltered): ', |
|
184 | print('cached value (unfiltered): ', | |
179 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) |
|
185 | vars(repo).get('testcachedunfifoobar', 'NOCACHE')) | |
180 | print('cached value ("visible" view): ', |
|
186 | print('cached value ("visible" view): ', | |
181 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) |
|
187 | vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) | |
182 | print('cached value ("immutable" view):', |
|
188 | print('cached value ("immutable" view):', | |
183 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
|
189 | vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) |
General Comments 0
You need to be logged in to leave comments.
Login now