/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 bzrlib/transform.py

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
997
997
        new_paths = self.new_paths()
998
998
        modified_paths = []
999
999
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1000
        completed_new = []
1000
1001
        try:
1001
1002
            for num, (path, trans_id) in enumerate(new_paths):
1002
1003
                new_entry = None
1019
1020
                            self.rename_count += 1
1020
1021
                    if trans_id in self._new_contents:
1021
1022
                        modified_paths.append(full_path)
1022
 
                        del self._new_contents[trans_id]
 
1023
                        completed_new.append(trans_id)
1023
1024
 
1024
1025
                if trans_id in self._new_id:
1025
1026
                    if kind is None:
1064
1065
                                            new_entry))
1065
1066
        finally:
1066
1067
            child_pb.finished()
 
1068
        for trans_id in completed_new:
 
1069
            del self._new_contents[trans_id]
1067
1070
        return modified_paths
1068
1071
 
1069
1072
    def _set_executability(self, path, entry, trans_id):
1319
1322
    return file_ids
1320
1323
 
1321
1324
 
1322
 
def build_tree(tree, wt):
 
1325
def build_tree(tree, wt, accelerator_tree=None):
1323
1326
    """Create working tree for a branch, using a TreeTransform.
1324
1327
    
1325
1328
    This function should be used on empty trees, having a tree root at most.
1332
1335
    - Otherwise, if the content on disk matches the content we are building,
1333
1336
      it is silently replaced.
1334
1337
    - Otherwise, conflict resolution will move the old file to 'oldname.moved'.
 
1338
 
 
1339
    :param tree: The tree to convert wt into a copy of
 
1340
    :param wt: The working tree that files will be placed into
 
1341
    :param accelerator_tree: A tree which can be used for retrieving file
 
1342
        contents more quickly than tree itself, i.e. a workingtree.  tree
 
1343
        will be used for cases where accelerator_tree's content is different.
1335
1344
    """
1336
1345
    wt.lock_tree_write()
1337
1346
    try:
1338
1347
        tree.lock_read()
1339
1348
        try:
1340
 
            return _build_tree(tree, wt)
 
1349
            if accelerator_tree is not None:
 
1350
                accelerator_tree.lock_read()
 
1351
            try:
 
1352
                return _build_tree(tree, wt, accelerator_tree)
 
1353
            finally:
 
1354
                if accelerator_tree is not None:
 
1355
                    accelerator_tree.unlock()
1341
1356
        finally:
1342
1357
            tree.unlock()
1343
1358
    finally:
1344
1359
        wt.unlock()
1345
1360
 
1346
1361
 
1347
 
def _build_tree(tree, wt):
 
1362
def _build_tree(tree, wt, accelerator_tree):
1348
1363
    """See build_tree."""
1349
1364
    if len(wt.inventory) > 1:  # more than just a root
1350
1365
        raise errors.WorkingTreeAlreadyPopulated(base=wt.basedir)
1421
1436
                    old_parent = tt.trans_id_tree_path(tree_path)
1422
1437
                    _reparent_children(tt, old_parent, new_trans_id)
1423
1438
            for num, (trans_id, bytes) in enumerate(
1424
 
                tree.iter_files_bytes(deferred_contents)):
 
1439
                _iter_files_bytes_accelerated(tree, accelerator_tree,
 
1440
                                              deferred_contents)):
1425
1441
                tt.create_file(bytes, trans_id)
1426
1442
                pb.update('Adding file contents',
1427
1443
                          (num + len(tree.inventory) - len(deferred_contents)),
1439
1455
            wt.add_conflicts(conflicts)
1440
1456
        except errors.UnsupportedOperation:
1441
1457
            pass
1442
 
        result = tt.apply()
 
1458
        result = tt.apply(no_conflicts=True)
1443
1459
    finally:
1444
1460
        tt.finalize()
1445
1461
        top_pb.finished()
1446
1462
    return result
1447
1463
 
1448
1464
 
 
1465
def _iter_files_bytes_accelerated(tree, accelerator_tree, desired_files):
 
1466
    if accelerator_tree is None:
 
1467
        new_desired_files = desired_files
 
1468
    else:
 
1469
        iter = accelerator_tree._iter_changes(tree, include_unchanged=True)
 
1470
        unchanged = dict((f, p[1]) for (f, p, c, v, d, n, k, e)
 
1471
                         in iter if not c)
 
1472
        new_desired_files = []
 
1473
        for file_id, identifier in desired_files:
 
1474
            accelerator_path = unchanged.get(file_id)
 
1475
            if accelerator_path is None:
 
1476
                new_desired_files.append((file_id, identifier))
 
1477
                continue
 
1478
            contents = accelerator_tree.get_file(file_id, accelerator_path)
 
1479
            try:
 
1480
                want_new = False
 
1481
                contents_bytes = (contents.read(),)
 
1482
            finally:
 
1483
                contents.close()
 
1484
            yield identifier, contents_bytes
 
1485
    for result in tree.iter_files_bytes(new_desired_files):
 
1486
        yield result
 
1487
 
 
1488
 
1449
1489
def _reparent_children(tt, old_parent, new_parent):
1450
1490
    for child in tt.iter_tree_children(old_parent):
1451
1491
        tt.adjust_path(tt.final_name(child), new_parent, child)