Пример #1
0
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
                   accelerator_tree=None, hardlink=False):
        """See WorkingTreeFormat.initialize().

        :param revision_id: if supplied, create a working tree at a different
            revision than the branch is at.
        :param accelerator_tree: A tree which can be used for retrieving file
            contents more quickly than the revision tree, i.e. a workingtree.
            The revision tree will be used for cases where accelerator_tree's
            content is different.
        :param hardlink: If true, hard-link files from accelerator_tree,
            where possible.
        """
        if not isinstance(a_bzrdir.transport, LocalTransport):
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
        transport = a_bzrdir.get_workingtree_transport(self)
        control_files = self._open_control_files(a_bzrdir)
        control_files.create_lock()
        control_files.lock_write()
        transport.put_bytes('format', self.as_string(),
            mode=a_bzrdir._get_file_mode())
        if from_branch is not None:
            branch = from_branch
        else:
            branch = a_bzrdir.open_branch()
        if revision_id is None:
            revision_id = _mod_revision.ensure_null(branch.last_revision())
        # WorkingTree3 can handle an inventory which has a unique root id.
        # as of bzr 0.12. However, bzr 0.11 and earlier fail to handle
        # those trees. And because there isn't a format bump inbetween, we
        # are maintaining compatibility with older clients.
        # inv = Inventory(root_id=gen_root_id())
        inv = self._initial_inventory()
        wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
                         branch,
                         inv,
                         _internal=True,
                         _format=self,
                         _bzrdir=a_bzrdir,
                         _control_files=control_files)
        wt.lock_tree_write()
        try:
            basis_tree = branch.repository.revision_tree(revision_id)
            # only set an explicit root id if there is one to set.
            if basis_tree.get_root_id() is not None:
                wt.set_root_id(basis_tree.get_root_id())
            if revision_id == _mod_revision.NULL_REVISION:
                wt.set_parent_trees([])
            else:
                wt.set_parent_trees([(revision_id, basis_tree)])
            transform.build_tree(basis_tree, wt)
            for hook in MutableTree.hooks['post_build_tree']:
                hook(wt)
        finally:
            # Unlock in this order so that the unlock-triggers-flush in
            # WorkingTree is given a chance to fire.
            control_files.unlock()
            wt.unlock()
        return wt
Пример #2
0
 def initialize(self,
                a_bzrdir,
                revision_id=None,
                from_branch=None,
                accelerator_tree=None,
                hardlink=False):
     """See WorkingTreeFormat.initialize()."""
     if not isinstance(a_bzrdir.transport, LocalTransport):
         raise errors.NotLocalUrl(a_bzrdir.transport.base)
     if from_branch is not None:
         branch = from_branch
     else:
         branch = a_bzrdir.open_branch()
     if revision_id is None:
         revision_id = _mod_revision.ensure_null(branch.last_revision())
     branch.lock_write()
     try:
         branch.generate_revision_history(revision_id)
     finally:
         branch.unlock()
     inv = inventory.Inventory()
     wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
                       branch,
                       inv,
                       _internal=True,
                       _format=self,
                       _bzrdir=a_bzrdir,
                       _control_files=branch.control_files)
     basis_tree = branch.repository.revision_tree(revision_id)
     if basis_tree.get_root_id() is not None:
         wt.set_root_id(basis_tree.get_root_id())
     # set the parent list and cache the basis tree.
     if _mod_revision.is_null(revision_id):
         parent_trees = []
     else:
         parent_trees = [(revision_id, basis_tree)]
     wt.set_parent_trees(parent_trees)
     transform.build_tree(basis_tree, wt)
     for hook in MutableTree.hooks['post_build_tree']:
         hook(wt)
     return wt
Пример #3
0
 def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
                accelerator_tree=None, hardlink=False):
     """See WorkingTreeFormat.initialize()."""
     if not isinstance(a_bzrdir.transport, LocalTransport):
         raise errors.NotLocalUrl(a_bzrdir.transport.base)
     if from_branch is not None:
         branch = from_branch
     else:
         branch = a_bzrdir.open_branch()
     if revision_id is None:
         revision_id = _mod_revision.ensure_null(branch.last_revision())
     branch.lock_write()
     try:
         branch.generate_revision_history(revision_id)
     finally:
         branch.unlock()
     inv = inventory.Inventory()
     wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
                      branch,
                      inv,
                      _internal=True,
                      _format=self,
                      _bzrdir=a_bzrdir,
                      _control_files=branch.control_files)
     basis_tree = branch.repository.revision_tree(revision_id)
     if basis_tree.get_root_id() is not None:
         wt.set_root_id(basis_tree.get_root_id())
     # set the parent list and cache the basis tree.
     if _mod_revision.is_null(revision_id):
         parent_trees = []
     else:
         parent_trees = [(revision_id, basis_tree)]
     wt.set_parent_trees(parent_trees)
     transform.build_tree(basis_tree, wt)
     for hook in MutableTree.hooks['post_build_tree']:
         hook(wt)
     return wt