##// END OF EJS Templates
dagop: make walk direction switchable so it can track descendants...
Yuya Nishihara -
r33079:550c390c default
parent child Browse files
Show More
@@ -23,10 +23,11 b' generatorset = smartset.generatorset'
23 23 # possible maximum depth between null and wdir()
24 24 _maxlogdepth = 0x80000000
25 25
26 def _walkrevtree(pfunc, revs, startdepth, stopdepth):
26 def _walkrevtree(pfunc, revs, startdepth, stopdepth, reverse):
27 27 """Walk DAG using 'pfunc' from the given 'revs' nodes
28 28
29 'pfunc(rev)' should return the parent revisions of the given 'rev'.
29 'pfunc(rev)' should return the parent/child revisions of the given 'rev'
30 if 'reverse' is True/False respectively.
30 31
31 32 Scan ends at the stopdepth (exlusive) if specified. Revisions found
32 33 earlier than the startdepth are omitted.
@@ -39,25 +40,29 b' def _walkrevtree(pfunc, revs, startdepth'
39 40 return
40 41 if stopdepth < 0:
41 42 raise error.ProgrammingError('negative stopdepth')
43 if reverse:
44 heapsign = -1 # max heap
45 else:
46 heapsign = +1 # min heap
42 47
43 48 # load input revs lazily to heap so earlier revisions can be yielded
44 49 # without fully computing the input revs
45 revs.sort(reverse=True)
50 revs.sort(reverse)
46 51 irevs = iter(revs)
47 pendingheap = [] # [(-rev, depth), ...] (i.e. lower depth first)
52 pendingheap = [] # [(heapsign * rev, depth), ...] (i.e. lower depth first)
48 53
49 54 inputrev = next(irevs, None)
50 55 if inputrev is not None:
51 heapq.heappush(pendingheap, (-inputrev, 0))
56 heapq.heappush(pendingheap, (heapsign * inputrev, 0))
52 57
53 58 lastrev = None
54 59 while pendingheap:
55 60 currev, curdepth = heapq.heappop(pendingheap)
56 currev = -currev
61 currev = heapsign * currev
57 62 if currev == inputrev:
58 63 inputrev = next(irevs, None)
59 64 if inputrev is not None:
60 heapq.heappush(pendingheap, (-inputrev, 0))
65 heapq.heappush(pendingheap, (heapsign * inputrev, 0))
61 66 # rescan parents until curdepth >= startdepth because queued entries
62 67 # of the same revision are iterated from the lowest depth
63 68 foundnew = (currev != lastrev)
@@ -68,7 +73,7 b' def _walkrevtree(pfunc, revs, startdepth'
68 73 if foundnew and pdepth < stopdepth:
69 74 for prev in pfunc(currev):
70 75 if prev != node.nullrev:
71 heapq.heappush(pendingheap, (-prev, pdepth))
76 heapq.heappush(pendingheap, (heapsign * prev, pdepth))
72 77
73 78 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth):
74 79 if followfirst:
@@ -81,7 +86,7 b' def _genrevancestors(repo, revs, followf'
81 86 return cl.parentrevs(rev)[:cut]
82 87 except error.WdirUnsupported:
83 88 return (pctx.rev() for pctx in repo[rev].parents()[:cut])
84 return _walkrevtree(pfunc, revs, startdepth, stopdepth)
89 return _walkrevtree(pfunc, revs, startdepth, stopdepth, reverse=True)
85 90
86 91 def revancestors(repo, revs, followfirst, startdepth=None, stopdepth=None):
87 92 """Like revlog.ancestors(), but supports additional options, includes
General Comments 0
You need to be logged in to leave comments. Login now