Patchwork [1,of,5] phase: use `trackedphases` in `_getphaserevsnative`

login
register
mail settings
Submitter Boris Feld
Date Aug. 24, 2018, 10:35 p.m.
Message ID <79b9bd9659a2b3f98154.1535150137@FB-lair>
Download mbox | patch
Permalink /patch/34036/
State Accepted
Headers show

Comments

Boris Feld - Aug. 24, 2018, 10:35 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 79b9bd9659a2b3f9815491a371b988eb7c458726
# Parent  66f046116105a306f7c701c9a5cf97d7b6c926c0
# EXP-Topic internal-phase.prepare
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 79b9bd9659a2
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):