21 generatorset = smartset.generatorset |
21 generatorset = smartset.generatorset |
22 |
22 |
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 _genrevancestors(repo, revs, followfirst, stopdepth): |
26 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth): |
27 if followfirst: |
27 if followfirst: |
28 cut = 1 |
28 cut = 1 |
29 else: |
29 else: |
30 cut = None |
30 cut = None |
|
31 if startdepth is None: |
|
32 startdepth = 0 |
31 if stopdepth is None: |
33 if stopdepth is None: |
32 stopdepth = _maxlogdepth |
34 stopdepth = _maxlogdepth |
33 if stopdepth <= 0: |
35 if stopdepth <= 0: |
34 return |
36 return |
35 |
37 |
51 currev = -currev |
53 currev = -currev |
52 if currev == inputrev: |
54 if currev == inputrev: |
53 inputrev = next(irevs, None) |
55 inputrev = next(irevs, None) |
54 if inputrev is not None: |
56 if inputrev is not None: |
55 heapq.heappush(pendingheap, (-inputrev, 0)) |
57 heapq.heappush(pendingheap, (-inputrev, 0)) |
|
58 # rescan parents until curdepth >= startdepth because queued entries |
|
59 # of the same revision are iterated from the lowest depth |
56 foundnew = (currev != lastrev) |
60 foundnew = (currev != lastrev) |
57 if foundnew: |
61 if foundnew and curdepth >= startdepth: |
58 lastrev = currev |
62 lastrev = currev |
59 yield currev |
63 yield currev |
60 pdepth = curdepth + 1 |
64 pdepth = curdepth + 1 |
61 if foundnew and pdepth < stopdepth: |
65 if foundnew and pdepth < stopdepth: |
62 try: |
66 try: |
66 except error.WdirUnsupported: |
70 except error.WdirUnsupported: |
67 for pctx in repo[currev].parents()[:cut]: |
71 for pctx in repo[currev].parents()[:cut]: |
68 if pctx.rev() != node.nullrev: |
72 if pctx.rev() != node.nullrev: |
69 heapq.heappush(pendingheap, (-pctx.rev(), pdepth)) |
73 heapq.heappush(pendingheap, (-pctx.rev(), pdepth)) |
70 |
74 |
71 def revancestors(repo, revs, followfirst, stopdepth=None): |
75 def revancestors(repo, revs, followfirst, startdepth=None, stopdepth=None): |
72 """Like revlog.ancestors(), but supports additional options, includes |
76 """Like revlog.ancestors(), but supports additional options, includes |
73 the given revs themselves, and returns a smartset |
77 the given revs themselves, and returns a smartset |
74 |
78 |
75 Scan ends at the stopdepth (exlusive) if specified. |
79 Scan ends at the stopdepth (exlusive) if specified. Revisions found |
|
80 earlier than the startdepth are omitted. |
76 """ |
81 """ |
77 gen = _genrevancestors(repo, revs, followfirst, stopdepth) |
82 gen = _genrevancestors(repo, revs, followfirst, startdepth, stopdepth) |
78 return generatorset(gen, iterasc=False) |
83 return generatorset(gen, iterasc=False) |
79 |
84 |
80 def revdescendants(repo, revs, followfirst): |
85 def revdescendants(repo, revs, followfirst): |
81 """Like revlog.descendants() but supports followfirst.""" |
86 """Like revlog.descendants() but supports followfirst.""" |
82 if followfirst: |
87 if followfirst: |