Patchwork [2,of,5] phases: add invalidate function

login
register
mail settings
Submitter Durham Goode
Date Oct. 9, 2014, 7:22 p.m.
Message ID <34e934d15e8c9a8c5809.1412882560@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6167/
State Accepted
Headers show

Comments

Durham Goode - Oct. 9, 2014, 7:22 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1412707074 25200
#      Tue Oct 07 11:37:54 2014 -0700
# Node ID 34e934d15e8c9a8c5809dc1909cbdfcba1017603
# Parent  21386e638281d3fe94138c5fb8ea6f6d7aa3a8cd
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.

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -163,8 +163,8 @@  class phasecache(object):
         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 @@  class phasecache(object):
                         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 @@  class phasecache(object):
         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 @@  class phasecache(object):
 
     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 @@  class phasecache(object):
         # 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.