author | Brodie Rao <brodie@sf.io> |
Sat, 12 May 2012 15:54:54 +0200 | |
changeset 16683 | 525fdb738975 |
parent 15518 | d01e08ea459d |
child 16688 | cfb6682961b8 |
permissions | -rw-r--r-- |
14928 | 1 |
import sys, os, subprocess |
2 |
||
16683 | 3 |
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
4 |
'cacheable']): |
|
14928 | 5 |
sys.exit(80) |
6 |
||
7 |
from mercurial import util, scmutil, extensions |
|
8 |
||
9 |
filecache = scmutil.filecache |
|
10 |
||
11 |
class fakerepo(object): |
|
12 |
def __init__(self): |
|
13 |
self._filecache = {} |
|
14 |
||
15 |
def join(self, p): |
|
16 |
return p |
|
17 |
||
18 |
def sjoin(self, p): |
|
19 |
return p |
|
20 |
||
21 |
@filecache('x') |
|
22 |
def cached(self): |
|
23 |
print 'creating' |
|
24 |
||
25 |
def invalidate(self): |
|
26 |
for k in self._filecache: |
|
27 |
try: |
|
28 |
delattr(self, k) |
|
29 |
except AttributeError: |
|
30 |
pass |
|
31 |
||
32 |
def basic(repo): |
|
33 |
# file doesn't exist, calls function |
|
34 |
repo.cached |
|
35 |
||
36 |
repo.invalidate() |
|
37 |
# file still doesn't exist, uses cache |
|
38 |
repo.cached |
|
39 |
||
40 |
# create empty file |
|
41 |
f = open('x', 'w') |
|
42 |
f.close() |
|
43 |
repo.invalidate() |
|
44 |
# should recreate the object |
|
45 |
repo.cached |
|
46 |
||
47 |
f = open('x', 'w') |
|
48 |
f.write('a') |
|
49 |
f.close() |
|
50 |
repo.invalidate() |
|
51 |
# should recreate the object |
|
52 |
repo.cached |
|
53 |
||
54 |
repo.invalidate() |
|
55 |
# stats file again, nothing changed, reuses object |
|
56 |
repo.cached |
|
57 |
||
58 |
# atomic replace file, size doesn't change |
|
59 |
# hopefully st_mtime doesn't change as well so this doesn't use the cache |
|
60 |
# because of inode change |
|
61 |
f = scmutil.opener('.')('x', 'w', atomictemp=True) |
|
62 |
f.write('b') |
|
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
63 |
f.close() |
14928 | 64 |
|
65 |
repo.invalidate() |
|
66 |
repo.cached |
|
67 |
||
68 |
def fakeuncacheable(): |
|
69 |
def wrapcacheable(orig, *args, **kwargs): |
|
70 |
return False |
|
71 |
||
72 |
def wrapinit(orig, *args, **kwargs): |
|
73 |
pass |
|
74 |
||
75 |
originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) |
|
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
76 |
origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
77 |
wrapcacheable) |
14928 | 78 |
|
79 |
try: |
|
80 |
os.remove('x') |
|
81 |
except: |
|
82 |
pass |
|
83 |
||
84 |
basic(fakerepo()) |
|
85 |
||
86 |
util.cachestat.cacheable = origcacheable |
|
87 |
util.cachestat.__init__ = originit |
|
88 |
||
89 |
print 'basic:' |
|
90 |
||
91 |
basic(fakerepo()) |
|
92 |
||
93 |
print 'fakeuncacheable:' |
|
94 |
||
95 |
fakeuncacheable() |