changeset 44097:2f1d6180737f

transaction: allow finalizer to add finalizer It will make some code (persistent nodemap related) simpler to write, because higher level code can blindly queue finalization without thinking too hard about the context. Differential Revision: https://phab.mercurial-scm.org/D7833
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:47:03 +0100
parents e598c874b4af
children 19533e4c3450
files mercurial/transaction.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/transaction.py	Sat Dec 28 12:25:16 2019 -0500
+++ b/mercurial/transaction.py	Wed Jan 15 15:47:03 2020 +0100
@@ -506,9 +506,12 @@
             self._validator(self)  # will raise exception if needed
             self._validator = None  # Help prevent cycles.
             self._generatefiles(group=gengroupprefinalize)
-            categories = sorted(self._finalizecallback)
-            for cat in categories:
-                self._finalizecallback[cat](self)
+            while self._finalizecallback:
+                callbacks = self._finalizecallback
+                self._finalizecallback = {}
+                categories = sorted(callbacks)
+                for cat in categories:
+                    callbacks[cat](self)
             # Prevent double usage and help clear cycles.
             self._finalizecallback = None
             self._generatefiles(group=gengrouppostfinalize)