changeset 23280:b01c491af0cf

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 08 Nov 2014 16:27:50 +0000
parents e245775f8fd3
children f60ed8cf4afc
files mercurial/changelog.py mercurial/transaction.py
diffstat 2 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Wed Nov 05 10:22:17 2014 +0000
+++ b/mercurial/changelog.py	Sat Nov 08 16:27:50 2014 +0000
@@ -270,7 +270,7 @@
         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
--- a/mercurial/transaction.py	Wed Nov 05 10:22:17 2014 +0000
+++ b/mercurial/transaction.py	Sat Nov 08 16:27:50 2014 +0000
@@ -281,6 +281,8 @@
     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 @@
         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