comparison mercurial/lock.py @ 43798:888bd39ed555

lock: pass "success" boolean to _afterlock callbacks This lets the callback decide if it should actually run or not. I suspect that most callbacks (and hooks) *should not* run in this scenario, but I'm trying to not break any existing behavior. `persistmanifestcache`, however, seems actively dangerous to run: we just encountered an exception and the repo is in an unknown state (hopefully a consistent one due to transactions, but this is not 100% guaranteed), and the data we cache may be based on this unknown state. This was observed by our users since we wrap some of the functions that persistmanifestcache calls and it expects that the repo object is in a certain state that we'd set up earlier. If the user hits ctrl-c before we establish that state, we end up crashing there. I'm going to make that extension resilient to this issue, but figured it might be a common issue and should be handled here as well instead of just working around the issue. Differential Revision: https://phab.mercurial-scm.org/D7459
author Kyle Lippincott <spectral@google.com>
date Tue, 19 Nov 2019 18:38:17 -0800
parents 039fbd14d4e2
children 9b16bb3b2349
comparison
equal deleted inserted replaced
43797:c8e9a3636abe 43798:888bd39ed555
231 231
232 def __enter__(self): 232 def __enter__(self):
233 return self 233 return self
234 234
235 def __exit__(self, exc_type, exc_value, exc_tb): 235 def __exit__(self, exc_type, exc_value, exc_tb):
236 self.release() 236 success = all(a is None for a in (exc_type, exc_value, exc_tb))
237 self.release(success=success)
237 238
238 def __del__(self): 239 def __del__(self):
239 if self.held: 240 if self.held:
240 warnings.warn( 241 warnings.warn(
241 "use lock.release instead of del lock", 242 "use lock.release instead of del lock",
406 finally: 407 finally:
407 if self.acquirefn: 408 if self.acquirefn:
408 self.acquirefn() 409 self.acquirefn()
409 self._inherited = False 410 self._inherited = False
410 411
411 def release(self): 412 def release(self, success=True):
412 """release the lock and execute callback function if any 413 """release the lock and execute callback function if any
413 414
414 If the lock has been acquired multiple times, the actual release is 415 If the lock has been acquired multiple times, the actual release is
415 delayed to the last release call.""" 416 delayed to the last release call."""
416 if self.held > 1: 417 if self.held > 1:
431 pass 432 pass
432 # The postrelease functions typically assume the lock is not held 433 # The postrelease functions typically assume the lock is not held
433 # at all. 434 # at all.
434 if not self._parentheld: 435 if not self._parentheld:
435 for callback in self.postrelease: 436 for callback in self.postrelease:
436 callback() 437 callback(success)
437 # Prevent double usage and help clear cycles. 438 # Prevent double usage and help clear cycles.
438 self.postrelease = None 439 self.postrelease = None
439 440
440 441
441 def release(*locks): 442 def release(*locks):