mercurial/phases.py
changeset 22893 9672f0b2cdd9
parent 22080 37f46575d9c2
child 22894 c40be72dc177
equal deleted inserted replaced
22892:40f46fd7c50e 22893:9672f0b2cdd9
   161 
   161 
   162     def replace(self, phcache):
   162     def replace(self, phcache):
   163         for a in 'phaseroots dirty opener _phaserevs'.split():
   163         for a in 'phaseroots dirty opener _phaserevs'.split():
   164             setattr(self, a, getattr(phcache, a))
   164             setattr(self, a, getattr(phcache, a))
   165 
   165 
   166     def getphaserevs(self, repo, rebuild=False):
   166     def getphaserevs(self, repo):
   167         if rebuild or 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             for phase in trackedphases:
   170             for phase in trackedphases:
   171                 roots = map(repo.changelog.rev, self.phaseroots[phase])
   171                 roots = map(repo.changelog.rev, self.phaseroots[phase])
   172                 if roots:
   172                 if roots:
   174                         revs[rev] = phase
   174                         revs[rev] = phase
   175                     for rev in repo.changelog.descendants(roots):
   175                     for rev in repo.changelog.descendants(roots):
   176                         revs[rev] = phase
   176                         revs[rev] = phase
   177             self._phaserevs = revs
   177             self._phaserevs = revs
   178         return self._phaserevs
   178         return self._phaserevs
       
   179     def invalidate(self):
       
   180         self._phaserevs = None
   179 
   181 
   180     def phase(self, repo, rev):
   182     def phase(self, repo, rev):
   181         # We need a repo argument here to be able to build _phaserevs
   183         # We need a repo argument here to be able to build _phaserevs
   182         # if necessary. The repository instance is not stored in
   184         # if necessary. The repository instance is not stored in
   183         # phasecache to avoid reference cycles. The changelog instance
   185         # phasecache to avoid reference cycles. The changelog instance
   186         if rev == nullrev:
   188         if rev == nullrev:
   187             return public
   189             return public
   188         if rev < nullrev:
   190         if rev < nullrev:
   189             raise ValueError(_('cannot lookup negative revision'))
   191             raise ValueError(_('cannot lookup negative revision'))
   190         if self._phaserevs is None or rev >= len(self._phaserevs):
   192         if self._phaserevs is None or rev >= len(self._phaserevs):
   191             self._phaserevs = self.getphaserevs(repo, rebuild=True)
   193             self.invalidate()
       
   194             self._phaserevs = self.getphaserevs(repo)
   192         return self._phaserevs[rev]
   195         return self._phaserevs[rev]
   193 
   196 
   194     def write(self):
   197     def write(self):
   195         if not self.dirty:
   198         if not self.dirty:
   196             return
   199             return
   206                 fp.write('%i %s\n' % (phase, hex(h)))
   209                 fp.write('%i %s\n' % (phase, hex(h)))
   207         self.dirty = False
   210         self.dirty = False
   208 
   211 
   209     def _updateroots(self, phase, newroots, tr):
   212     def _updateroots(self, phase, newroots, tr):
   210         self.phaseroots[phase] = newroots
   213         self.phaseroots[phase] = newroots
   211         self._phaserevs = None
   214         self.invalidate()
   212         self.dirty = True
   215         self.dirty = True
   213 
   216 
   214         tr.addfilegenerator('phase', ('phaseroots',), self._write)
   217         tr.addfilegenerator('phase', ('phaseroots',), self._write)
   215 
   218 
   216     def advanceboundary(self, repo, tr, targetphase, nodes):
   219     def advanceboundary(self, repo, tr, targetphase, nodes):
   279         #
   282         #
   280         # The other caller is __init__ that have no _phaserevs initialized
   283         # The other caller is __init__ that have no _phaserevs initialized
   281         # anyway. If this change we should consider adding a dedicated
   284         # anyway. If this change we should consider adding a dedicated
   282         # "destroyed" function to phasecache or a proper cache key mechanism
   285         # "destroyed" function to phasecache or a proper cache key mechanism
   283         # (see branchmap one)
   286         # (see branchmap one)
   284         self._phaserevs = None
   287         self.invalidate()
   285 
   288 
   286 def advanceboundary(repo, tr, targetphase, nodes):
   289 def advanceboundary(repo, tr, targetphase, nodes):
   287     """Add nodes to a phase changing other nodes phases if necessary.
   290     """Add nodes to a phase changing other nodes phases if necessary.
   288 
   291 
   289     This function move boundary *forward* this means that all nodes
   292     This function move boundary *forward* this means that all nodes