18 ) |
18 ) |
19 |
19 |
20 baseset = smartset.baseset |
20 baseset = smartset.baseset |
21 generatorset = smartset.generatorset |
21 generatorset = smartset.generatorset |
22 |
22 |
23 def revancestors(repo, revs, followfirst): |
23 def _genrevancestors(repo, revs, followfirst): |
24 """Like revlog.ancestors(), but supports followfirst.""" |
|
25 if followfirst: |
24 if followfirst: |
26 cut = 1 |
25 cut = 1 |
27 else: |
26 else: |
28 cut = None |
27 cut = None |
29 cl = repo.changelog |
28 cl = repo.changelog |
30 |
29 revs.sort(reverse=True) |
31 def iterate(): |
30 irevs = iter(revs) |
32 revs.sort(reverse=True) |
31 h = [] |
33 irevs = iter(revs) |
32 |
34 h = [] |
33 inputrev = next(irevs, None) |
35 |
34 if inputrev is not None: |
36 inputrev = next(irevs, None) |
35 heapq.heappush(h, -inputrev) |
37 if inputrev is not None: |
36 |
38 heapq.heappush(h, -inputrev) |
37 seen = set() |
39 |
38 while h: |
40 seen = set() |
39 current = -heapq.heappop(h) |
41 while h: |
40 if current == inputrev: |
42 current = -heapq.heappop(h) |
41 inputrev = next(irevs, None) |
43 if current == inputrev: |
42 if inputrev is not None: |
44 inputrev = next(irevs, None) |
43 heapq.heappush(h, -inputrev) |
45 if inputrev is not None: |
44 if current not in seen: |
46 heapq.heappush(h, -inputrev) |
45 seen.add(current) |
47 if current not in seen: |
46 yield current |
48 seen.add(current) |
47 try: |
49 yield current |
48 for parent in cl.parentrevs(current)[:cut]: |
50 try: |
49 if parent != node.nullrev: |
51 for parent in cl.parentrevs(current)[:cut]: |
50 heapq.heappush(h, -parent) |
52 if parent != node.nullrev: |
51 except error.WdirUnsupported: |
53 heapq.heappush(h, -parent) |
52 for parent in repo[current].parents()[:cut]: |
54 except error.WdirUnsupported: |
53 if parent.rev() != node.nullrev: |
55 for parent in repo[current].parents()[:cut]: |
54 heapq.heappush(h, -parent.rev()) |
56 if parent.rev() != node.nullrev: |
55 |
57 heapq.heappush(h, -parent.rev()) |
56 def revancestors(repo, revs, followfirst): |
58 |
57 """Like revlog.ancestors(), but supports followfirst.""" |
59 return generatorset(iterate(), iterasc=False) |
58 gen = _genrevancestors(repo, revs, followfirst) |
|
59 return generatorset(gen, iterasc=False) |
60 |
60 |
61 def revdescendants(repo, revs, followfirst): |
61 def revdescendants(repo, revs, followfirst): |
62 """Like revlog.descendants() but supports followfirst.""" |
62 """Like revlog.descendants() but supports followfirst.""" |
63 if followfirst: |
63 if followfirst: |
64 cut = 1 |
64 cut = 1 |