comparison mercurial/localrepo.py @ 26250:bc1f8a79b4e4

localrepo: move closure of lock release to class It only captures "self", so it isn't necessary to be created dynamically.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 15 Sep 2015 21:00:28 +0900
parents 51a30cae2bff
children 5c0f5db65c6b
comparison
equal deleted inserted replaced
26249:3166bcc0c538 26250:bc1f8a79b4e4
1196 subsequent operation to reread any outside changes.''' 1196 subsequent operation to reread any outside changes.'''
1197 # extension should hook this to invalidate its caches 1197 # extension should hook this to invalidate its caches
1198 self.invalidate() 1198 self.invalidate()
1199 self.invalidatedirstate() 1199 self.invalidatedirstate()
1200 1200
1201 def _refreshfilecachestats(self):
1202 """Reload stats of cached files so that they are flagged as valid"""
1203 for k, ce in self._filecache.items():
1204 if k == 'dirstate' or k not in self.__dict__:
1205 continue
1206 ce.refresh()
1207
1201 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc): 1208 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc):
1202 try: 1209 try:
1203 l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc) 1210 l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc)
1204 except error.LockHeld as inst: 1211 except error.LockHeld as inst:
1205 if not wait: 1212 if not wait:
1238 l = self._lockref and self._lockref() 1245 l = self._lockref and self._lockref()
1239 if l is not None and l.held: 1246 if l is not None and l.held:
1240 l.lock() 1247 l.lock()
1241 return l 1248 return l
1242 1249
1243 def unlock(): 1250 l = self._lock(self.svfs, "lock", wait, self._refreshfilecachestats,
1244 for k, ce in self._filecache.items():
1245 if k == 'dirstate' or k not in self.__dict__:
1246 continue
1247 ce.refresh()
1248
1249 l = self._lock(self.svfs, "lock", wait, unlock,
1250 self.invalidate, _('repository %s') % self.origroot) 1251 self.invalidate, _('repository %s') % self.origroot)
1251 self._lockref = weakref.ref(l) 1252 self._lockref = weakref.ref(l)
1252 return l 1253 return l
1253 1254
1254 def wlock(self, wait=True): 1255 def wlock(self, wait=True):