comparison mercurial/phases.py @ 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 e803186296ab
comparison
equal deleted inserted replaced
22893:9672f0b2cdd9 22894:c40be72dc177
165 165
166 def getphaserevs(self, repo): 166 def getphaserevs(self, repo):
167 if self._phaserevs is None: 167 if self._phaserevs is None:
168 repo = repo.unfiltered() 168 repo = repo.unfiltered()
169 revs = [public] * len(repo.changelog) 169 revs = [public] * len(repo.changelog)
170 self._phaserevs = revs
171 self._populatephaseroots(repo)
170 for phase in trackedphases: 172 for phase in trackedphases:
171 roots = map(repo.changelog.rev, self.phaseroots[phase]) 173 roots = map(repo.changelog.rev, self.phaseroots[phase])
172 if roots: 174 if roots:
173 for rev in roots: 175 for rev in roots:
174 revs[rev] = phase 176 revs[rev] = phase
175 for rev in repo.changelog.descendants(roots): 177 for rev in repo.changelog.descendants(roots):
176 revs[rev] = phase 178 revs[rev] = phase
177 self._phaserevs = revs
178 return self._phaserevs 179 return self._phaserevs
180
179 def invalidate(self): 181 def invalidate(self):
180 self._phaserevs = None 182 self._phaserevs = None
183
184 def _populatephaseroots(self, repo):
185 """Fills the _phaserevs cache with phases for the roots.
186 """
187 cl = repo.changelog
188 phaserevs = self._phaserevs
189 for phase in trackedphases:
190 roots = map(cl.rev, self.phaseroots[phase])
191 for root in roots:
192 phaserevs[root] = phase
181 193
182 def phase(self, repo, rev): 194 def phase(self, repo, rev):
183 # We need a repo argument here to be able to build _phaserevs 195 # We need a repo argument here to be able to build _phaserevs
184 # if necessary. The repository instance is not stored in 196 # if necessary. The repository instance is not stored in
185 # phasecache to avoid reference cycles. The changelog instance 197 # phasecache to avoid reference cycles. The changelog instance