21 def sjoin(self, p): |
21 def sjoin(self, p): |
22 return p |
22 return p |
23 |
23 |
24 @filecache('x', 'y') |
24 @filecache('x', 'y') |
25 def cached(self): |
25 def cached(self): |
26 print 'creating' |
26 print('creating') |
27 return 'string from function' |
27 return 'string from function' |
28 |
28 |
29 def invalidate(self): |
29 def invalidate(self): |
30 for k in self._filecache: |
30 for k in self._filecache: |
31 try: |
31 try: |
32 delattr(self, k) |
32 delattr(self, k) |
33 except AttributeError: |
33 except AttributeError: |
34 pass |
34 pass |
35 |
35 |
36 def basic(repo): |
36 def basic(repo): |
37 print "* neither file exists" |
37 print("* neither file exists") |
38 # calls function |
38 # calls function |
39 repo.cached |
39 repo.cached |
40 |
40 |
41 repo.invalidate() |
41 repo.invalidate() |
42 print "* neither file still exists" |
42 print("* neither file still exists") |
43 # uses cache |
43 # uses cache |
44 repo.cached |
44 repo.cached |
45 |
45 |
46 # create empty file |
46 # create empty file |
47 f = open('x', 'w') |
47 f = open('x', 'w') |
48 f.close() |
48 f.close() |
49 repo.invalidate() |
49 repo.invalidate() |
50 print "* empty file x created" |
50 print("* empty file x created") |
51 # should recreate the object |
51 # should recreate the object |
52 repo.cached |
52 repo.cached |
53 |
53 |
54 f = open('x', 'w') |
54 f = open('x', 'w') |
55 f.write('a') |
55 f.write('a') |
56 f.close() |
56 f.close() |
57 repo.invalidate() |
57 repo.invalidate() |
58 print "* file x changed size" |
58 print("* file x changed size") |
59 # should recreate the object |
59 # should recreate the object |
60 repo.cached |
60 repo.cached |
61 |
61 |
62 repo.invalidate() |
62 repo.invalidate() |
63 print "* nothing changed with either file" |
63 print("* nothing changed with either file") |
64 # stats file again, reuses object |
64 # stats file again, reuses object |
65 repo.cached |
65 repo.cached |
66 |
66 |
67 # atomic replace file, size doesn't change |
67 # atomic replace file, size doesn't change |
68 # hopefully st_mtime doesn't change as well so this doesn't use the cache |
68 # hopefully st_mtime doesn't change as well so this doesn't use the cache |
70 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
70 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
71 f.write('b') |
71 f.write('b') |
72 f.close() |
72 f.close() |
73 |
73 |
74 repo.invalidate() |
74 repo.invalidate() |
75 print "* file x changed inode" |
75 print("* file x changed inode") |
76 repo.cached |
76 repo.cached |
77 |
77 |
78 # create empty file y |
78 # create empty file y |
79 f = open('y', 'w') |
79 f = open('y', 'w') |
80 f.close() |
80 f.close() |
81 repo.invalidate() |
81 repo.invalidate() |
82 print "* empty file y created" |
82 print("* empty file y created") |
83 # should recreate the object |
83 # should recreate the object |
84 repo.cached |
84 repo.cached |
85 |
85 |
86 f = open('y', 'w') |
86 f = open('y', 'w') |
87 f.write('A') |
87 f.write('A') |
88 f.close() |
88 f.close() |
89 repo.invalidate() |
89 repo.invalidate() |
90 print "* file y changed size" |
90 print("* file y changed size") |
91 # should recreate the object |
91 # should recreate the object |
92 repo.cached |
92 repo.cached |
93 |
93 |
94 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
94 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
95 f.write('B') |
95 f.write('B') |
96 f.close() |
96 f.close() |
97 |
97 |
98 repo.invalidate() |
98 repo.invalidate() |
99 print "* file y changed inode" |
99 print("* file y changed inode") |
100 repo.cached |
100 repo.cached |
101 |
101 |
102 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
102 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
103 f.write('c') |
103 f.write('c') |
104 f.close() |
104 f.close() |
105 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
105 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
106 f.write('C') |
106 f.write('C') |
107 f.close() |
107 f.close() |
108 |
108 |
109 repo.invalidate() |
109 repo.invalidate() |
110 print "* both files changed inode" |
110 print("* both files changed inode") |
111 repo.cached |
111 repo.cached |
112 |
112 |
113 def fakeuncacheable(): |
113 def fakeuncacheable(): |
114 def wrapcacheable(orig, *args, **kwargs): |
114 def wrapcacheable(orig, *args, **kwargs): |
115 return False |
115 return False |
150 def setbeforeget(repo): |
150 def setbeforeget(repo): |
151 os.remove('x') |
151 os.remove('x') |
152 os.remove('y') |
152 os.remove('y') |
153 repo.cached = 'string set externally' |
153 repo.cached = 'string set externally' |
154 repo.invalidate() |
154 repo.invalidate() |
155 print "* neither file exists" |
155 print("* neither file exists") |
156 print repo.cached |
156 print(repo.cached) |
157 repo.invalidate() |
157 repo.invalidate() |
158 f = open('x', 'w') |
158 f = open('x', 'w') |
159 f.write('a') |
159 f.write('a') |
160 f.close() |
160 f.close() |
161 print "* file x created" |
161 print("* file x created") |
162 print repo.cached |
162 print(repo.cached) |
163 |
163 |
164 repo.cached = 'string 2 set externally' |
164 repo.cached = 'string 2 set externally' |
165 repo.invalidate() |
165 repo.invalidate() |
166 print "* string set externally again" |
166 print("* string set externally again") |
167 print repo.cached |
167 print(repo.cached) |
168 |
168 |
169 repo.invalidate() |
169 repo.invalidate() |
170 f = open('y', 'w') |
170 f = open('y', 'w') |
171 f.write('b') |
171 f.write('b') |
172 f.close() |
172 f.close() |
173 print "* file y created" |
173 print("* file y created") |
174 print repo.cached |
174 print(repo.cached) |
175 |
175 |
176 print 'basic:' |
176 print('basic:') |
177 print |
177 print() |
178 basic(fakerepo()) |
178 basic(fakerepo()) |
179 print |
179 print() |
180 print 'fakeuncacheable:' |
180 print('fakeuncacheable:') |
181 print |
181 print() |
182 fakeuncacheable() |
182 fakeuncacheable() |
183 test_filecache_synced() |
183 test_filecache_synced() |
184 print |
184 print() |
185 print 'setbeforeget:' |
185 print('setbeforeget:') |
186 print |
186 print() |
187 setbeforeget(fakerepo()) |
187 setbeforeget(fakerepo()) |