Patchwork [1,of,3] histedit: add transaction support to writing the state file

login
register
mail settings
Submitter Durham Goode
Date March 9, 2017, 12:33 a.m.
Message ID <c9195d0e227ad2c3b454.1489019618@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/19044/
State Superseded
Headers show

Comments

Durham Goode - March 9, 2017, 12:33 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1489019264 28800
#      Wed Mar 08 16:27:44 2017 -0800
# Node ID c9195d0e227ad2c3b4544a9352dd59ccd0336d36
# Parent  150cd51257221fad5ccba5794e7a21837afba479
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.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -300,8 +300,15 @@  class histeditstate(object):
         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 @@  class histeditstate(object):
         if not backupfile:
             backupfile = ''
         fp.write('%s\n' % backupfile)
-        fp.close()
 
     def _load(self):
         fp = self.repo.vfs('histedit-state', 'r')