Patchwork [4,of,5] phase: extract the phaseroots serialisation in a dedicated method

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 7, 2014, 10:52 p.m.
Message ID <ed5766a5d48982f97946.1407451922@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5328/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 7, 2014, 10:52 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1407447660 25200
#      Thu Aug 07 14:41:00 2014 -0700
# Node ID ed5766a5d48982f9794683f594625ce663ca8f90
# Parent  db950150e34324daa2985b2f51ddc8d0ef6b4705
phase: extract the phaseroots serialisation in a dedicated method

In most case, the file creation logic will be handled by the transaction
itself. The write method have to stay around for case were repository is
modified outside a transaction (strip).

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -194,15 +194,18 @@  class phasecache(object):
     def write(self):
         if not self.dirty:
             return
         f = self.opener('phaseroots', 'w', atomictemp=True)
         try:
-            for phase, roots in enumerate(self.phaseroots):
-                for h in roots:
-                    f.write('%i %s\n' % (phase, hex(h)))
+            self._write(f)
         finally:
             f.close()
+
+    def _write(self, fp):
+        for phase, roots in enumerate(self.phaseroots):
+            for h in roots:
+                fp.write('%i %s\n' % (phase, hex(h)))
         self.dirty = False
 
     def _updateroots(self, phase, newroots):
         self.phaseroots[phase] = newroots
         self._phaserevs = None