changeset 31511:fa8aaff2001a

histedit: add transaction support to writing the state file This will be used in a future diff to enable a single transaction around an entire histedit.
author Durham Goode <durham@fb.com>
date Fri, 10 Mar 2017 15:43:31 -0800
parents 2244fb3eee49
children 16f8107a489c
files hgext/histedit.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Sun Mar 19 01:11:00 2017 -0400
+++ b/hgext/histedit.py	Fri Mar 10 15:43:31 2017 -0800
@@ -300,8 +300,15 @@
         self.replacements = replacements
         self.backupfile = backupfile
 
-    def write(self):
-        fp = self.repo.vfs('histedit-state', 'w')
+    def write(self, tr=None):
+        if tr:
+            tr.addfilegenerator('histedit-state', ('histedit-state',),
+                                self._write, location='plain')
+        else:
+            with self.repo.vfs("histedit-state", "w") as f:
+                self._write(f)
+
+    def _write(self, fp):
         fp.write('v1\n')
         fp.write('%s\n' % node.hex(self.parentctxnode))
         fp.write('%s\n' % node.hex(self.topmost))
@@ -317,7 +324,6 @@
         if not backupfile:
             backupfile = ''
         fp.write('%s\n' % backupfile)
-        fp.close()
 
     def _load(self):
         fp = self.repo.vfs('histedit-state', 'r')