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