Patchwork [11,of,25,RFC] phase: use `trackedphases` in `_getphaserevsnative`

login
register
mail settings
Submitter Boris Feld
Date June 7, 2018, 2:11 p.m.
Message ID <76416e99327fc44f0495.1528380670@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/32005/
State Accepted
Headers show

Comments

Boris Feld - June 7, 2018, 2:11 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1528215367 -7200
#      Tue Jun 05 18:16:07 2018 +0200
# Node ID 76416e99327fc44f049546ad6a39609d9d606081
# Parent  7fa3408f83ef1a04e2d23ab6f8498833b450e589
# EXP-Topic internal-phase
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 76416e99327f
phase: use `trackedphases` in `_getphaserevsnative`

Instead of manually listing secret and draft, simply use the `trackedphases`
constant. The constant is already used by `_getphaserevsnative`.

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -272,19 +272,16 @@  class phasecache(object):
         repo = repo.unfiltered()
         cl = repo.changelog
         self._phasesets = [set() for phase in allphases]
-        roots = pycompat.maplist(cl.rev, self.phaseroots[secret])
-        if roots:
-            ps = set(cl.descendants(roots))
-            for root in roots:
-                ps.add(root)
-            self._phasesets[secret] = ps
-        roots = pycompat.maplist(cl.rev, self.phaseroots[draft])
-        if roots:
-            ps = set(cl.descendants(roots))
-            for root in roots:
-                ps.add(root)
-            ps.difference_update(self._phasesets[secret])
-            self._phasesets[draft] = ps
+        lowerroots = set()
+        for phase in reversed(trackedphases):
+            roots = pycompat.maplist(cl.rev, self.phaseroots[phase])
+            if roots:
+                ps = set(cl.descendants(roots))
+                for root in roots:
+                    ps.add(root)
+                ps.difference_update(lowerroots)
+                lowerroots.update(ps)
+                self._phasesets[phase] = ps
         self._loadedrevslen = len(cl)
 
     def loadphaserevs(self, repo):