# HG changeset patch # User Durham Goode # Date 2014-10-07 18:42:37 # Node ID c40be72dc1779495d38cad5ed64f4b67fd87fcd6 # Parent 9672f0b2cdd9e910d3264553156563fd0801d95a 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. diff --git a/mercurial/phases.py b/mercurial/phases.py --- a/mercurial/phases.py +++ b/mercurial/phases.py @@ -167,6 +167,8 @@ class phasecache(object): 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 @@ class phasecache(object): 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