55
from bzrlib import bzrdir, errors, ignores, osutils, urlutils
55
from bzrlib import bzrdir, errors, ignores, osutils, urlutils, repository
56
56
from bzrlib.atomicfile import AtomicFile
57
57
import bzrlib.branch
58
58
from bzrlib.conflicts import Conflict, ConflictList, CONFLICT_SUFFIXES
842
842
other_tree.unlock()
843
843
other_tree.bzrdir.destroy_workingtree_metadata()
845
@needs_tree_write_lock
846
def extract(self, file_id):
847
"""Extract a subtree from this tree.
849
A new branch will be created, relative to the path for this tree.
851
sub_path = self.id2path(file_id)
852
branch_transport = self.branch.bzrdir.root_transport.clone(sub_path)
853
format = bzrdir.BzrDirMetaFormat1()
854
format.repository_format = repository.RepositoryFormatKnit2()
855
branch_bzrdir = format.initialize_on_transport(branch_transport)
857
repo = branch_bzrdir.find_repository()
858
except errors.NoRepositoryPresent:
859
repo = branch_bzrdir.create_repository()
860
assert repo.supports_rich_root()
862
if not repo.supports_rich_root():
864
new_branch = branch_bzrdir.create_branch()
865
for parent_id in self.get_parent_ids():
866
new_branch.fetch(self.branch, parent_id)
867
tree_transport = self.bzrdir.root_transport.clone(sub_path)
868
if tree_transport.base != branch_transport.base:
869
tree_bzrdir = format.initialize_on_transport(tree_transport)
870
# create branch reference
873
tree_bzrdir = branch_bzrdir
874
wt = tree_bzrdir.create_workingtree('null:')
875
wt.set_parent_ids(self.get_parent_ids())
876
my_inv = self.inventory
877
child_inv = Inventory(root_id=None)
878
new_root = my_inv[file_id]
879
my_inv.remove_recursive_id(file_id)
880
new_root.parent_id = None
881
child_inv.add(new_root)
882
self._write_inventory(my_inv)
883
wt._write_inventory(child_inv)
846
887
def merge_modified(self):