[PATCH 3 of 5 V2] rebase: add storestatus support for transactions

Durham Goode durham at fb.com
Tue Mar 7 19:37:35 EST 2017


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1488924269 28800
#      Tue Mar 07 14:04:29 2017 -0800
# Node ID 8451bfc2e1d6260a0ce9dac505dd9f34fb3b19aa
# Parent  9ee513d4a3884d19a85b2aadd7bac362d1530d11
rebase: add storestatus support for transactions

This let's the status writing logic support transactions. This will be useful in
a later patch where we add a transaction around the entire rebase.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -159,10 +159,17 @@ class rebaseruntime(object):
         self.keepopen = opts.get('keepopen', False)
         self.obsoletenotrebased = {}
 
-    def storestatus(self):
+    def storestatus(self, tr=None):
         """Store the current status to allow recovery"""
+        if tr:
+            tr.addfilegenerator('rebasestate', ('rebasestate',),
+                                self._writestatus, location='plain')
+        else:
+            with self.repo.vfs("rebasestate", "w") as f:
+                self._writestatus(f)
+
+    def _writestatus(self, f):
         repo = self.repo
-        f = repo.vfs("rebasestate", "w")
         f.write(repo[self.originalwd].hex() + '\n')
         f.write(repo[self.target].hex() + '\n')
         f.write(repo[self.external].hex() + '\n')
@@ -181,7 +188,6 @@ class rebaseruntime(object):
             else:
                 newrev = v
             f.write("%s:%s\n" % (oldrev, newrev))
-        f.close()
         repo.ui.debug('rebase status stored\n')
 
     def restorestatus(self):


More information about the Mercurial-devel mailing list