diff mercurial/phases.py @ 15418:cf729af26963

phases: basic I/O logic Add function to read and write phase roots. Add a _phaseroots filecache on localrepo class to access the phaseroots data.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 04 Nov 2011 00:16:24 +0100
parents 5261140d9322
children ccb7de21625a
line wrap: on
line diff
--- a/mercurial/phases.py	Thu Nov 03 23:49:14 2011 +0100
+++ b/mercurial/phases.py	Fri Nov 04 00:16:24 2011 +0100
@@ -7,5 +7,33 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+from node import nullid, bin, hex
+
 allphases = range(2)
 trackedphases = allphases[1:]
+
+def readroots(repo):
+    """Read phase roots from disk"""
+    roots = [set() for i in allphases]
+    roots[0].add(nullid)
+    try:
+        f = repo.sopener('phaseroots')
+        try:
+            for line in f:
+                phase, nh = line.strip().split()
+                roots[int(phase)].add(bin(nh))
+        finally:
+            f.close()
+    except IOError:
+        pass # default value are enough
+    return roots
+
+def writeroots(repo):
+    """Write phase roots from disk"""
+    f = repo.sopener('phaseroots', 'w', atomictemp=True)
+    try:
+        for phase, roots in enumerate(repo._phaseroots):
+            for h in roots:
+                f.write('%i %s\n' % (phase, hex(h)))
+    finally:
+        f.close()