changeset 22894:c40be72dc177

phases: move root phase assignment to it's own function This moves the initial root phase assignment to it's own function. Future patches which make phase calculations lazy will use this function to pre-fill certain phases which can be deduced from the roots.
author Durham Goode <durham@fb.com>
date Tue, 07 Oct 2014 11:42:37 -0700
parents 9672f0b2cdd9
children dfa44e25bb53
files mercurial/phases.py
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/phases.py	Tue Oct 07 11:37:54 2014 -0700
+++ b/mercurial/phases.py	Tue Oct 07 11:42:37 2014 -0700
@@ -167,6 +167,8 @@
         if self._phaserevs is None:
             repo = repo.unfiltered()
             revs = [public] * len(repo.changelog)
+            self._phaserevs = revs
+            self._populatephaseroots(repo)
             for phase in trackedphases:
                 roots = map(repo.changelog.rev, self.phaseroots[phase])
                 if roots:
@@ -174,11 +176,21 @@
                         revs[rev] = phase
                     for rev in repo.changelog.descendants(roots):
                         revs[rev] = phase
-            self._phaserevs = revs
         return self._phaserevs
+
     def invalidate(self):
         self._phaserevs = None
 
+    def _populatephaseroots(self, repo):
+        """Fills the _phaserevs cache with phases for the roots.
+        """
+        cl = repo.changelog
+        phaserevs = self._phaserevs
+        for phase in trackedphases:
+            roots = map(cl.rev, self.phaseroots[phase])
+            for root in roots:
+                phaserevs[root] = phase
+
     def phase(self, repo, rev):
         # We need a repo argument here to be able to build _phaserevs
         # if necessary. The repository instance is not stored in