Show More
@@ -0,0 +1,34 b'' | |||
|
1 | $ hg init r1 | |
|
2 | $ cd r1 | |
|
3 | $ hg ci --config ui.allowemptycommit=true -m c0 | |
|
4 | $ hg ci --config ui.allowemptycommit=true -m c1 | |
|
5 | $ hg ci --config ui.allowemptycommit=true -m c2 | |
|
6 | $ hg co -q 0 | |
|
7 | $ hg ci --config ui.allowemptycommit=true -m c3 | |
|
8 | created new head | |
|
9 | $ hg co -q 3 | |
|
10 | $ hg merge --quiet | |
|
11 | $ hg ci --config ui.allowemptycommit=true -m c4 | |
|
12 | ||
|
13 | $ hg log -G -T'{desc}' | |
|
14 | @ c4 | |
|
15 | |\ | |
|
16 | | o c3 | |
|
17 | | | | |
|
18 | o | c2 | |
|
19 | | | | |
|
20 | o | c1 | |
|
21 | |/ | |
|
22 | o c0 | |
|
23 | ||
|
24 | ||
|
25 | >>> from mercurial.ui import ui | |
|
26 | >>> from mercurial.hg import repository | |
|
27 | >>> repo = repository(ui()) | |
|
28 | >>> for anc in repo.changelog.ancestors([4], inclusive=True): | |
|
29 | ... print(anc) | |
|
30 | 4 | |
|
31 | 3 | |
|
32 | 2 | |
|
33 | 1 | |
|
34 | 0 |
@@ -7,7 +7,6 b'' | |||
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | import collections | |
|
11 | 10 | import heapq |
|
12 | 11 | |
|
13 | 12 | from .node import nullrev |
@@ -305,14 +304,15 b' class lazyancestors(object):' | |||
|
305 | 304 | """Generate the ancestors of _initrevs in reverse topological order. |
|
306 | 305 | |
|
307 | 306 | If inclusive is False, yield a sequence of revision numbers starting |
|
308 |
with the parents of each revision in revs, i.e., each revision is |
|
|
309 |
considered an ancestor of itself. |
|
|
310 | parents of each rev in revs, then parents of those, etc. | |
|
307 | with the parents of each revision in revs, i.e., each revision is | |
|
308 | *not* considered an ancestor of itself. Results are emitted in reverse | |
|
309 | revision number order. That order is also topological: a child is | |
|
310 | always emitted before its parent. | |
|
311 | 311 | |
|
312 | 312 | If inclusive is True, yield all the revs first (ignoring stoprev), |
|
313 | then yield all the ancestors of revs as when inclusive is False. | |
|
314 |
|
|
|
315 |
|
|
|
313 | then yield all the ancestors of revs as when inclusive is False. If an | |
|
314 | element in revs is an ancestor of a different rev it is not yielded | |
|
315 | again.""" | |
|
316 | 316 | seen = set() |
|
317 | 317 | revs = self._initrevs |
|
318 | 318 | if self._inclusive: |
@@ -322,17 +322,27 b' class lazyancestors(object):' | |||
|
322 | 322 | |
|
323 | 323 | parentrevs = self._parentrevs |
|
324 | 324 | stoprev = self._stoprev |
|
325 | visit = collections.deque(revs) | |
|
325 | visit = [] | |
|
326 | heapq.heapify(visit) | |
|
327 | schedule = heapq.heappush | |
|
328 | nextitem = heapq.heappop | |
|
329 | see = seen.add | |
|
330 | see(nullrev) | |
|
326 | 331 | |
|
327 | see = seen.add | |
|
328 | schedule = visit.append | |
|
332 | for r in revs: | |
|
333 | for parent in parentrevs(r): | |
|
334 | if parent not in seen: | |
|
335 | schedule(visit, -parent) | |
|
336 | see(parent) | |
|
329 | 337 | |
|
330 | 338 | while visit: |
|
331 | for parent in parentrevs(visit.popleft()): | |
|
332 |
|
|
|
333 |
|
|
|
334 | see(parent) | |
|
335 |
|
|
|
339 | current = -nextitem(visit) | |
|
340 | if current >= stoprev: | |
|
341 | yield current | |
|
342 | for parent in parentrevs(current): | |
|
343 | if parent not in seen: | |
|
344 | schedule(visit, -parent) | |
|
345 | see(parent) | |
|
336 | 346 | |
|
337 | 347 | def __contains__(self, target): |
|
338 | 348 | """Test whether target is an ancestor of self._initrevs.""" |
@@ -3,16 +3,16 b' membership: []' | |||
|
3 | 3 | iteration: [] |
|
4 | 4 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = False |
|
5 | 5 | membership: [7, 8, 3, 4, 1, 0] |
|
6 |
iteration: [ |
|
|
6 | iteration: [8, 7, 4, 3, 2, 1, 0] | |
|
7 | 7 | % lazy ancestor set for [1, 3], stoprev = 0, inclusive = False |
|
8 | 8 | membership: [1, 0] |
|
9 |
iteration: [ |
|
|
9 | iteration: [1, 0] | |
|
10 | 10 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = True |
|
11 | 11 | membership: [11, 13, 7, 8, 3, 4, 1, 0] |
|
12 |
iteration: [11, 13, |
|
|
12 | iteration: [11, 13, 8, 7, 4, 3, 2, 1, 0] | |
|
13 | 13 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = False |
|
14 | 14 | membership: [7, 8] |
|
15 |
iteration: [ |
|
|
15 | iteration: [8, 7] | |
|
16 | 16 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = True |
|
17 | 17 | membership: [11, 13, 7, 8] |
|
18 |
iteration: [11, 13, |
|
|
18 | iteration: [11, 13, 8, 7] |
@@ -1,13 +1,13 b'' | |||
|
1 | 1 | Ancestors of 5 |
|
2 | 2 | 4 2 0 |
|
3 | 3 | Ancestors of 6 and 5 |
|
4 |
|
|
|
4 | 4 3 2 1 0 | |
|
5 | 5 | Ancestors of 5 and 4 |
|
6 | 6 | 4 2 0 |
|
7 | 7 | Ancestors of 7, stop at 6 |
|
8 | 8 | 6 |
|
9 | 9 | Ancestors of 7, including revs |
|
10 |
7 6 5 |
|
|
10 | 7 6 5 4 3 2 1 0 | |
|
11 | 11 | Ancestors of 7, 5 and 3, including revs |
|
12 | 12 | 7 5 3 6 4 2 1 0 |
|
13 | 13 |
General Comments 0
You need to be logged in to leave comments.
Login now