##// END OF EJS Templates
dagop: use heap to compute max rev in filectxancestors()
Yuya Nishihara -
r35298:c9144396 default
parent child Browse files
Show More
@@ -82,10 +82,12 b' def filectxancestors(fctxs, followfirst='
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:
@@ -96,12 +98,13 b' def filectxancestors(fctxs, followfirst='
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,
General Comments 0
You need to be logged in to leave comments. Login now