# HG changeset patch # User Pierre-Yves David # Date 1428095810 25200 # Node ID 72d34c5a66141361ce7eb0d92d7e2315c21c9b2f # Parent 9e558b788daa159df06de258478600e2bb60b77b 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. diff -r 9e558b788daa -r 72d34c5a6614 mercurial/repoview.py --- 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):