446
446
# start_revision_id.
447
447
if self._merge_sorted_revisions_cache is None:
448
448
last_revision = self.last_revision()
449
graph = self.repository.get_graph()
450
parent_map = dict(((key, value) for key, value in
451
graph.iter_ancestry([last_revision]) if value is not None))
452
revision_graph = repository._strip_NULL_ghosts(parent_map)
453
revs = tsort.merge_sort(revision_graph, last_revision, None,
455
# Drop the sequence # before caching
456
self._merge_sorted_revisions_cache = [r[1:] for r in revs]
449
last_key = (last_revision,)
450
known_graph = self.repository.revisions.get_known_graph_ancestry(
452
self._merge_sorted_revisions_cache = known_graph.merge_sort(
458
454
filtered = self._filter_merge_sorted_revisions(
459
455
self._merge_sorted_revisions_cache, start_revision_id,
460
456
stop_revision_id, stop_rule)
470
466
"""Iterate over an inclusive range of sorted revisions."""
471
467
rev_iter = iter(merge_sorted_revisions)
472
468
if start_revision_id is not None:
473
for rev_id, depth, revno, end_of_merge in rev_iter:
469
for node in rev_iter:
470
rev_id = node.key[-1]
474
471
if rev_id != start_revision_id:
477
474
# The decision to include the start or not
478
475
# depends on the stop_rule if a stop is provided
480
iter([(rev_id, depth, revno, end_of_merge)]),
476
# so pop this node back into the iterator
477
rev_iter = chain(iter([node]), rev_iter)
483
479
if stop_revision_id is None:
484
for rev_id, depth, revno, end_of_merge in rev_iter:
485
yield rev_id, depth, revno, end_of_merge
481
for node in rev_iter:
482
rev_id = node.key[-1]
483
yield (rev_id, node.merge_depth, node.revno,
486
485
elif stop_rule == 'exclude':
487
for rev_id, depth, revno, end_of_merge in rev_iter:
486
for node in rev_iter:
487
rev_id = node.key[-1]
488
488
if rev_id == stop_revision_id:
490
yield rev_id, depth, revno, end_of_merge
490
yield (rev_id, node.merge_depth, node.revno,
491
492
elif stop_rule == 'include':
492
for rev_id, depth, revno, end_of_merge in rev_iter:
493
yield rev_id, depth, revno, end_of_merge
493
for node in rev_iter:
494
rev_id = node.key[-1]
495
yield (rev_id, node.merge_depth, node.revno,
494
497
if rev_id == stop_revision_id:
496
499
elif stop_rule == 'with-merges':
499
502
left_parent = stop_rev.parent_ids[0]
501
504
left_parent = _mod_revision.NULL_REVISION
502
for rev_id, depth, revno, end_of_merge in rev_iter:
505
for node in rev_iter:
506
rev_id = node.key[-1]
503
507
if rev_id == left_parent:
505
yield rev_id, depth, revno, end_of_merge
509
yield (rev_id, node.merge_depth, node.revno,
507
512
raise ValueError('invalid stop_rule %r' % stop_rule)