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

Durham Goode durham at fb.com
Thu Mar 9 00:33:38 UTC 2017


# HG changeset patch
# User Durham Goode <durham at 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.

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


More information about the Mercurial-devel mailing list