Mercurial > hg
comparison mercurial/dagop.py @ 35297:c9144396099b
dagop: use heap to compute max rev in filectxancestors()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 22 Sep 2016 18:41:51 +0900 |
parents | 2cb05e6043be |
children | 7affcabf561e |
comparison
equal
deleted
inserted
replaced
35296:2cb05e6043be | 35297:c9144396099b |
---|---|
80 and includes the given fctxs themselves | 80 and includes the given fctxs themselves |
81 | 81 |
82 Yields (rev, {fctx, ...}) pairs in descending order. | 82 Yields (rev, {fctx, ...}) pairs in descending order. |
83 """ | 83 """ |
84 visit = {} | 84 visit = {} |
85 visitheap = [] | |
85 def addvisit(fctx): | 86 def addvisit(fctx): |
86 rev = fctx.rev() | 87 rev = fctx.rev() |
87 if rev not in visit: | 88 if rev not in visit: |
88 visit[rev] = set() | 89 visit[rev] = set() |
90 heapq.heappush(visitheap, -rev) # max heap | |
89 visit[rev].add(fctx) | 91 visit[rev].add(fctx) |
90 | 92 |
91 if followfirst: | 93 if followfirst: |
92 cut = 1 | 94 cut = 1 |
93 else: | 95 else: |
94 cut = None | 96 cut = None |
95 | 97 |
96 for c in fctxs: | 98 for c in fctxs: |
97 addvisit(c) | 99 addvisit(c) |
98 while visit: | 100 while visit: |
99 currev = max(visit) | 101 currev = -heapq.heappop(visitheap) |
100 curfctxs = visit.pop(currev) | 102 curfctxs = visit.pop(currev) |
101 yield currev, curfctxs | 103 yield currev, curfctxs |
102 for c in curfctxs: | 104 for c in curfctxs: |
103 for parent in c.parents()[:cut]: | 105 for parent in c.parents()[:cut]: |
104 addvisit(parent) | 106 addvisit(parent) |
107 assert not visitheap | |
105 | 108 |
106 def filerevancestors(fctxs, followfirst=False): | 109 def filerevancestors(fctxs, followfirst=False): |
107 """Like filectx.ancestors(), but can walk from multiple files/revisions, | 110 """Like filectx.ancestors(), but can walk from multiple files/revisions, |
108 and includes the given fctxs themselves | 111 and includes the given fctxs themselves |
109 | 112 |