~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Robey Pointer
  • Date: 2006-12-18 07:49:19 UTC
  • Revision ID: robey@lag.net-20061218074919-epu2so3jhu6b7zsm
don't bother to rebuild the cache when it's full

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
                p.branch_nick = p_change_dict[p.revid].branch_nick
376
376
            for p in change.merge_points:
377
377
                p.branch_nick = p_change_dict[p.revid].branch_nick
378
 
        
 
378
    
 
379
    @with_cache_lock
 
380
    def cache_full(self, get_diffs=False):
 
381
        if get_diffs:
 
382
            cache = self._change_cache_diffs
 
383
        else:
 
384
            cache = self._change_cache
 
385
        return len(cache) == len(self._full_history)
 
386
    
379
387
    @with_branch_lock
380
388
    def get_changes(self, revid_list, get_diffs=False):
381
389
        if self._change_cache is None:
517
525
        return entries
518
526
 
519
527
    @with_branch_lock
520
 
    def diff_revisions(self, revid, otherrevid, get_diffs=True):
521
 
        new_tree = self._branch.repository.revision_tree(revid)
522
 
        old_tree = self._branch.repository.revision_tree(otherrevid)
523
 
        delta = new_tree.changes_from(old_tree)
524
 
 
 
528
    def get_file(self, file_id, revision_id):
 
529
        "returns (filename, data)"
 
530
        inv_entry = self.get_inventory(revid)[file_id]
 
531
        rev_tree = self._branch.repository.revision_tree(inv_entry.revision)
 
532
        return inv_entry.name, rev_tree.get_file_text(file_id)
525
533
    
526
534
    @with_branch_lock
527
535
    def parse_delta(self, delta, get_diffs=True, old_tree=None, new_tree=None):
557
565
                path += '@'
558
566
            return path
559
567
        
560
 
        def tree_lines(tree, fid):
561
 
            if not fid in tree:
562
 
                return []
563
 
            tree_file = bzrlib.textfile.text_file(tree.get_file(fid))
564
 
            return tree_file.readlines()
565
 
        
566
568
        def process_diff(diff):
567
569
            chunks = []
568
570
            chunk = None
604
606
            if not get_diffs:
605
607
                modified.append(util.Container(filename=rich_filename(new_path, kind)))
606
608
                return
607
 
            old_lines = tree_lines(old_tree, fid)
608
 
            new_lines = tree_lines(new_tree, fid)
 
609
            old_lines = old_tree.get_file_lines(fid)
 
610
            new_lines = new_tree.get_file_lines(fid)
609
611
            buffer = StringIO()
610
612
            bzrlib.diff.internal_diff(old_path, old_lines, new_path, new_lines, buffer)
611
613
            diff = buffer.getvalue()
664
666
        
665
667
        file_revid = self.get_inventory(revid)[file_id].revision
666
668
        oldvalues = None
667
 
        revision_cache = {}
668
669
        
669
670
        # because we cache revision metadata ourselves, it's actually much
670
671
        # faster to call 'annotate_iter' on the weave directly than it is to
671
672
        # ask bzrlib to annotate for us.
672
673
        w = self._branch.repository.weave_store.get_weave(file_id, self._branch.repository.get_transaction())
 
674
        
 
675
        revid_set = set()
 
676
        for line_revid, text in w.annotate_iter(file_revid):
 
677
            revid_set.add(line_revid)
 
678
        change_cache = dict([(c.revid, c) for c in self.get_changes(list(revid_set))])
 
679
        
673
680
        last_line_revid = None
674
681
        for line_revid, text in w.annotate_iter(file_revid):
675
682
            if line_revid == last_line_revid:
679
686
                status = 'changed'
680
687
                parity ^= 1
681
688
                last_line_revid = line_revid
682
 
                change = revision_cache.get(line_revid, None)
683
 
                if change is None:
684
 
                    change = self.get_change(line_revid)
685
 
                    revision_cache[line_revid] = change
 
689
                change = change_cache[line_revid]
686
690
                trunc_revno = change.revno
687
691
                if len(trunc_revno) > 10:
688
692
                    trunc_revno = trunc_revno[:9] + '...'