##// END OF EJS Templates
filecache: unimplement __set__() and __delete__() (API)...
Yuya Nishihara -
r40775:7caf632e default
parent child Browse files
Show More
@@ -317,7 +317,7 b' class dirstate(object):'
317 317 return copies
318 318
319 319 def setbranch(self, branch):
320 self._branch = encoding.fromlocal(branch)
320 self.__class__._branch.set(self, encoding.fromlocal(branch))
321 321 f = self._opener('branch', 'w', atomictemp=True, checkambig=True)
322 322 try:
323 323 f.write(self._branch + '\n')
@@ -91,17 +91,16 b' class _basefilecache(scmutil.filecache):'
91 91 def __get__(self, repo, type=None):
92 92 if repo is None:
93 93 return self
94 # inlined the fast path as the cost of function call matters
94 # proxy to unfiltered __dict__ since filtered repo has no entry
95 95 unfi = repo.unfiltered()
96 96 try:
97 97 return unfi.__dict__[self.sname]
98 98 except KeyError:
99 99 pass
100 100 return super(_basefilecache, self).__get__(unfi, type)
101 def __set__(self, repo, value):
102 return super(_basefilecache, self).__set__(repo.unfiltered(), value)
103 def __delete__(self, repo):
104 return super(_basefilecache, self).__delete__(repo.unfiltered())
101
102 def set(self, repo, value):
103 return super(_basefilecache, self).set(repo.unfiltered(), value)
105 104
106 105 class repofilecache(_basefilecache):
107 106 """filecache for files in .hg but outside of .hg/store"""
@@ -1249,16 +1249,15 b' class filecache(object):'
1249 1249 results cached. The decorated function is called. The results are stashed
1250 1250 away in a ``_filecache`` dict on the object whose method is decorated.
1251 1251
1252 On subsequent access, the cached result is returned.
1253
1254 On external property set operations, stat() calls are performed and the new
1255 value is cached.
1252 On subsequent access, the cached result is used as it is set to the
1253 instance dictionary.
1256 1254
1257 On property delete operations, cached data is removed.
1255 On external property set/delete operations, the caller must update the
1256 corresponding _filecache entry appropriately. Use __class__.<attr>.set()
1257 instead of directly setting <attr>.
1258 1258
1259 When using the property API, cached data is always returned, if available:
1260 no stat() is performed to check if the file has changed and if the function
1261 needs to be called to reflect file changes.
1259 When using the property API, the cached data is always used if available.
1260 No stat() is performed to check if the file has changed.
1262 1261
1263 1262 Others can muck about with the state of the ``_filecache`` dict. e.g. they
1264 1263 can populate an entry before the property's getter is called. In this case,
@@ -1291,11 +1290,8 b' class filecache(object):'
1291 1290 # if accessed on the class, return the descriptor itself.
1292 1291 if obj is None:
1293 1292 return self
1294 # do we need to check if the file changed?
1295 try:
1296 return obj.__dict__[self.sname]
1297 except KeyError:
1298 pass
1293
1294 assert self.sname not in obj.__dict__
1299 1295
1300 1296 entry = obj._filecache.get(self.name)
1301 1297
@@ -1315,7 +1311,10 b' class filecache(object):'
1315 1311 obj.__dict__[self.sname] = entry.obj
1316 1312 return entry.obj
1317 1313
1318 def __set__(self, obj, value):
1314 # don't implement __set__(), which would make __dict__ lookup as slow as
1315 # function call.
1316
1317 def set(self, obj, value):
1319 1318 if self.name not in obj._filecache:
1320 1319 # we add an entry for the missing value because X in __dict__
1321 1320 # implies X in _filecache
@@ -1328,12 +1327,6 b' class filecache(object):'
1328 1327 ce.obj = value # update cached copy
1329 1328 obj.__dict__[self.sname] = value # update copy returned by obj.x
1330 1329
1331 def __delete__(self, obj):
1332 try:
1333 del obj.__dict__[self.sname]
1334 except KeyError:
1335 raise AttributeError(self.sname)
1336
1337 1330 def extdatasource(repo, source):
1338 1331 """Gather a map of rev -> value dict from the specified source
1339 1332
@@ -177,7 +177,7 b' def test_filecache_synced():'
177 177 def setbeforeget(repo):
178 178 os.remove('x')
179 179 os.remove('y')
180 repo.cached = 'string set externally'
180 repo.__class__.cached.set(repo, 'string set externally')
181 181 repo.invalidate()
182 182 print("* neither file exists")
183 183 print(repo.cached)
@@ -188,7 +188,7 b' def setbeforeget(repo):'
188 188 print("* file x created")
189 189 print(repo.cached)
190 190
191 repo.cached = 'string 2 set externally'
191 repo.__class__.cached.set(repo, 'string 2 set externally')
192 192 repo.invalidate()
193 193 print("* string set externally again")
194 194 print(repo.cached)
General Comments 0
You need to be logged in to leave comments. Login now