Mercurial > hg
changeset 23281:f60ed8cf4afc
transaction: pass the transaction to 'finalize' callback
The callback will likely need to perform some operation related to the
transaction (eg: registering file update). So we better pass the current
transaction as the callback argument. Otherwise callback that needs it has to
rely on horrible weak reference trick.
This allow already allow us to slay a wild weak reference usage.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sat, 08 Nov 2014 16:31:38 +0000 |
parents | b01c491af0cf |
children | 6c1351352b6c |
files | mercurial/changelog.py mercurial/transaction.py |
diffstat | 2 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Sat Nov 08 16:27:50 2014 +0000 +++ b/mercurial/changelog.py Sat Nov 08 16:31:38 2014 +0000 @@ -5,7 +5,6 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import weakref from node import bin, hex, nullid from i18n import _ import util, error, revlog, encoding @@ -240,8 +239,7 @@ self._delaybuf) self._delayed = True tr.addpending('cl-%i' % id(self), self._writepending) - trp = weakref.proxy(tr) - tr.addfinalize('cl-%i' % id(self), lambda: self._finalize(trp)) + tr.addfinalize('cl-%i' % id(self), self._finalize) def _finalize(self, tr): "finalize index updates"
--- a/mercurial/transaction.py Sat Nov 08 16:27:50 2014 +0000 +++ b/mercurial/transaction.py Sat Nov 08 16:31:38 2014 +0000 @@ -304,6 +304,8 @@ def addfinalize(self, category, callback): """add a callback to be called when the transaction is closed + The transaction will be given as callback's first argument. + Category is a unique identifier to allow overwriting old callbacks with newer callbacks. """ @@ -325,7 +327,7 @@ self._generatefiles() categories = sorted(self._finalizecallback) for cat in categories: - self._finalizecallback[cat]() + self._finalizecallback[cat](self) self.onclose() self.count -= 1