# HG changeset patch # User Durham Goode # Date 1412707074 25200 # Node ID 9672f0b2cdd9e910d3264553156563fd0801d95a # Parent 40f46fd7c50e160675c66bc040cd654947291871 phases: add invalidate function Phase cache invalidation was spread all over the place. Let's add a function to unify it. Later more will be added to this function. diff -r 40f46fd7c50e -r 9672f0b2cdd9 mercurial/phases.py --- a/mercurial/phases.py Sun Oct 12 23:30:04 2014 -0700 +++ b/mercurial/phases.py Tue Oct 07 11:37:54 2014 -0700 @@ -163,8 +163,8 @@ for a in 'phaseroots dirty opener _phaserevs'.split(): setattr(self, a, getattr(phcache, a)) - def getphaserevs(self, repo, rebuild=False): - if rebuild or self._phaserevs is None: + def getphaserevs(self, repo): + if self._phaserevs is None: repo = repo.unfiltered() revs = [public] * len(repo.changelog) for phase in trackedphases: @@ -176,6 +176,8 @@ revs[rev] = phase self._phaserevs = revs return self._phaserevs + def invalidate(self): + self._phaserevs = None def phase(self, repo, rev): # We need a repo argument here to be able to build _phaserevs @@ -188,7 +190,8 @@ if rev < nullrev: raise ValueError(_('cannot lookup negative revision')) if self._phaserevs is None or rev >= len(self._phaserevs): - self._phaserevs = self.getphaserevs(repo, rebuild=True) + self.invalidate() + self._phaserevs = self.getphaserevs(repo) return self._phaserevs[rev] def write(self): @@ -208,7 +211,7 @@ def _updateroots(self, phase, newroots, tr): self.phaseroots[phase] = newroots - self._phaserevs = None + self.invalidate() self.dirty = True tr.addfilegenerator('phase', ('phaseroots',), self._write) @@ -281,7 +284,7 @@ # anyway. If this change we should consider adding a dedicated # "destroyed" function to phasecache or a proper cache key mechanism # (see branchmap one) - self._phaserevs = None + self.invalidate() def advanceboundary(repo, tr, targetphase, nodes): """Add nodes to a phase changing other nodes phases if necessary.