changeset 22893:9672f0b2cdd9

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.
author Durham Goode <durham@fb.com>
date Tue, 07 Oct 2014 11:37:54 -0700
parents 40f46fd7c50e
children c40be72dc177
files mercurial/phases.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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.