# HG changeset patch # User FUJIWARA Katsunori # Date 1444330426 -32400 # Node ID 9e0aaac0d9ebe681430bc081b7527dcae06084b4 # Parent d60815664c34d6bbe4be7863d3b78134d277abff transaction: add releasefn to notify the end of a transaction scope 'releasefn' is used by subsequent patch, to do appropriate action according to the result of it at the end of a transaction scope. To ensure that 'releasefn' is invoked only once, this patch invokes it after assignment 'self.journal = None', because such assignment prevents from invoked 'transaction._abort()' again via '__del__()'. def __del__(self): if self.journal: self._abort() diff -r d60815664c34 -r 9e0aaac0d9eb mercurial/transaction.py --- a/mercurial/transaction.py Wed Oct 07 23:35:30 2015 -0700 +++ b/mercurial/transaction.py Fri Oct 09 03:53:46 2015 +0900 @@ -89,7 +89,7 @@ class transaction(object): def __init__(self, report, opener, vfsmap, journalname, undoname=None, - after=None, createmode=None, validator=None): + after=None, createmode=None, validator=None, releasefn=None): """Begin a new transaction Begins a new transaction that allows rolling back writes in the event of @@ -97,6 +97,7 @@ * `after`: called after the transaction has been committed * `createmode`: the mode of the journal file that will be created + * `releasefn`: called after releasing (with transaction and result) """ self.count = 1 self.usages = 1 @@ -119,6 +120,11 @@ if validator is None: validator = lambda tr: None self.validator = validator + # A callback to do something just after releasing transaction. + if releasefn is None: + releasefn = lambda tr, success: None + self.releasefn = releasefn + # a dict of arguments to be passed to hooks self.hookargs = {} self.file = opener.open(self.journal, "w") @@ -442,6 +448,9 @@ % (vfs.join(b), inst)) self._backupentries = [] self.journal = None + + self.releasefn(self, True) # notify success of closing transaction + # run post close action categories = sorted(self._postclosecallback) for cat in categories: @@ -506,7 +515,7 @@ self.report(_("rollback failed - please run hg recover\n")) finally: self.journal = None - + self.releasefn(self, False) # notify failure of transaction def rollback(opener, vfsmap, file, report): """Rolls back the transaction contained in the given file