# HG changeset patch # User Pierre-Yves David # Date 2014-11-08 16:27:50 # Node ID b01c491af0cf7816f691d4f86a2f50261ac20309 # Parent e245775f8fd30ef49f0026048605965f93194599 transaction: pass the transaction to 'pending' callback The callback will likely need to perform some operation related to the transaction (eg: backing files up). So we better pass the current transaction as the callback argument. Otherwise callback that needs it has to rely on horrible weak reference trick. The first foreseen user of this is changelog._writepending. We would like it to register the temporary file it create for cleanup purpose. diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -270,7 +270,7 @@ class changelog(revlog.revlog): self._nodecache = r._nodecache self._chunkcache = r._chunkcache - def _writepending(self): + def _writepending(self, tr): "create a file containing the unfinalized state for pretxnchangegroup" if self._delaybuf: # make a temporary copy of the index diff --git a/mercurial/transaction.py b/mercurial/transaction.py --- a/mercurial/transaction.py +++ b/mercurial/transaction.py @@ -281,6 +281,8 @@ class transaction(object): def addpending(self, category, callback): """add a callback to be called when the transaction is pending + The transaction will be given as callback's first argument. + Category is a unique identifier to allow overwriting an old callback with a newer callback. """ @@ -294,7 +296,7 @@ class transaction(object): categories = sorted(self._pendingcallback) for cat in categories: # remove callback since the data will have been flushed - any = self._pendingcallback.pop(cat)() + any = self._pendingcallback.pop(cat)(self) self._anypending = self._anypending or any return self._anypending