Patchwork [4,of,7,main-line-of-work] transaction: pass the transaction to 'pending' callback

mail settings
Submitter Pierre-Yves David
Date Nov. 11, 2014, 5:35 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/6677/
State Accepted
Commit b01c491af0cf7816f691d4f86a2f50261ac20309
Headers show


Pierre-Yves David - Nov. 11, 2014, 5:35 p.m.
# HG changeset patch
# User Pierre-Yves David <>
# Date 1415464070 0
#      Sat Nov 08 16:27:50 2014 +0000
# Node ID 0655518980f77b00f74ee2a13fecd0ce5273dfd4
# Parent  f82d02b7ff612b2c00e531832d776e60f2392714
transaction: pass the transaction to 'pending' callback

The callback will likely needs 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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -268,11 +268,11 @@  class changelog(revlog.revlog):
         self.index = r.index
         self.nodemap = r.nodemap
         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
             fp1 = self._realopener(self.indexfile)
             fp2 = self._realopener(self.indexfile + ".a", "w")
diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -279,10 +279,12 @@  class transaction(object):
         return self.count > 0
     def addpending(self, category, callback):
         """add a callback to be called when the transaction is pending
+        The transaction will be given as callback first argument.
         Category is a unique identifier to allow overwriting an old callback
         with a newer callback.
         self._pendingcallback[category] = callback
@@ -292,11 +294,11 @@  class transaction(object):
         This is used to allow hooks to view a transaction before commit'''
         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
     def addfinalize(self, category, callback):