~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Robey Pointer
  • Date: 2007-01-14 01:22:51 UTC
  • Revision ID: robey@lag.net-20070114012251-4r9icwoouak09zog
try john's idea of implementing _get_deltas_for_revisions_with_trees().
i don't think it helps a lot, but it's clearly less redundant.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
import bzrlib.annotate
48
48
import bzrlib.branch
49
49
import bzrlib.bundle.serializer
 
50
import bzrlib.decorators
50
51
import bzrlib.diff
51
52
import bzrlib.errors
52
53
import bzrlib.progress
592
593
        stats.sort()
593
594
        stats.freeze()
594
595
        cPickle.dump(stats, open('lsprof.stats', 'w'), 2)
 
596
        self.log.info('lsprof complete!')
595
597
        return ret
596
598
 
 
599
    def _get_deltas_for_revisions_with_trees(self, revisions):
 
600
        """Produce a generator of revision deltas.
 
601
        
 
602
        Note that the input is a sequence of REVISIONS, not revision_ids.
 
603
        Trees will be held in memory until the generator exits.
 
604
        Each delta is relative to the revision's lefthand predecessor.
 
605
        """
 
606
        required_trees = set()
 
607
        for revision in revisions:
 
608
            required_trees.add(revision.revision_id)
 
609
            required_trees.update(revision.parent_ids[:1])
 
610
        trees = dict((t.get_revision_id(), t) for 
 
611
                     t in self._branch.repository.revision_trees(required_trees))
 
612
        ret = []
 
613
        self._branch.repository.lock_read()
 
614
        try:
 
615
            for revision in revisions:
 
616
                if not revision.parent_ids:
 
617
                    old_tree = self._branch.repository.revision_tree(None)
 
618
                else:
 
619
                    old_tree = trees[revision.parent_ids[0]]
 
620
                tree = trees[revision.revision_id]
 
621
                ret.append((tree, old_tree, tree.changes_from(old_tree)))
 
622
            return ret
 
623
        finally:
 
624
            self._branch.repository.unlock()
 
625
    
597
626
    @with_branch_lock
598
627
    @with_bzrlib_read_lock
599
628
    def get_changes_uncached(self, revid_list, get_diffs=False):
602
631
        except (KeyError, bzrlib.errors.NoSuchRevision):
603
632
            return None
604
633
        
605
 
        delta_list = self._branch.repository.get_deltas_for_revisions(rev_list)
 
634
        delta_list = self._get_deltas_for_revisions_with_trees(rev_list)
606
635
        combined_list = zip(rev_list, delta_list)
607
636
        
608
 
        tree_map = {}
609
 
        if get_diffs:
610
 
            # lookup the trees for each revision, so we can calculate diffs
611
 
            lookup_set = set()
612
 
            for rev in rev_list:
613
 
                lookup_set.add(rev.revision_id)
614
 
                if len(rev.parent_ids) > 0:
615
 
                    lookup_set.add(rev.parent_ids[0])
616
 
            tree_map = dict((t.get_revision_id(), t) for t in self._branch.repository.revision_trees(lookup_set))
617
 
            # also the root tree, in case we hit the origin:
618
 
            tree_map[None] = self._branch.repository.revision_tree(None)
619
 
        
620
637
        entries = []
621
 
        for rev, delta in combined_list:
 
638
        for rev, (new_tree, old_tree, delta) in combined_list:
622
639
            commit_time = datetime.datetime.fromtimestamp(rev.timestamp)
623
640
            
624
641
            parents = [util.Container(revid=r, revno=self.get_revno(r)) for r in rev.parent_ids]
638
655
            if len(short_message) > 60:
639
656
                short_message = short_message[:60] + '...'
640
657
    
641
 
            old_tree, new_tree = None, None
642
 
            if get_diffs:
643
 
                new_tree = tree_map[rev.revision_id]
644
 
                old_tree = tree_map[left_parent]
645
 
 
646
658
            entry = {
647
659
                'revid': rev.revision_id,
648
660
                'revno': self.get_revno(rev.revision_id),