/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

Avoid storing entries for trees in the cache, use blobs instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
205
205
    return ret
206
206
 
207
207
 
208
 
def import_git_tree(texts, mapping, path, hexsha, base_inv, base_ie, parent_id,
209
 
    revision_id, parent_invs, shagitmap, lookup_object, allow_submodules=False):
 
208
def import_git_tree(texts, mapping, path, hexsha, base_inv, base_inv_trees,
 
209
    base_ie, parent_id, revision_id, parent_invs, shagitmap, lookup_object,
 
210
    allow_submodules=False):
210
211
    """Import a git tree object into a bzr repository.
211
212
 
212
213
    :param texts: VersionedFiles object to add to
228
229
    else:
229
230
        # See if this has changed at all
230
231
        try:
231
 
            base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
 
232
            base_sha = base_inv_trees[file_id]
232
233
        except KeyError:
233
234
            pass
234
235
        else:
255
256
        if stat.S_ISDIR(mode):
256
257
            subinvdelta, grandchildmodes, subshamap = import_git_tree(
257
258
                    texts, mapping, child_path, child_hexsha, base_inv,
258
 
                    base_children.get(basename), file_id, revision_id,
259
 
                    parent_invs, shagitmap, lookup_object,
 
259
                    base_inv_trees, base_children.get(basename), file_id,
 
260
                    revision_id, parent_invs, shagitmap, lookup_object,
260
261
                    allow_submodules=allow_submodules)
261
262
            invdelta.extend(subinvdelta)
262
263
            child_modes.update(grandchildmodes)
294
295
 
295
296
 
296
297
def import_git_commit(repo, mapping, head, lookup_object,
297
 
                      target_git_object_retriever, parent_invs_cache):
 
298
                      target_git_object_retriever, parent_invs_cache,
 
299
                      parent_inv_trees_cache):
298
300
    o = lookup_object(head)
299
301
    rev = mapping.import_commit(o)
300
302
    # We have to do this here, since we have to walk the tree and
311
313
    if parent_invs == []:
312
314
        base_inv = Inventory(root_id=None)
313
315
        base_ie = None
 
316
        base_inv_trees = {}
314
317
    else:
315
318
        base_inv = parent_invs[0]
316
319
        base_ie = base_inv.root
 
320
        base_inv_trees = parent_inv_trees_cache.get(rev.parent_ids[0], {})
317
321
    inv_delta, unusual_modes, shamap = import_git_tree(repo.texts,
318
 
            mapping, "", o.tree, base_inv, base_ie, None, rev.revision_id,
319
 
            parent_invs, target_git_object_retriever._idmap, lookup_object,
 
322
            mapping, "", o.tree, base_inv, base_inv_trees, base_ie, None,
 
323
            rev.revision_id, parent_invs, target_git_object_retriever._idmap,
 
324
            lookup_object,
320
325
            allow_submodules=getattr(repo._format, "supports_tree_reference", False))
 
326
    parent_inv_trees_cache[rev.revision_id] = dict(base_inv_trees.iteritems())
 
327
    parent_inv_trees_cache[rev.revision_id].update(dict(
 
328
        ((key[0], hexsha) for (hexsha, kind, key) in shamap if kind == "tree")))
321
329
    target_git_object_retriever._idmap.add_entries(shamap)
322
330
    if unusual_modes != {}:
323
331
        for path, mode in unusual_modes.iteritems():
368
376
    heads = list(set(heads))
369
377
    parent_invs_cache = lru_cache.LRUSizeCache(compute_size=approx_inv_size,
370
378
                                               max_size=MAX_INV_CACHE_SIZE)
 
379
    parent_inv_trees_cache = lru_cache.LRUSizeCache(
 
380
        compute_size=approx_inv_size, max_size=MAX_INV_CACHE_SIZE)
371
381
    target_git_object_retriever.start_write_group() # FIXME: try/finally
372
382
    # Find and convert commit objects
373
383
    while heads:
411
421
                    pb.update("fetching revisions", offset+i, len(revision_ids))
412
422
                import_git_commit(repo, mapping, head, lookup_object,
413
423
                                  target_git_object_retriever,
414
 
                                  parent_invs_cache)
 
424
                                  parent_invs_cache, parent_inv_trees_cache)
415
425
                last_imported = head
416
426
        except:
417
427
            repo.abort_write_group()