diff mercurial/exchange.py @ 33793:bbbbd3c30bfc

util: add base class for transactional context managers We have at least three types with a close() and a release() method where the close() method is supposed to be called on success and the release() method is supposed to be called last, whether successful or not. Two of them (transaction and dirstateguard) already have identical implementations of __enter__ and __exit__. Let's extract a base class for this, so we reuse the code and so the third type (transactionmanager) can also be used as a context manager. Differential Revision: https://phab.mercurial-scm.org/D392
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 28 Jul 2017 22:42:10 -0700
parents 5904511fc9f8
children 389f7b17ffb3
line wrap: on
line diff
--- a/mercurial/exchange.py	Mon Aug 14 16:26:36 2017 -0700
+++ b/mercurial/exchange.py	Fri Jul 28 22:42:10 2017 -0700
@@ -1168,7 +1168,7 @@
         # deprecated; talk to trmanager directly
         return self.trmanager.transaction()
 
-class transactionmanager(object):
+class transactionmanager(util.transactional):
     """An object to manage the life cycle of a transaction
 
     It creates the transaction on demand and calls the appropriate hooks when