/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

Cope with ghosts, cache inventories.

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,
31
30
    osutils,
32
31
    trace,
33
32
    ui,
66
65
    )
67
66
from bzrlib.plugins.git.object_store import (
68
67
    BazaarObjectStore,
 
68
    LRUInventoryCache,
69
69
    )
70
70
from bzrlib.plugins.git.remote import (
71
71
    RemoteGitRepository,
77
77
    )
78
78
 
79
79
 
80
 
MAX_INV_CACHE_SIZE = 50 * 1024 * 1024
81
 
 
82
 
 
83
80
def import_git_blob(texts, mapping, path, hexsha, base_inv, base_inv_shamap,
84
81
    base_ie, parent_id, revision_id, parent_invs, lookup_object,
85
82
    executable, symlink):
286
283
    return invdelta, child_modes, shamap
287
284
 
288
285
 
289
 
def approx_inv_size(inv):
290
 
    # Very rough estimate, 1k per inventory entry
291
 
    return len(inv) * 1024
292
 
 
293
 
 
294
286
def import_git_commit(repo, mapping, head, lookup_object,
295
287
                      target_git_object_retriever, parent_invs_cache):
296
288
    o = lookup_object(head)
298
290
    # We have to do this here, since we have to walk the tree and
299
291
    # we need to make sure to import the blobs / trees with the right
300
292
    # path; this may involve adding them more than once.
301
 
    parent_invs = []
302
 
    for parent_id in rev.parent_ids:
303
 
        try:
304
 
            parent_invs.append(parent_invs_cache[parent_id])
305
 
        except KeyError:
306
 
            parent_inv = repo.get_inventory(parent_id)
307
 
            parent_invs.append(parent_inv)
308
 
            parent_invs_cache[parent_id] = parent_inv
 
293
    parent_invs = parent_invs_cache.get_inventories(rev.parent_ids)
309
294
    if parent_invs == []:
310
295
        base_inv = Inventory(root_id=None)
311
296
        base_ie = None
343
328
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
344
329
              inv_delta, rev.revision_id, rev.parent_ids,
345
330
              base_inv)
346
 
    parent_invs_cache[rev.revision_id] = inv
 
331
    parent_invs_cache.add(rev.revision_id, inv)
347
332
    repo.add_revision(rev.revision_id, rev)
348
333
    if "verify" in debug.debug_flags:
349
334
        new_unusual_modes = mapping.export_unusual_file_modes(rev)
378
363
    graph = []
379
364
    checked = set()
380
365
    heads = list(set(heads))
381
 
    parent_invs_cache = lru_cache.LRUSizeCache(compute_size=approx_inv_size,
382
 
                                               max_size=MAX_INV_CACHE_SIZE)
 
366
    parent_invs_cache = LRUInventoryCache(repo)
383
367
    target_git_object_retriever.start_write_group() # FIXME: try/finally
384
368
    # Find and convert commit objects
385
369
    while heads: