comparison mercurial/repoview.py @ 24617:f76595f6ed7c

repoview: simplify process in _getstatichidden Since all children are processed before their parents, we can apply the following algorithm: For each rev (descending order): * If I'm still hidden, no children will block me, * If I'm not hidden, I must remove my parent from the hidden set, This allows us to dynamically change the set of 'hidden' revisions, dropping the need for the 'actuallyhidden' dictionary and the 'blocked' boolean in the queue. As before, we start iterating from all heads and stop at the first public changesets. This ensures the hidden computation is 'O(not public())' instead of 'O(len(min(not public()):))'.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Apr 2015 14:35:53 -0700
parents 72d34c5a6614
children cde57a8d8fe7
comparison
equal deleted inserted replaced
24616:72d34c5a6614 24617:f76595f6ed7c
32 A second pass will be done to apply "dynamic blocker" like bookmarks or 32 A second pass will be done to apply "dynamic blocker" like bookmarks or
33 working directory parents. 33 working directory parents.
34 34
35 """ 35 """
36 assert not repo.changelog.filteredrevs 36 assert not repo.changelog.filteredrevs
37 hideable = hideablerevs(repo) 37 hidden = set(hideablerevs(repo))
38 if hideable: 38 if hidden:
39 actuallyhidden = {}
40 getphase = repo._phasecache.phase 39 getphase = repo._phasecache.phase
41 getparentrevs = repo.changelog.parentrevs 40 getparentrevs = repo.changelog.parentrevs
42 heap = [(-r, False) for r in repo.changelog.headrevs()] 41 heap = [-r for r in repo.changelog.headrevs()]
43 heapq.heapify(heap) 42 heapq.heapify(heap)
44 heappop = heapq.heappop 43 heappop = heapq.heappop
45 heappush = heapq.heappush 44 heappush = heapq.heappush
46 while heap: 45 while heap:
47 rev, blocked = heappop(heap) 46 rev = -heappop(heap)
48 rev = - rev 47 # Skip nodes which are public (guaranteed to not be hidden)
49 phase = getphase(repo, rev) 48 if not getphase(repo, rev):
50 # Skip nodes which are public (guaranteed to not be hidden) and
51 # nodes which have already been processed and won't be blocked by
52 # the previous node.
53 if phase == 0 or (not blocked and rev in actuallyhidden):
54 continue 49 continue
55 if rev in hideable: 50 # All children have been processed so at that point, if no children
56 if blocked: 51 # removed 'rev' from the 'hidden' set, 'rev' is going to be hidden.
57 actuallyhidden[rev] = False 52 blocker = rev not in hidden
58 else: 53 for parent in getparentrevs(rev):
59 actuallyhidden.setdefault(rev, True) 54 if parent == nullrev:
60 else: 55 continue
61 blocked = True 56 if blocker:
62 57 # If visible, ensure parent will be visible too
63 for parent in (p for p in getparentrevs(rev) if p != nullrev): 58 hidden.discard(parent)
64 heappush(heap, (- parent, blocked)) 59 heappush(heap, -parent)
65 return set(rev for rev, hidden in actuallyhidden.iteritems() if hidden) 60 return hidden
66 61
67 def _getdynamicblockers(repo): 62 def _getdynamicblockers(repo):
68 """Non-cacheable revisions blocking hidden changesets from being filtered. 63 """Non-cacheable revisions blocking hidden changesets from being filtered.
69 64
70 Get revisions that will block hidden changesets and are likely to change, 65 Get revisions that will block hidden changesets and are likely to change,