/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 fetch.py

Fix some places where we were way too much memory for repositories with a large number of entries in the inventory and a large number of revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from bzrlib import (
29
29
    debug,
 
30
    lru_cache,
30
31
    osutils,
31
32
    trace,
32
33
    ui,
43
44
    InventoryLink,
44
45
    TreeReference,
45
46
    )
46
 
from bzrlib.lru_cache import (
47
 
    LRUCache,
48
 
    )
49
47
from bzrlib.repository import (
50
48
    InterRepository,
51
49
    )
79
77
    )
80
78
 
81
79
 
 
80
MAX_INV_CACHE_SIZE = 50 * 1024 * 1024
 
81
 
 
82
 
82
83
def import_git_blob(texts, mapping, path, hexsha, base_inv, base_ie, parent_id,
83
84
    revision_id, parent_invs, shagitmap, lookup_object, executable, symlink):
84
85
    """Import a git blob object into a bzr repository.
282
283
    return invdelta, child_modes, shamap
283
284
 
284
285
 
 
286
def approx_inv_size(inv):
 
287
    # Very rough estimate, 1k per inventory entry
 
288
    return len(inv) * 1024
 
289
 
 
290
 
285
291
def import_git_objects(repo, mapping, object_iter, target_git_object_retriever,
286
292
        heads, pb=None):
287
293
    """Import a set of git objects into a bzr repository.
297
303
            return target_git_object_retriever[sha]
298
304
    # TODO: a more (memory-)efficient implementation of this
299
305
    graph = []
300
 
    root_trees = {}
301
 
    revisions = {}
302
306
    checked = set()
303
307
    heads = list(heads)
304
 
    parent_invs_cache = LRUCache(50)
 
308
    parent_invs_cache = lru_cache.LRUSizeCache(compute_size=approx_inv_size,
 
309
                                               max_size=MAX_INV_CACHE_SIZE)
305
310
    # Find and convert commit objects
306
311
    while heads:
307
312
        if pb is not None:
318
323
            if repo.has_revision(rev.revision_id):
319
324
                continue
320
325
            squash_revision(repo, rev)
321
 
            root_trees[rev.revision_id] = o.tree
322
 
            revisions[rev.revision_id] = rev
323
 
            graph.append((rev.revision_id, rev.parent_ids))
 
326
            graph.append((o.id, o.parents))
324
327
            target_git_object_retriever._idmap.add_entry(o.id, "commit",
325
328
                    (rev.revision_id, o.tree))
326
329
            heads.extend([p for p in o.parents if p not in checked])
328
331
            heads.append(o.object[1])
329
332
        else:
330
333
            trace.warning("Unable to import head object %r" % o)
331
 
        checked.add(head)
 
334
        checked.add(o.id)
 
335
    del checked
332
336
    # Order the revisions
333
337
    # Create the inventory objects
334
 
    for i, revid in enumerate(topo_sort(graph)):
 
338
    for i, head in enumerate(topo_sort(graph)):
335
339
        if pb is not None:
336
340
            pb.update("fetching revisions", i, len(graph))
337
 
        rev = revisions[revid]
 
341
        o = lookup_object(head)
 
342
        rev = mapping.import_commit(o)
338
343
        # We have to do this here, since we have to walk the tree and
339
344
        # we need to make sure to import the blobs / trees with the right
340
345
        # path; this may involve adding them more than once.
353
358
            base_inv = parent_invs[0]
354
359
            base_ie = base_inv.root
355
360
        inv_delta, unusual_modes, shamap = import_git_tree(repo.texts,
356
 
                mapping, "", root_trees[revid], base_inv, base_ie, None, revid,
 
361
                mapping, "", o.tree, base_inv, base_ie, None, rev.revision_id,
357
362
                parent_invs, target_git_object_retriever._idmap, lookup_object,
358
363
                allow_submodules=getattr(repo._format, "supports_tree_reference", False))
359
364
        target_git_object_retriever._idmap.add_entries(shamap)
378
383
            objs = inventory_to_tree_and_blobs(inv, repo.texts, mapping, unusual_modes)
379
384
            for sha1, newobj, path in objs:
380
385
                assert path is not None
381
 
                oldobj = tree_lookup_path(lookup_object, root_trees[revid], path)
 
386
                oldobj = tree_lookup_path(lookup_object, o.tree, path)
382
387
                if oldobj != newobj:
383
388
                    raise AssertionError("%r != %r in %s" % (oldobj, newobj, path))
384
389