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

login
register
mail settings
Submitter Durham Goode
Date March 10, 2017, 11:58 p.m.
Message ID <0c9a2c16ec96fa56206d.1489190283@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/19089/
State Accepted
Headers show

Comments

Durham Goode - March 10, 2017, 11:58 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1489189411 28800
#      Fri Mar 10 15:43:31 2017 -0800
# Node ID 0c9a2c16ec96fa56206dbb1199f01dcb4ece7c11
# Parent  718a57e95a897f4ac407ae3733a7d41e87354acb
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')