/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to revisionloader.py

smart caching of serialised inventories

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Parameterised loading of revisions into a repository."""
18
18
 
19
19
 
20
 
from bzrlib import errors
 
20
from bzrlib import errors, lru_cache
 
21
from bzrlib import revision as _mod_revision
21
22
 
22
23
 
23
24
class RevisionLoader(object):
60
61
        self._load_texts(rev.revision_id, inv.iter_entries(), parent_invs,
61
62
            text_provider)
62
63
        try:
63
 
            rev.inventory_sha1 = self.repo.add_inventory(rev.revision_id,
 
64
            rev.inventory_sha1 = self._add_inventory(rev.revision_id,
64
65
                inv, present_parents)
65
66
        except errors.RevisionAlreadyPresent:
66
67
            pass
111
112
            lines = text_provider(ie.file_id)
112
113
            vfile.add_lines(revision_id, text_parents, lines)
113
114
 
 
115
    def _add_inventory(self, revision_id, inv, parents):
 
116
        """Add the inventory inv to the repository as revision_id.
 
117
        
 
118
        :param parents: The revision ids of the parents that revision_id
 
119
                        is known to have and are in the repository already.
 
120
 
 
121
        :returns: The validator(which is a sha1 digest, though what is sha'd is
 
122
            repository format specific) of the serialized inventory.
 
123
        """
 
124
        return self.repo.add_inventory(revision_id, inv, parents)
 
125
 
114
126
    def _default_inventories_provider(self, revision_ids):
115
127
        """An inventories provider that queries the repository."""
116
128
        present = []
123
135
                rev_tree = self.repo.revision_tree(None)
124
136
            inventories.append(rev_tree.inventory)
125
137
        return present, inventories
 
138
 
 
139
 
 
140
class ImportRevisionLoader(RevisionLoader):
 
141
    """A RevisionLoader optimised for importing.
 
142
        
 
143
    This implementation allows caching of the serialised inventory texts.
 
144
    """
 
145
 
 
146
    def __init__(self, repo, inventories_provider=None, inv_parent_texts=None):
 
147
        """See RevisionLoader.__init__."""
 
148
        RevisionLoader.__init__(self, repo, inventories_provider)
 
149
        if inv_parent_texts is not None:
 
150
            self.inv_parent_texts = inv_parent_texts
 
151
        else:
 
152
            self.inv_parent_texts = {}
 
153
 
 
154
    def _add_inventory(self, revision_id, inv, parents):
 
155
        """See RevisionLoader._add_inventory."""
 
156
        # Code taken from bzrlib.repository.add_inventory
 
157
        assert self.repo.is_in_write_group()
 
158
        _mod_revision.check_not_reserved_id(revision_id)
 
159
        assert inv.revision_id is None or inv.revision_id == revision_id, \
 
160
            "Mismatch between inventory revision" \
 
161
            " id and insertion revid (%r, %r)" % (inv.revision_id, revision_id)
 
162
        assert inv.root is not None
 
163
        inv_lines = self.repo._serialise_inventory_to_lines(inv)
 
164
        inv_vf = self.repo.get_inventory_weave()
 
165
 
 
166
        # Code taken from bzrlib.repository._inventory_add_lines
 
167
        final_parents = []
 
168
        for parent in parents:
 
169
            if parent in inv_vf:
 
170
                final_parents.append(parent)
 
171
        sha1, num_bytes, parent_text = inv_vf.add_lines(revision_id,
 
172
            final_parents, inv_lines, self.inv_parent_texts,
 
173
            check_content=False)
 
174
        self.inv_parent_texts[revision_id] = parent_text
 
175
        return sha1