mercurial/transaction.py
changeset 23204 10beda5bd2b7
parent 23202 ea5af863fbff
child 23220 3f543f6be500
--- a/mercurial/transaction.py	Fri Oct 17 21:55:31 2014 -0700
+++ b/mercurial/transaction.py	Fri Oct 17 22:28:09 2014 -0700
@@ -105,6 +105,8 @@
         self._pendingcallback = {}
         # True is any pending data have been written ever
         self._anypending = False
+        # holds callback to call when writing the transaction
+        self._finalizecallback = {}
 
     def __del__(self):
         if self.journal:
@@ -288,10 +290,22 @@
         return self._anypending
 
     @active
+    def addfinalize(self, category, callback):
+        """add a callback to be called when the transaction is closed
+
+        Category is a unique identifier to allow overwriting old callbacks with
+        newer callbacks.
+        """
+        self._finalizecallback[category] = callback
+
+    @active
     def close(self):
         '''commit the transaction'''
         if self.count == 1 and self.onclose is not None:
             self._generatefiles()
+            categories = sorted(self._finalizecallback)
+            for cat in categories:
+                self._finalizecallback[cat]()
             self.onclose()
 
         self.count -= 1