Show More
@@ -1,95 +1,96 b'' | |||||
1 | import sys, os, subprocess |
|
1 | import sys, os, subprocess | |
2 |
|
2 | |||
3 | try: |
|
3 | try: | |
4 | subprocess.check_call(['%s/hghave' % os.environ['TESTDIR'], 'cacheable']) |
|
4 | subprocess.check_call(['%s/hghave' % os.environ['TESTDIR'], 'cacheable']) | |
5 | except subprocess.CalledProcessError: |
|
5 | except subprocess.CalledProcessError: | |
6 | sys.exit(80) |
|
6 | sys.exit(80) | |
7 |
|
7 | |||
8 | from mercurial import util, scmutil, extensions |
|
8 | from mercurial import util, scmutil, extensions | |
9 |
|
9 | |||
10 | filecache = scmutil.filecache |
|
10 | filecache = scmutil.filecache | |
11 |
|
11 | |||
12 | class fakerepo(object): |
|
12 | class fakerepo(object): | |
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 | self._filecache = {} |
|
14 | self._filecache = {} | |
15 |
|
15 | |||
16 | def join(self, p): |
|
16 | def join(self, p): | |
17 | return p |
|
17 | return p | |
18 |
|
18 | |||
19 | def sjoin(self, p): |
|
19 | def sjoin(self, p): | |
20 | return p |
|
20 | return p | |
21 |
|
21 | |||
22 | @filecache('x') |
|
22 | @filecache('x') | |
23 | def cached(self): |
|
23 | def cached(self): | |
24 | print 'creating' |
|
24 | print 'creating' | |
25 |
|
25 | |||
26 | def invalidate(self): |
|
26 | def invalidate(self): | |
27 | for k in self._filecache: |
|
27 | for k in self._filecache: | |
28 | try: |
|
28 | try: | |
29 | delattr(self, k) |
|
29 | delattr(self, k) | |
30 | except AttributeError: |
|
30 | except AttributeError: | |
31 | pass |
|
31 | pass | |
32 |
|
32 | |||
33 | def basic(repo): |
|
33 | def basic(repo): | |
34 | # file doesn't exist, calls function |
|
34 | # file doesn't exist, calls function | |
35 | repo.cached |
|
35 | repo.cached | |
36 |
|
36 | |||
37 | repo.invalidate() |
|
37 | repo.invalidate() | |
38 | # file still doesn't exist, uses cache |
|
38 | # file still doesn't exist, uses cache | |
39 | repo.cached |
|
39 | repo.cached | |
40 |
|
40 | |||
41 | # create empty file |
|
41 | # create empty file | |
42 | f = open('x', 'w') |
|
42 | f = open('x', 'w') | |
43 | f.close() |
|
43 | f.close() | |
44 | repo.invalidate() |
|
44 | repo.invalidate() | |
45 | # should recreate the object |
|
45 | # should recreate the object | |
46 | repo.cached |
|
46 | repo.cached | |
47 |
|
47 | |||
48 | f = open('x', 'w') |
|
48 | f = open('x', 'w') | |
49 | f.write('a') |
|
49 | f.write('a') | |
50 | f.close() |
|
50 | f.close() | |
51 | repo.invalidate() |
|
51 | repo.invalidate() | |
52 | # should recreate the object |
|
52 | # should recreate the object | |
53 | repo.cached |
|
53 | repo.cached | |
54 |
|
54 | |||
55 | repo.invalidate() |
|
55 | repo.invalidate() | |
56 | # stats file again, nothing changed, reuses object |
|
56 | # stats file again, nothing changed, reuses object | |
57 | repo.cached |
|
57 | repo.cached | |
58 |
|
58 | |||
59 | # atomic replace file, size doesn't change |
|
59 | # atomic replace file, size doesn't change | |
60 | # hopefully st_mtime doesn't change as well so this doesn't use the cache |
|
60 | # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
61 | # because of inode change |
|
61 | # because of inode change | |
62 | f = scmutil.opener('.')('x', 'w', atomictemp=True) |
|
62 | f = scmutil.opener('.')('x', 'w', atomictemp=True) | |
63 | f.write('b') |
|
63 | f.write('b') | |
64 | f.rename() |
|
64 | f.rename() | |
65 |
|
65 | |||
66 | repo.invalidate() |
|
66 | repo.invalidate() | |
67 | repo.cached |
|
67 | repo.cached | |
68 |
|
68 | |||
69 | def fakeuncacheable(): |
|
69 | def fakeuncacheable(): | |
70 | def wrapcacheable(orig, *args, **kwargs): |
|
70 | def wrapcacheable(orig, *args, **kwargs): | |
71 | return False |
|
71 | return False | |
72 |
|
72 | |||
73 | def wrapinit(orig, *args, **kwargs): |
|
73 | def wrapinit(orig, *args, **kwargs): | |
74 | pass |
|
74 | pass | |
75 |
|
75 | |||
76 | originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) |
|
76 | originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
77 |
origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
|
77 | origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', | |
|
78 | wrapcacheable) | |||
78 |
|
79 | |||
79 | try: |
|
80 | try: | |
80 | os.remove('x') |
|
81 | os.remove('x') | |
81 | except: |
|
82 | except: | |
82 | pass |
|
83 | pass | |
83 |
|
84 | |||
84 | basic(fakerepo()) |
|
85 | basic(fakerepo()) | |
85 |
|
86 | |||
86 | util.cachestat.cacheable = origcacheable |
|
87 | util.cachestat.cacheable = origcacheable | |
87 | util.cachestat.__init__ = originit |
|
88 | util.cachestat.__init__ = originit | |
88 |
|
89 | |||
89 | print 'basic:' |
|
90 | print 'basic:' | |
90 |
|
91 | |||
91 | basic(fakerepo()) |
|
92 | basic(fakerepo()) | |
92 |
|
93 | |||
93 | print 'fakeuncacheable:' |
|
94 | print 'fakeuncacheable:' | |
94 |
|
95 | |||
95 | fakeuncacheable() |
|
96 | fakeuncacheable() |
General Comments 0
You need to be logged in to leave comments.
Login now