author | Siddharth Agarwal <sid0@fb.com> |
Wed, 19 Jun 2013 22:34:34 -0700 | |
branch | stable |
changeset 19317 | 66da6e9feacd |
parent 18316 | f36375576ed5 |
child 20040 | ed80cecdfc57 |
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 |
||
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
7 |
from mercurial import util, scmutil, extensions, hg, ui |
14928 | 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') |
|
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
81 |
except OSError: |
14928 | 82 |
pass |
83 |
||
84 |
basic(fakerepo()) |
|
85 |
||
86 |
util.cachestat.cacheable = origcacheable |
|
87 |
util.cachestat.__init__ = originit |
|
88 |
||
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
89 |
def test_filecache_synced(): |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
90 |
# test old behaviour that caused filecached properties to go out of sync |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
91 |
os.system('hg init && echo a >> a && hg ci -qAm.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
92 |
repo = hg.repository(ui.ui()) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
93 |
# first rollback clears the filecache, but changelog to stays in __dict__ |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
94 |
repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
95 |
repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
96 |
# second rollback comes along and touches the changelog externally |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
97 |
# (file is moved) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
98 |
repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
99 |
# but since changelog isn't under the filecache control anymore, we don't |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
100 |
# see that it changed, and return the old changelog without reconstructing |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
101 |
# it |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
102 |
repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
103 |
|
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
104 |
def setbeforeget(repo): |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
105 |
os.remove('x') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
106 |
repo.cached = 0 |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
107 |
repo.invalidate() |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
108 |
print repo.cached |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
109 |
repo.invalidate() |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
110 |
f = open('x', 'w') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
111 |
f.write('a') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
112 |
f.close() |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
113 |
print repo.cached |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
114 |
|
14928 | 115 |
print 'basic:' |
116 |
||
117 |
basic(fakerepo()) |
|
118 |
||
119 |
print 'fakeuncacheable:' |
|
120 |
||
121 |
fakeuncacheable() |
|
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
122 |
test_filecache_synced() |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
123 |
|
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
124 |
print 'setbeforeget:' |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
125 |
|
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
126 |
setbeforeget(fakerepo()) |