~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Aaron Bentley
  • Date: 2007-12-18 22:01:46 UTC
  • mto: This revision was merged to the branch mainline in revision 3135.
  • Revision ID: abentley@panoramicfeedback.com-20071218220146-xgb0g70vvu51z77o
Make build-tree able to use an additional 'accelerator' tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1322
1322
    return file_ids
1323
1323
 
1324
1324
 
1325
 
def build_tree(tree, wt):
 
1325
def build_tree(tree, wt, accelerator_tree=None):
1326
1326
    """Create working tree for a branch, using a TreeTransform.
1327
1327
    
1328
1328
    This function should be used on empty trees, having a tree root at most.
1340
1340
    try:
1341
1341
        tree.lock_read()
1342
1342
        try:
1343
 
            return _build_tree(tree, wt)
 
1343
            if accelerator_tree is not None:
 
1344
                accelerator_tree.lock_read()
 
1345
            try:
 
1346
                return _build_tree(tree, wt, accelerator_tree)
 
1347
            finally:
 
1348
                if accelerator_tree is not None:
 
1349
                    accelerator_tree.unlock()
1344
1350
        finally:
1345
1351
            tree.unlock()
1346
1352
    finally:
1347
1353
        wt.unlock()
1348
1354
 
1349
1355
 
1350
 
def _build_tree(tree, wt):
 
1356
def _build_tree(tree, wt, accelerator_tree):
1351
1357
    """See build_tree."""
1352
1358
    if len(wt.inventory) > 1:  # more than just a root
1353
1359
        raise errors.WorkingTreeAlreadyPopulated(base=wt.basedir)
1423
1429
                    new_trans_id = file_trans_id[file_id]
1424
1430
                    old_parent = tt.trans_id_tree_path(tree_path)
1425
1431
                    _reparent_children(tt, old_parent, new_trans_id)
 
1432
            if accelerator_tree is not None:
 
1433
                new_deferred_contents = []
 
1434
                for file_id, trans_id in deferred_contents:
 
1435
                    if (accelerator_tree.get_file_sha1(file_id) ==
 
1436
                        tree.get_file_sha1(file_id)):
 
1437
                        contents = accelerator_tree.get_file(file_id)
 
1438
                        try:
 
1439
                            tt.create_file(contents, trans_id)
 
1440
                        finally:
 
1441
                            contents.close()    
 
1442
                    else:
 
1443
                        new_deferred_contents.append((file_id, trans_id))
 
1444
                deferred_contents = new_deferred_contents
1426
1445
            for num, (trans_id, bytes) in enumerate(
1427
1446
                tree.iter_files_bytes(deferred_contents)):
1428
1447
                tt.create_file(bytes, trans_id)