changeset 24616:72d34c5a6614

repoview: use a heap in _getstatichidden Since we want to process all non-public changesets from top to bottom, a heap seems more appropriate. This will ensure any revision is processed after all its children, opening the way to code simplification.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Apr 2015 14:16:50 -0700
parents 9e558b788daa
children f76595f6ed7c
files mercurial/repoview.py
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/repoview.py	Fri Apr 03 13:58:12 2015 -0700
+++ b/mercurial/repoview.py	Fri Apr 03 14:16:50 2015 -0700
@@ -6,7 +6,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import collections
+import heapq
 import copy
 import error
 import phases
@@ -39,9 +39,13 @@
         actuallyhidden = {}
         getphase = repo._phasecache.phase
         getparentrevs = repo.changelog.parentrevs
-        queue = collections.deque((r, False) for r in repo.changelog.headrevs())
-        while queue:
-            rev, blocked = queue.popleft()
+        heap = [(-r, False) for r in repo.changelog.headrevs()]
+        heapq.heapify(heap)
+        heappop = heapq.heappop
+        heappush = heapq.heappush
+        while heap:
+            rev, blocked = heappop(heap)
+            rev = - rev
             phase = getphase(repo, rev)
             # Skip nodes which are public (guaranteed to not be hidden) and
             # nodes which have already been processed and won't be blocked by
@@ -57,7 +61,7 @@
                 blocked = True
 
             for parent in (p for p in getparentrevs(rev) if p != nullrev):
-                queue.append((parent, blocked))
+                heappush(heap, (- parent, blocked))
     return set(rev for rev, hidden in actuallyhidden.iteritems() if hidden)
 
 def _getdynamicblockers(repo):