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

login
register
mail settings
Submitter Pierre-Yves David
Date April 3, 2015, 10:23 p.m.
Message ID <ce977bd09297ff9320b6.1428099827@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8487/
State Accepted
Commit 72d34c5a66141361ce7eb0d92d7e2315c21c9b2f
Headers show

Comments

Pierre-Yves David - April 3, 2015, 10:23 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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@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.