comparison mercurial/lock.py @ 28959:518c3e392f75

lock: clear postrelease hooks list after usage Post release hooks should only be called once. Setting the list to None after usage will prevent accidental usage after they are used. In addition, it is easy for reference cycles to sneak into hook functions. Clearing the hooks after usage helps prevent these cycles.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 16 Apr 2016 09:00:15 -0700
parents 14033c5dd261
children dc9f086c7691
comparison
equal deleted inserted replaced
28958:77e566fe31ec 28959:518c3e392f75
232 # The postrelease functions typically assume the lock is not held 232 # The postrelease functions typically assume the lock is not held
233 # at all. 233 # at all.
234 if not self._parentheld: 234 if not self._parentheld:
235 for callback in self.postrelease: 235 for callback in self.postrelease:
236 callback() 236 callback()
237 # Prevent double usage and help clear cycles.
238 self.postrelease = None
237 239
238 def release(*locks): 240 def release(*locks):
239 for lock in locks: 241 for lock in locks:
240 if lock is not None: 242 if lock is not None:
241 lock.release() 243 lock.release()