| 1 |
"""test behavior of propertycache and unfiltered propertycache |
| 2 |
|
| 3 |
The repoview overlay is quite complex. We test the behavior of |
| 4 |
property cache of both localrepo and repoview to prevent |
| 5 |
regression.""" |
| 6 |
|
| 7 |
import os |
| 8 |
import subprocess |
| 9 |
|
| 10 |
from mercurial import ( |
| 11 |
localrepo, |
| 12 |
pycompat, |
| 13 |
ui as uimod, |
| 14 |
util, |
| 15 |
) |
| 16 |
|
| 17 |
from mercurial.utils import procutil |
| 18 |
from mercurial.repo import factory |
| 19 |
|
| 20 |
# create some special property cache that trace they call |
| 21 |
|
| 22 |
calllog = [] |
| 23 |
|
| 24 |
|
| 25 |
@util.propertycache |
| 26 |
def testcachedfoobar(repo): |
| 27 |
name = repo.filtername |
| 28 |
if name is None: |
| 29 |
name = '' |
| 30 |
val = len(name) |
| 31 |
calllog.append(val) |
| 32 |
return val |
| 33 |
|
| 34 |
|
| 35 |
unficalllog = [] |
| 36 |
|
| 37 |
|
| 38 |
@localrepo.unfilteredpropertycache |
| 39 |
def testcachedunfifoobar(repo): |
| 40 |
name = repo.filtername |
| 41 |
if name is None: |
| 42 |
name = '' |
| 43 |
val = 100 + len(name) |
| 44 |
unficalllog.append(val) |
| 45 |
return val |
| 46 |
|
| 47 |
|
| 48 |
# plug them on repo |
| 49 |
localrepo.localrepository.testcachedfoobar = testcachedfoobar |
| 50 |
localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar |
| 51 |
|
| 52 |
|
| 53 |
# Create an empty repo and instantiate it. It is important to run |
| 54 |
# these tests on the real object to detect regression. |
| 55 |
repopath = pycompat.fsencode(os.path.join(os.environ['TESTTMP'], 'repo')) |
| 56 |
assert ( |
| 57 |
subprocess.call( |
| 58 |
pycompat.rapply(procutil.tonativestr, [b'hg', b'init', repopath]) |
| 59 |
) |
| 60 |
== 0 |
| 61 |
) |
| 62 |
|
| 63 |
ui = uimod.ui.load() |
| 64 |
repo = factory.repository(ui, path=repopath).unfiltered() |
| 65 |
|
| 66 |
|
| 67 |
print('') |
| 68 |
print('=== property cache ===') |
| 69 |
print('') |
| 70 |
print('calllog:', calllog) |
| 71 |
print( |
| 72 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 73 |
) |
| 74 |
|
| 75 |
print('') |
| 76 |
print('= first access on unfiltered, should do a call') |
| 77 |
print('access:', repo.testcachedfoobar) |
| 78 |
print('calllog:', calllog) |
| 79 |
print( |
| 80 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 81 |
) |
| 82 |
|
| 83 |
print('') |
| 84 |
print('= second access on unfiltered, should not do call') |
| 85 |
print('access', repo.testcachedfoobar) |
| 86 |
print('calllog:', calllog) |
| 87 |
print( |
| 88 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 89 |
) |
| 90 |
|
| 91 |
print('') |
| 92 |
print('= first access on "visible" view, should do a call') |
| 93 |
visibleview = repo.filtered('visible') |
| 94 |
print( |
| 95 |
'cached value ("visible" view):', |
| 96 |
vars(visibleview).get('testcachedfoobar', 'NOCACHE'), |
| 97 |
) |
| 98 |
print('access:', visibleview.testcachedfoobar) |
| 99 |
print('calllog:', calllog) |
| 100 |
print( |
| 101 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 102 |
) |
| 103 |
print( |
| 104 |
'cached value ("visible" view):', |
| 105 |
vars(visibleview).get('testcachedfoobar', 'NOCACHE'), |
| 106 |
) |
| 107 |
|
| 108 |
print('') |
| 109 |
print('= second access on "visible view", should not do call') |
| 110 |
print('access:', visibleview.testcachedfoobar) |
| 111 |
print('calllog:', calllog) |
| 112 |
print( |
| 113 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 114 |
) |
| 115 |
print( |
| 116 |
'cached value ("visible" view):', |
| 117 |
vars(visibleview).get('testcachedfoobar', 'NOCACHE'), |
| 118 |
) |
| 119 |
|
| 120 |
print('') |
| 121 |
print('= no effect on other view') |
| 122 |
immutableview = repo.filtered('immutable') |
| 123 |
print( |
| 124 |
'cached value ("immutable" view):', |
| 125 |
vars(immutableview).get('testcachedfoobar', 'NOCACHE'), |
| 126 |
) |
| 127 |
print('access:', immutableview.testcachedfoobar) |
| 128 |
print('calllog:', calllog) |
| 129 |
print( |
| 130 |
'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE') |
| 131 |
) |
| 132 |
print( |
| 133 |
'cached value ("visible" view):', |
| 134 |
vars(visibleview).get('testcachedfoobar', 'NOCACHE'), |
| 135 |
) |
| 136 |
print( |
| 137 |
'cached value ("immutable" view):', |
| 138 |
vars(immutableview).get('testcachedfoobar', 'NOCACHE'), |
| 139 |
) |
| 140 |
|
| 141 |
# unfiltered property cache test |
| 142 |
print('') |
| 143 |
print('') |
| 144 |
print('=== unfiltered property cache ===') |
| 145 |
print('') |
| 146 |
print('unficalllog:', unficalllog) |
| 147 |
print( |
| 148 |
'cached value (unfiltered): ', |
| 149 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 150 |
) |
| 151 |
print( |
| 152 |
'cached value ("visible" view): ', |
| 153 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 154 |
) |
| 155 |
print( |
| 156 |
'cached value ("immutable" view):', |
| 157 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 158 |
) |
| 159 |
|
| 160 |
print('') |
| 161 |
print('= first access on unfiltered, should do a call') |
| 162 |
print('access (unfiltered):', repo.testcachedunfifoobar) |
| 163 |
print('unficalllog:', unficalllog) |
| 164 |
print( |
| 165 |
'cached value (unfiltered): ', |
| 166 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 167 |
) |
| 168 |
|
| 169 |
print('') |
| 170 |
print('= second access on unfiltered, should not do call') |
| 171 |
print('access (unfiltered):', repo.testcachedunfifoobar) |
| 172 |
print('unficalllog:', unficalllog) |
| 173 |
print( |
| 174 |
'cached value (unfiltered): ', |
| 175 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 176 |
) |
| 177 |
|
| 178 |
print('') |
| 179 |
print('= access on view should use the unfiltered cache') |
| 180 |
print('access (unfiltered): ', repo.testcachedunfifoobar) |
| 181 |
print('access ("visible" view): ', visibleview.testcachedunfifoobar) |
| 182 |
print('access ("immutable" view):', immutableview.testcachedunfifoobar) |
| 183 |
print('unficalllog:', unficalllog) |
| 184 |
print( |
| 185 |
'cached value (unfiltered): ', |
| 186 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 187 |
) |
| 188 |
print( |
| 189 |
'cached value ("visible" view): ', |
| 190 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 191 |
) |
| 192 |
print( |
| 193 |
'cached value ("immutable" view):', |
| 194 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 195 |
) |
| 196 |
|
| 197 |
print('') |
| 198 |
print('= even if we clear the unfiltered cache') |
| 199 |
del repo.__dict__['testcachedunfifoobar'] |
| 200 |
print( |
| 201 |
'cached value (unfiltered): ', |
| 202 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 203 |
) |
| 204 |
print( |
| 205 |
'cached value ("visible" view): ', |
| 206 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 207 |
) |
| 208 |
print( |
| 209 |
'cached value ("immutable" view):', |
| 210 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 211 |
) |
| 212 |
print('unficalllog:', unficalllog) |
| 213 |
print('access ("visible" view): ', visibleview.testcachedunfifoobar) |
| 214 |
print('unficalllog:', unficalllog) |
| 215 |
print( |
| 216 |
'cached value (unfiltered): ', |
| 217 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 218 |
) |
| 219 |
print( |
| 220 |
'cached value ("visible" view): ', |
| 221 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 222 |
) |
| 223 |
print( |
| 224 |
'cached value ("immutable" view):', |
| 225 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 226 |
) |
| 227 |
print('access ("immutable" view):', immutableview.testcachedunfifoobar) |
| 228 |
print('unficalllog:', unficalllog) |
| 229 |
print( |
| 230 |
'cached value (unfiltered): ', |
| 231 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 232 |
) |
| 233 |
print( |
| 234 |
'cached value ("visible" view): ', |
| 235 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 236 |
) |
| 237 |
print( |
| 238 |
'cached value ("immutable" view):', |
| 239 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 240 |
) |
| 241 |
print('access (unfiltered): ', repo.testcachedunfifoobar) |
| 242 |
print('unficalllog:', unficalllog) |
| 243 |
print( |
| 244 |
'cached value (unfiltered): ', |
| 245 |
vars(repo).get('testcachedunfifoobar', 'NOCACHE'), |
| 246 |
) |
| 247 |
print( |
| 248 |
'cached value ("visible" view): ', |
| 249 |
vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'), |
| 250 |
) |
| 251 |
print( |
| 252 |
'cached value ("immutable" view):', |
| 253 |
vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'), |
| 254 |
) |