~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Michael Hudson
  • Date: 2009-03-19 19:31:22 UTC
  • mfrom: (308.1.9 sorry-rob)
  • Revision ID: michael.hudson@canonical.com-20090319193122-xcqbe62hkzyyuvvy
avoid loading inventories when possible for revision pages -- will be
unnecessary with the new chk formats, but for now for packs it can make things
10x faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
        return len(self.revid_list)
132
132
 
133
133
class FileChangeReporter(object):
134
 
    def __init__(self):
 
134
    def __init__(self, old_inv, new_inv):
135
135
        self.added = []
136
136
        self.modified = []
137
137
        self.renamed = []
138
138
        self.removed = []
139
139
        self.text_changes = []
 
140
        self.old_inv = old_inv
 
141
        self.new_inv = new_inv
 
142
 
 
143
    def revid(self, inv, file_id):
 
144
        try:
 
145
            return inv[file_id].revision
 
146
        except bzrlib.errors.NoSuchId:
 
147
            return 'null:'
 
148
 
140
149
    def report(self, file_id, paths, versioned, renamed, modified,
141
150
               exe_change, kind):
142
151
        if modified not in ('unchanged', 'kind changed'):
143
152
            self.text_changes.append(util.Container(
144
153
                filename=rich_filename(paths[1], kind[0]),
145
 
                file_id=file_id))
 
154
                file_id=file_id,
 
155
                old_revision=self.revid(self.old_inv, file_id),
 
156
                new_revision=self.revid(self.new_inv, file_id)))
146
157
        if versioned == 'added':
147
158
            self.added.append(util.Container(
148
159
                filename=rich_filename(paths[1], kind),
588
599
    def get_file_changes_uncached(self, entry):
589
600
        repo = self._branch.repository
590
601
        if entry.parents:
591
 
            old_tree = repo.revision_tree(entry.parents[0].revid)
 
602
            old_revid = entry.parents[0].revid
592
603
        else:
593
 
            old_tree = repo.revision_tree(bzrlib.revision.NULL_REVISION)
594
 
        new_tree = repo.revision_tree(entry.revid)
595
 
        return self.file_changes_from_revision_trees(old_tree, new_tree)
 
604
            old_revid = bzrlib.revision.NULL_REVISION
 
605
        return self.file_changes_for_revision_ids(old_revid, entry.revid)
596
606
 
597
607
    def get_file_changes(self, entry):
598
608
        if self._file_change_cache is None:
614
624
            path = '/' + path
615
625
        return path, inv_entry.name, rev_tree.get_file_text(file_id)
616
626
 
617
 
    def file_changes_from_revision_trees(self, old_tree, new_tree):
 
627
    def file_changes_for_revision_ids(self, old_revid, new_revid):
618
628
        """
619
629
        Return a nested data structure containing the changes in a delta::
620
630
 
627
637
            ),
628
638
            text_changes: list((filename, file_id)),
629
639
        """
630
 
        reporter = FileChangeReporter()
 
640
        repo = self._branch.repository
 
641
        if bzrlib.revision.is_null(old_revid) or \
 
642
               bzrlib.revision.is_null(new_revid):
 
643
            old_tree, new_tree = map(
 
644
                repo.revision_tree, [old_revid, new_revid])
 
645
        else:
 
646
            old_tree, new_tree = repo.revision_trees([old_revid, new_revid])
 
647
 
 
648
        reporter = FileChangeReporter(old_tree.inventory, new_tree.inventory)
631
649
 
632
650
        bzrlib.delta.report_changes(new_tree.iter_changes(old_tree), reporter)
633
651