~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-06 20:48:00 UTC
  • mto: This revision was merged to the branch mainline in revision 4522.
  • Revision ID: john@arbash-meinel.com-20090706204800-twnc8rfatyaroi1s
Implement RevisionTree.annotate_iter and WT.annotate_iter
in terms of the new VF.get_annotator().
Only PreviewTree is left, though the logic there is yet-again different.
Also, feels like there are some missing tests, but I'll check on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    errors,
59
59
    generate_ids,
60
60
    globbing,
 
61
    graph as _mod_graph,
61
62
    hashcache,
62
63
    ignores,
63
64
    inventory,
477
478
        incorrectly attributed to CURRENT_REVISION (but after committing, the
478
479
        attribution will be correct).
479
480
        """
480
 
        basis = self.basis_tree()
481
 
        basis.lock_read()
482
 
        try:
483
 
            changes = self.iter_changes(basis, True, [self.id2path(file_id)],
484
 
                require_versioned=True).next()
485
 
            changed_content, kind = changes[2], changes[6]
486
 
            if not changed_content:
487
 
                return basis.annotate_iter(file_id)
488
 
            if kind[1] is None:
489
 
                return None
490
 
            from bzrlib import annotate
491
 
            if kind[0] != 'file':
492
 
                old_lines = []
493
 
            else:
494
 
                old_lines = list(basis.annotate_iter(file_id))
495
 
            old = [old_lines]
496
 
            for tree in self.branch.repository.revision_trees(
497
 
                self.get_parent_ids()[1:]):
498
 
                if file_id not in tree:
 
481
        maybe_file_parent_keys = []
 
482
        for parent_id in self.get_parent_ids():
 
483
            try:
 
484
                parent_tree = self.revision_tree(parent_id)
 
485
            except errors.NoSuchRevisionInTree:
 
486
                parent_tree = self.branch.repository.revision_tree(parent_id)
 
487
            parent_tree.lock_read()
 
488
            try:
 
489
                if file_id not in parent_tree:
499
490
                    continue
500
 
                old.append(list(tree.annotate_iter(file_id)))
501
 
            return annotate.reannotate(old, self.get_file(file_id).readlines(),
502
 
                                       default_revision)
503
 
        finally:
504
 
            basis.unlock()
 
491
                ie = parent_tree.inventory[file_id]
 
492
                parent_text_key = (file_id, ie.revision)
 
493
                if parent_text_key not in maybe_file_parent_keys:
 
494
                    maybe_file_parent_keys.append(parent_text_key)
 
495
            finally:
 
496
                parent_tree.unlock()
 
497
        graph = _mod_graph.Graph(self.branch.repository.texts)
 
498
        heads = graph.heads(maybe_file_parent_keys)
 
499
        file_parent_keys = []
 
500
        for key in maybe_file_parent_keys:
 
501
            if key in heads:
 
502
                file_parent_keys.append(key)
 
503
 
 
504
        # Now we have the parents of this content
 
505
        annotator = self.branch.repository.texts.get_annotator()
 
506
        text = self.get_file(file_id).read()
 
507
        this_key =(file_id, default_revision)
 
508
        annotator.add_special_text(this_key, file_parent_keys, text)
 
509
        annotations = [(key[-1], line)
 
510
                       for key, line in annotator.annotate_flat(this_key)]
 
511
        return annotations
505
512
 
506
513
    def _get_ancestors(self, default_revision):
507
514
        ancestors = set([default_revision])