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

login
register
mail settings
Submitter Durham Goode
Date March 8, 2017, 12:37 a.m.
Message ID <8451bfc2e1d6260a0ce9.1488933455@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/18975/
State Accepted
Headers show

Comments

Durham Goode - March 8, 2017, 12:37 a.m.
# HG changeset patch
# User Durham Goode <durham@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.

Patch

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):