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

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Oct 10 12:27:58 UTC 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1318159211 -7200
# Node ID a021813a715118f511262e67a3b80179207efe5b
# Parent  712a670bb8ce039782649741a8c409de66968d42
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
@@ -165,10 +165,14 @@ class localrepository(repo.repository):
 
     @filecache('bookmarks.current')
     def _bookmarkcurrent(self):
         return bookmarks.readcurrent(self)
 
+    @filecache('phases-heads')
+    def _phasesheads(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,39 @@
 #                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
+
 allphases = range(2)
 trackedphases = allphases[:-1]
+
+### I/O code
+############
+
+def readheads(repo):
+    """Read phrases head from disk"""
+    try:
+        heads = [set()]
+        f = repo.sopener('phrases-heads')
+        try:
+            for line in f:
+                phrase, nh = line.strip().split()
+                heads[int(phrase)].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 phrases head from disk"""
+    f = repo.sopener('phrases-heads', 'w', atomictemp=True)
+    try:
+        for phrase, heads in enumerate(repo._phraseheads):
+            for h in heads:
+                f.write('%i %s\n' % (phrase, hex(h)))
+    finally:
+        f.close()



More information about the Mercurial-devel mailing list