[PATCH 03 of 12] phases: add a cache allowing to know in which phase a changeset is

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Oct 18 12:27:00 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318955107 -7200
# Node ID d8381a929be96f1320becc6b05a68a043900b420
# Parent  6fd51910bd8bed80307f29fd5a536cfbeab0a9f6
phases: add a cache allowing to know in which phase a changeset is

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -172,10 +172,25 @@ class localrepository(repo.repository):
 
     @filecache('phaseheads')
     def _phaseheads(self):
         return phases.readheads(self)
 
+    @propertycache
+    def _phaserev(self):
+        cache = [phases.allphases[-1]] * len(self)
+        for phase in reversed(phases.trackedphases):
+            heads = map(self.changelog.rev, self._phaseheads[phase])
+            # we probably have majority of lower state changeset
+            for rev in heads:
+                if rev == -1:
+                    continue
+                cache[rev] = phase
+            for rev in self.changelog.ancestors(*heads):
+                cache[rev] = phase
+        return cache
+
+
     @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
@@ -36,5 +36,6 @@ def writeheads(repo):
         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