[PATCH 6 of 6] repoview: avoid processing the same rev twice in _getstatichidden

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Apr 3 22:23:51 UTC 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1428097278 25200
#      Fri Apr 03 14:41:18 2015 -0700
# Node ID 7accf9c57110d99e4e14a0552161a1d4bc652dcc
# Parent  1bc2f01364c0ffb2b2048d5d35d3c7d03d89caf7
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.

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -39,10 +39,11 @@ def _getstatichidden(repo):
         # 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
@@ -50,12 +51,15 @@ def _getstatichidden(repo):
                 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.



More information about the Mercurial-devel mailing list