~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-17 20:41:26 UTC
  • mto: This revision was merged to the branch mainline in revision 4629.
  • Revision ID: john@arbash-meinel.com-20090817204126-fokcicx22mwsgud0
Change the KnownGraph.merge_sort api.

Instead of being a tuple api, it is now an Object api. TIMEIT testing at least
seems to say that _MergeSortNode.key is no slower than using a tuple.
Allocating the nodes is also not much slower (especially since we already needed
them.)

In the end it makes for an api which, IMO, is much easier to use, so
since performance isn't impacted, it is worth switching.


Also, determined that we needed to implement the new get_known_graph... on
the weave code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
449
449
            last_key = (last_revision,)
450
450
            known_graph = self.repository.revisions.get_known_graph_ancestry(
451
451
                [last_key])
452
 
            revs = known_graph.merge_sort(last_key)
453
 
            self._merge_sorted_revisions_cache = [(key[-1], d, rn, eom)
454
 
                for key, d, rn, eom in revs]
455
 
 
 
452
            self._merge_sorted_revisions_cache = known_graph.merge_sort(
 
453
                last_key)
456
454
        filtered = self._filter_merge_sorted_revisions(
457
455
            self._merge_sorted_revisions_cache, start_revision_id,
458
456
            stop_revision_id, stop_rule)
468
466
        """Iterate over an inclusive range of sorted revisions."""
469
467
        rev_iter = iter(merge_sorted_revisions)
470
468
        if start_revision_id is not None:
471
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
469
            for node in rev_iter:
 
470
                rev_id = node.key[-1]
472
471
                if rev_id != start_revision_id:
473
472
                    continue
474
473
                else:
475
474
                    # The decision to include the start or not
476
475
                    # depends on the stop_rule if a stop is provided
477
 
                    rev_iter = chain(
478
 
                        iter([(rev_id, depth, revno, end_of_merge)]),
479
 
                        rev_iter)
 
476
                    # so pop this node back into the iterator
 
477
                    rev_iter = chain(iter([node]), rev_iter)
480
478
                    break
481
479
        if stop_revision_id is None:
482
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
483
 
                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)
484
485
        elif stop_rule == 'exclude':
485
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
486
            for node in rev_iter:
 
487
                rev_id = node.key[-1]
486
488
                if rev_id == stop_revision_id:
487
489
                    return
488
 
                yield rev_id, depth, revno, end_of_merge
 
490
                yield (rev_id, node.merge_depth, node.revno,
 
491
                       node.end_of_merge)
489
492
        elif stop_rule == 'include':
490
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
491
 
                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)
492
497
                if rev_id == stop_revision_id:
493
498
                    return
494
499
        elif stop_rule == 'with-merges':
497
502
                left_parent = stop_rev.parent_ids[0]
498
503
            else:
499
504
                left_parent = _mod_revision.NULL_REVISION
500
 
            for rev_id, depth, revno, end_of_merge in rev_iter:
 
505
            for node in rev_iter:
 
506
                rev_id = node.key[-1]
501
507
                if rev_id == left_parent:
502
508
                    return
503
 
                yield rev_id, depth, revno, end_of_merge
 
509
                yield (rev_id, node.merge_depth, node.revno,
 
510
                       node.end_of_merge)
504
511
        else:
505
512
            raise ValueError('invalid stop_rule %r' % stop_rule)
506
513