From patchwork Tue Dec 9 01:26:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3,of,4] transaction: remove the redundant 'onclose' mechanism From: Pierre-Yves David X-Patchwork-Id: 7025 Message-Id: <6187b0dbeaf5ce313b6d.1418088374@marginatus.alto.octopoid.net> To: mercurial-devel@selenic.com Cc: Pierre-Yves David Date: Mon, 08 Dec 2014 17:26:14 -0800 # HG changeset patch # User Pierre-Yves David # Date 1417729901 28800 # Thu Dec 04 13:51:41 2014 -0800 # Node ID 6187b0dbeaf5ce313b6dae85f1f01c3ec67e866f # Parent 4e336e79c48b48dda748198dde5a66ecc56edd2a transaction: remove the redundant 'onclose' mechanism It is superseded by the 'addfinalize' function and all its user have been migrated. diff --git a/mercurial/transaction.py b/mercurial/transaction.py --- a/mercurial/transaction.py +++ b/mercurial/transaction.py @@ -82,20 +82,18 @@ def _playback(journal, report, opener, v # only pure backup file remains, it is sage to ignore any error pass class transaction(object): def __init__(self, report, opener, vfsmap, journal, after=None, - createmode=None, onclose=None, onabort=None): + createmode=None, onabort=None): """Begin a new transaction Begins a new transaction that allows rolling back writes in the event of an exception. * `after`: called after the transaction has been committed * `createmode`: the mode of the journal file that will be created - * `onclose`: called as the transaction is closing, but before it is - closed * `onabort`: called as the transaction is aborting, but before any files have been truncated """ self.count = 1 self.usages = 1 @@ -105,11 +103,10 @@ class transaction(object): # a map to access file in various {location -> vfs} vfsmap = vfsmap.copy() vfsmap[''] = opener # set default value self._vfsmap = vfsmap self.after = after - self.onclose = onclose self.onabort = onabort self.entries = [] self.map = {} self.journal = journal self._queue = [] @@ -373,12 +370,10 @@ class transaction(object): if self.count == 1: self._generatefiles() categories = sorted(self._finalizecallback) for cat in categories: self._finalizecallback[cat](self) - if self.onclose is not None: - self.onclose() self.count -= 1 if self.count != 0: return self.file.close() diff --git a/tests/test-fncache.t b/tests/test-fncache.t --- a/tests/test-fncache.t +++ b/tests/test-fncache.t @@ -239,26 +239,26 @@ Aborting transaction prevents fncache ch Aborted transactions can be recovered later $ cat > ../exceptionext.py < import os - > from mercurial import commands, util, transaction + > from mercurial import commands, util, transaction, localrepo > from mercurial.extensions import wrapfunction > - > def closewrapper(orig, self, *args, **kwargs): - > origonclose = self.onclose - > def onclose(): - > origonclose() + > def trwrapper(orig, self, *args, **kwargs): + > tr = orig(self, *args, **kwargs) + > def fail(tr): > raise util.Abort("forced transaction failure") - > self.onclose = onclose - > return orig(self, *args, **kwargs) + > # zzz prefix to ensure it sorted after store.write + > tr.addfinalize('zzz-forcefails', fail) + > return tr > > def abortwrapper(orig, self, *args, **kwargs): > raise util.Abort("forced transaction failure") > > def uisetup(ui): - > wrapfunction(transaction.transaction, 'close', closewrapper) + > wrapfunction(localrepo.localrepository, 'transaction', trwrapper) > wrapfunction(transaction.transaction, '_abort', abortwrapper) > > cmdtable = {} > > EOF