repoview: avoid processing the same rev twice in _getstatichidden
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 03 Apr 2015 14:41:18 -0700
changeset 24682 7c6f9097e2e03be6630d782114ac312264f7333a
parent 24681 ad6dea5d96f219ab4cdd12155081b2ba1879dbe6
child 24684 1e05f11619bb4256e85fac62cf71c0e3e4639d2e
push id12
push usergszorc@mozilla.com
push dateWed, 15 Apr 2015 21:42:54 +0000
repoview: avoid processing the same rev twice in _getstatichidden If a rev had multiple children, it would be added to the heap multiple times. We now ensure it is added only once.
mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -38,29 +38,33 @@ def _getstatichidden(repo):
     if hidden:
         getphase = repo._phasecache.phase
         getparentrevs = repo.changelog.parentrevs
         # Skip heads which are public (guaranteed to not be hidden)
         heap = [-r for r in repo.changelog.headrevs() if getphase(repo, r)]
         heapq.heapify(heap)
         heappop = heapq.heappop
         heappush = heapq.heappush
+        seen = set() # no need to init it with heads, they have no children
         while heap:
             rev = -heappop(heap)
             # All children have been processed so at that point, if no children
             # removed 'rev' from the 'hidden' set, 'rev' is going to be hidden.
             blocker = rev not in hidden
             for parent in getparentrevs(rev):
                 if parent == nullrev:
                     continue
                 if blocker:
                     # If visible, ensure parent will be visible too
                     hidden.discard(parent)
-                # Skip nodes which are public (guaranteed to not be hidden)
-                if getphase(repo, rev):
+                # - Avoid adding the same revision twice
+                # - Skip nodes which are public (guaranteed to not be hidden)
+                pre = len(seen)
+                seen.add(parent)
+                if pre < len(seen) and getphase(repo, rev):
                     heappush(heap, -parent)
     return hidden
 
 def _getdynamicblockers(repo):
     """Non-cacheable revisions blocking hidden changesets from being filtered.
 
     Get revisions that will block hidden changesets and are likely to change,
     but unlikely to create hidden blockers. They won't be cached, so be careful