[PATCH 2 of 6] repoview: use a heap in _getstatichidden

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Apr 3 17:23:47 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1428095810 25200
#      Fri Apr 03 14:16:50 2015 -0700
# Node ID ce977bd09297ff9320b60c3ed2ec45ba1103d147
# Parent  d99e07f199e8a0c597e09aa7dc19742b895a8774
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 revisions are processed after all
its children, opening the way to code simplification.

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -4,11 +4,11 @@
 #                Logilab SA        <contact at logilab.fr>
 #
 # 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
 import util
 import obsolete
@@ -35,13 +35,17 @@ def _getstatichidden(repo):
     hideable = hideablerevs(repo)
     if hideable:
         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
             # the previous node.
             if phase == 0 or (not blocked and rev in actuallyhidden):
@@ -53,11 +57,11 @@ def _getstatichidden(repo):
                     actuallyhidden.setdefault(rev, True)
             else:
                 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):
     """Non-cacheable revisions blocking hidden changesets from being filtered.
 


More information about the Mercurial-devel mailing list