histedit: add transaction support to writing the state file
authorDurham Goode <durham@fb.com>
Fri, 10 Mar 2017 15:43:31 -0800
changeset 31511 fa8aaff2001a
parent 31510 2244fb3eee49
child 31512 16f8107a489c
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.
hgext/histedit.py
--- 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')