/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

skip check re fulltext storage better than delta for inventories when in experimental mode

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, lru_cache
 
20
from bzrlib import errors, knit, lru_cache, osutils
21
21
from bzrlib import revision as _mod_revision
22
22
 
23
23
 
141
141
    This implementation caches serialised inventory texts.
142
142
    """
143
143
 
144
 
    def __init__(self, repo, parent_texts_to_cache=1):
 
144
    def __init__(self, repo, parent_texts_to_cache=1, random_ids=True):
145
145
        """See RevisionLoader.__init__.
146
146
 
147
147
        :param repository: the target repository
149
149
        """
150
150
        RevisionLoader.__init__(self, repo)
151
151
        self.inv_parent_texts = lru_cache.LRUCache(parent_texts_to_cache)
 
152
        self.random_ids = random_ids
152
153
 
153
154
    def _add_inventory(self, revision_id, inv, parents):
154
155
        """See RevisionLoader._add_inventory."""
162
163
        inv_lines = self.repo._serialise_inventory_to_lines(inv)
163
164
        inv_vf = self.repo.get_inventory_weave()
164
165
 
165
 
        # Code taken from bzrlib.repository._inventory_add_lines
 
166
        sha1, num_bytes, parent_text = self._inventory_add_lines(inv_vf,
 
167
            revision_id, parents, inv_lines, self.inv_parent_texts)
 
168
        self.inv_parent_texts[revision_id] = parent_text
 
169
        return sha1
 
170
 
 
171
    def _inventory_add_lines(self, inv_vf, version_id, parents, lines,
 
172
            parent_texts):
 
173
        """See Repository._inventory_add_lines()."""
166
174
        final_parents = []
167
175
        for parent in parents:
168
176
            if parent in inv_vf:
169
177
                final_parents.append(parent)
170
 
        sha1, num_bytes, parent_text = inv_vf.add_lines(revision_id,
171
 
            final_parents, inv_lines, self.inv_parent_texts,
172
 
            check_content=False)
173
 
        self.inv_parent_texts[revision_id] = parent_text
174
 
        return sha1
 
178
        return inv_vf.add_lines(version_id, final_parents, lines, parent_texts,
 
179
            random_id=self.random_ids, check_content=False)
 
180
 
 
181
 
 
182
class ExperimentalRevisionLoader(ImportRevisionLoader):
 
183
    """A RevisionLoader over optimised for importing.
 
184
        
 
185
    WARNING: This implementation uses undoumented bzrlib internals.
 
186
    It may not work in the future. In fact, it may not work now as
 
187
    it is a incubator for experimental code.
 
188
    """
 
189
 
 
190
    def __init__(self, repo, parent_texts_to_cache=1, fulltext_every=200):
 
191
        """See ImportRevisionLoader.__init__.
 
192
        
 
193
        :para fulltext_every: how often to store an inventory fulltext
 
194
        """
 
195
        ImportRevisionLoader.__init__(self, repo, parent_texts_to_cache)
 
196
        self.revision_count = 0
 
197
        self.fulltext_every = fulltext_every
 
198
 
 
199
    def _inventory_add_lines(self, inv_vf, version_id, parents, lines,
 
200
            parent_texts):
 
201
        """See Repository._inventory_add_lines()."""
 
202
        # setup parameters used in original code but not this API
 
203
        self.revision_count += 1
 
204
        if self.revision_count % self.fulltext_every == 0:
 
205
            delta = False
 
206
        else:
 
207
            delta = inv_vf.delta
 
208
        left_matching_blocks = None
 
209
        random_id = self.random_ids
 
210
        check_content = False
 
211
 
 
212
        # bzrlib.knit.add_lines() but error checking optimised
 
213
        inv_vf._check_add(version_id, lines, random_id, check_content)
 
214
 
 
215
        ####################################################################
 
216
        # bzrlib.knit._add() but skip checking if fulltext better than delta
 
217
        ####################################################################
 
218
 
 
219
        line_bytes = ''.join(lines)
 
220
        digest = osutils.sha_string(line_bytes)
 
221
        present_parents = []
 
222
        for parent in parents:
 
223
            if inv_vf.has_version(parent):
 
224
                present_parents.append(parent)
 
225
        if parent_texts is None:
 
226
            parent_texts = {}
 
227
 
 
228
        # can only compress against the left most present parent.
 
229
        if (delta and
 
230
            (len(present_parents) == 0 or
 
231
             present_parents[0] != parents[0])):
 
232
            delta = False
 
233
 
 
234
        text_length = len(line_bytes)
 
235
        options = []
 
236
        if lines:
 
237
            if lines[-1][-1] != '\n':
 
238
                # copy the contents of lines.
 
239
                lines = lines[:]
 
240
                options.append('no-eol')
 
241
                lines[-1] = lines[-1] + '\n'
 
242
                line_bytes += '\n'
 
243
 
 
244
        #if delta:
 
245
        #    # To speed the extract of texts the delta chain is limited
 
246
        #    # to a fixed number of deltas.  This should minimize both
 
247
        #    # I/O and the time spend applying deltas.
 
248
        #    delta = inv_vf._check_should_delta(present_parents)
 
249
 
 
250
        assert isinstance(version_id, str)
 
251
        content = inv_vf.factory.make(lines, version_id)
 
252
        if delta or (inv_vf.factory.annotated and len(present_parents) > 0):
 
253
            # Merge annotations from parent texts if needed.
 
254
            delta_hunks = inv_vf._merge_annotations(content, present_parents,
 
255
                parent_texts, delta, inv_vf.factory.annotated,
 
256
                left_matching_blocks)
 
257
 
 
258
        if delta:
 
259
            options.append('line-delta')
 
260
            store_lines = inv_vf.factory.lower_line_delta(delta_hunks)
 
261
            size, bytes = inv_vf._data._record_to_data(version_id, digest,
 
262
                store_lines)
 
263
        else:
 
264
            options.append('fulltext')
 
265
            # isinstance is slower and we have no hierarchy.
 
266
            if inv_vf.factory.__class__ == knit.KnitPlainFactory:
 
267
                # Use the already joined bytes saving iteration time in
 
268
                # _record_to_data.
 
269
                size, bytes = inv_vf._data._record_to_data(version_id, digest,
 
270
                    lines, [line_bytes])
 
271
            else:
 
272
                # get mixed annotation + content and feed it into the
 
273
                # serialiser.
 
274
                store_lines = inv_vf.factory.lower_fulltext(content)
 
275
                size, bytes = inv_vf._data._record_to_data(version_id, digest,
 
276
                    store_lines)
 
277
 
 
278
        access_memo = inv_vf._data.add_raw_records([size], bytes)[0]
 
279
        inv_vf._index.add_versions(
 
280
            ((version_id, options, access_memo, parents),),
 
281
            random_id=random_id)
 
282
        return digest, text_length, content