~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-19 18:04:49 UTC
  • mfrom: (4593.5.43 1.19-known-graph-sorted)
  • Revision ID: pqm@pqm.ubuntu.com-20090819180449-p5dibldf9pcp24n4
(jam) Add VersionedFiles.get_known_graph_ancestry and
        KnownGraph.merge_sort()

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
454
 
                generate_revno=True)
455
 
            # Drop the sequence # before caching
456
 
            self._merge_sorted_revisions_cache = [r[1:] for r in revs]
457
 
 
 
449
            last_key = (last_revision,)
 
450
            known_graph = self.repository.revisions.get_known_graph_ancestry(
 
451
                [last_key])
 
452
            self._merge_sorted_revisions_cache = known_graph.merge_sort(
 
453
                last_key)
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:
475
472
                    continue
476
473
                else:
477
474
                    # The decision to include the start or not
478
475
                    # depends on the stop_rule if a stop is provided
479
 
                    rev_iter = chain(
480
 
                        iter([(rev_id, depth, revno, end_of_merge)]),
481
 
                        rev_iter)
 
476
                    # so pop this node back into the iterator
 
477
                    rev_iter = chain(iter([node]), rev_iter)
482
478
                    break
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
 
480
            # Yield everything
 
481
            for node in rev_iter:
 
482
                rev_id = node.key[-1]
 
483
                yield (rev_id, node.merge_depth, node.revno,
 
484
                       node.end_of_merge)
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:
489
489
                    return
490
 
                yield rev_id, depth, revno, end_of_merge
 
490
                yield (rev_id, node.merge_depth, node.revno,
 
491
                       node.end_of_merge)
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,
 
496
                       node.end_of_merge)
494
497
                if rev_id == stop_revision_id:
495
498
                    return
496
499
        elif stop_rule == 'with-merges':
499
502
                left_parent = stop_rev.parent_ids[0]
500
503
            else:
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:
504
508
                    return
505
 
                yield rev_id, depth, revno, end_of_merge
 
509
                yield (rev_id, node.merge_depth, node.revno,
 
510
                       node.end_of_merge)
506
511
        else:
507
512
            raise ValueError('invalid stop_rule %r' % stop_rule)
508
513