diff mercurial/transaction.py @ 33087:fcd1c483f5ea

strip: add a delayedstrip method that works in a transaction For long, the fact that strip does not work inside a transaction and some code has to work with both obsstore and fallback to strip lead to duplicated code like: with repo.transaction(): .... if obsstore: obsstore.createmarkers(...) if not obsstore: repair.strip(...) Things get more complex when you want to call something which may call strip under the hood. Like you cannot simply write: with repo.transaction(): .... rebasemod.rebase(...) # may call "strip", so this doesn't work But you do want rebase to run inside a same transaction if possible, so the code may look like: with repo.transaction(): .... if obsstore: rebasemod.rebase(...) obsstore.createmarkers(...) if not obsstore: rebasemod.rebase(...) repair.strip(...) That's ugly and error-prone. Ideally it's possible to just write: with repo.transaction(): rebasemod.rebase(...) saferemovenodes(...) This patch is the first step towards that. It adds a "delayedstrip" method to repair.py which maintains a postclose callback in the transaction object.
author Jun Wu <quark@fb.com>
date Sun, 25 Jun 2017 10:38:45 -0700
parents 2312e70cf78b
children 87bca10a06ed
line wrap: on
line diff
--- a/mercurial/transaction.py	Sun Jun 25 22:30:14 2017 -0700
+++ b/mercurial/transaction.py	Sun Jun 25 10:38:45 2017 -0700
@@ -412,7 +412,7 @@
 
     @active
     def addpostclose(self, category, callback):
-        """add a callback to be called after the transaction is closed
+        """add or replace a callback to be called after the transaction closed
 
         The transaction will be given as callback's first argument.
 
@@ -422,6 +422,11 @@
         self._postclosecallback[category] = callback
 
     @active
+    def getpostclose(self, category):
+        """return a postclose callback added before, or None"""
+        return self._postclosecallback.get(category, None)
+
+    @active
     def addabort(self, category, callback):
         """add a callback to be called when the transaction is aborted.