[PATCH 02 of 12] phases: basic I/O logic

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Oct 18 12:26:59 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318945091 -7200
# Node ID 6fd51910bd8bed80307f29fd5a536cfbeab0a9f6
# Parent  5c3fed361df6eb56d8cadc2e7118c87430010e0e
phases: basic I/O logic

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -6,11 +6,11 @@
 # GNU General Public License version 2 or any later version.
 
 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
 import merge as mergemod
 import tags as tagsmod
@@ -168,10 +168,14 @@ class localrepository(repo.repository):
         return bookmarks.readcurrent(self)
 
     def _writebookmarks(self, marks):
       bookmarks.write(self)
 
+    @filecache('phaseheads')
+    def _phaseheads(self):
+        return phases.readheads(self)
+
     @filecache('00changelog.i', True)
     def changelog(self):
         c = changelog.changelog(self.sopener)
         if 'HG_PENDING' in os.environ:
             p = os.environ['HG_PENDING']
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -5,7 +5,36 @@
 #                Augie Fackler     <durin42 at gmail.com>
 #
 # 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 readheads(repo):
+    """Read phase heads from disk"""
+    try:
+        heads = [set()]
+        f = repo.sopener('phaseheads')
+        try:
+            for line in f:
+                phase, nh = line.strip().split()
+                heads[int(phase)].add(bin(nh))
+        finally:
+            f.close()
+    except IOError:
+        pass # gracefully filled bellow
+    if not heads[0]:
+        heads[0].add(nullid)
+    return heads
+
+def writeheads(repo):
+    """Write phase heads from disk"""
+    f = repo.sopener('phaseheads', 'w', atomictemp=True)
+    try:
+        for phase, heads in enumerate(repo._phaseheads):
+            for h in heads:
+                f.write('%i %s\n' % (phase, hex(h)))
+    finally:
+        f.close()


More information about the Mercurial-devel mailing list