[PATCH 2 of 6 phases] phases: basic I/O logic

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Nov 4 04:02:30 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1320362184 -3600
# Node ID 9d9364532b0d84bbe24c619d0a184593a5dfa652
# Parent  ab00b78318fbaf0d63078b0adb3c6dc7eee7e9ab
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.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -8,7 +8,7 @@
 from node import bin, hex, nullid, nullrev, short
 from i18n import _
 import repo, changegroup, subrepo, discovery, pushkey
-import changelog, dirstate, filelog, manifest, context, bookmarks
+import changelog, dirstate, filelog, manifest, context, bookmarks, phases
 import lock, transaction, store, encoding
 import scmutil, util, extensions, hook, error, revset
 import match as matchmod
@@ -170,6 +170,10 @@
     def _writebookmarks(self, marks):
       bookmarks.write(self)
 
+    @filecache('phaseroots')
+    def _phaseroots(self):
+        return phases.readroots(self)
+
     @filecache('00changelog.i', True)
     def changelog(self):
         c = changelog.changelog(self.sopener)
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -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()


More information about the Mercurial-devel mailing list