~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
 
166
166
def gen_root_id():
167
167
    """Return a new tree-root file id."""
168
 
    return gen_file_id('TREE_ROOT')
 
168
    return gen_file_id('tree_root')
169
169
 
170
170
 
171
171
class TreeEntry(object):
554
554
    @needs_read_lock
555
555
    def copy_content_into(self, tree, revision_id=None):
556
556
        """Copy the current content and user files of this tree into tree."""
 
557
        tree.set_root_id(self.get_root_id())
557
558
        if revision_id is None:
558
559
            merge.transform_tree(tree, self)
559
560
        else:
1188
1189
                                basis_tree,
1189
1190
                                this_tree=self,
1190
1191
                                pb=pb)
 
1192
                    if (basis_tree.inventory.root is None and
 
1193
                        new_basis_tree.inventory.root is not None):
 
1194
                        self.set_root_id(new_basis_tree.inventory.root.file_id)
1191
1195
                finally:
1192
1196
                    pb.finished()
1193
1197
                # TODO - dedup parents list with things merged by pull ?
1641
1645
    def update(self):
1642
1646
        """Update a working tree along its branch.
1643
1647
 
1644
 
        This will update the branch if its bound too, which means we have multiple trees involved:
1645
 
        The new basis tree of the master.
1646
 
        The old basis tree of the branch.
1647
 
        The old basis tree of the working tree.
1648
 
        The current working tree state.
1649
 
        pathologically all three may be different, and non ancestors of each other.
1650
 
        Conceptually we want to:
1651
 
        Preserve the wt.basis->wt.state changes
1652
 
        Transform the wt.basis to the new master basis.
1653
 
        Apply a merge of the old branch basis to get any 'local' changes from it into the tree.
1654
 
        Restore the wt.basis->wt.state changes.
 
1648
        This will update the branch if its bound too, which means we have
 
1649
        multiple trees involved:
 
1650
 
 
1651
        - The new basis tree of the master.
 
1652
        - The old basis tree of the branch.
 
1653
        - The old basis tree of the working tree.
 
1654
        - The current working tree state.
 
1655
 
 
1656
        Pathologically, all three may be different, and non-ancestors of each
 
1657
        other.  Conceptually we want to:
 
1658
 
 
1659
        - Preserve the wt.basis->wt.state changes
 
1660
        - Transform the wt.basis to the new master basis.
 
1661
        - Apply a merge of the old branch basis to get any 'local' changes from
 
1662
          it into the tree.
 
1663
        - Restore the wt.basis->wt.state changes.
1655
1664
 
1656
1665
        There isn't a single operation at the moment to do that, so we:
1657
 
        Merge current state -> basis tree of the master w.r.t. the old tree basis.
1658
 
        Do a 'normal' merge of the old branch basis if it is relevant.
 
1666
        - Merge current state -> basis tree of the master w.r.t. the old tree
 
1667
          basis.
 
1668
        - Do a 'normal' merge of the old branch basis if it is relevant.
1659
1669
        """
1660
1670
        old_tip = self.branch.update()
 
1671
 
1661
1672
        # here if old_tip is not None, it is the old tip of the branch before
1662
1673
        # it was updated from the master branch. This should become a pending
1663
1674
        # merge in the working tree to preserve the user existing work.  we
1677
1688
            # merge tree state up to new branch tip.
1678
1689
            basis = self.basis_tree()
1679
1690
            to_tree = self.branch.basis_tree()
 
1691
            if basis.inventory.root is None:
 
1692
                self.set_root_id(to_tree.inventory.root.file_id)
1680
1693
            result += merge.merge_inner(
1681
1694
                                  self.branch,
1682
1695
                                  to_tree,
2014
2027
                         _internal=True,
2015
2028
                         _format=self,
2016
2029
                         _bzrdir=a_bzrdir)
2017
 
        wt.set_root_id(inv.root.file_id)
2018
2030
        basis_tree = branch.repository.revision_tree(revision)
 
2031
        if basis_tree.inventory.root is not None:
 
2032
            wt.set_root_id(basis_tree.inventory.root.file_id)
 
2033
        # set the parent list and cache the basis tree.
2019
2034
        wt.set_parent_trees([(revision, basis_tree)])
2020
2035
        transform.build_tree(basis_tree, wt)
2021
2036
        return wt
2085
2100
        branch = a_bzrdir.open_branch()
2086
2101
        if revision_id is None:
2087
2102
            revision_id = branch.last_revision()
2088
 
        inv = Inventory()
 
2103
        inv = Inventory(root_id=gen_root_id())
2089
2104
        wt = WorkingTree3(a_bzrdir.root_transport.local_abspath('.'),
2090
2105
                         branch,
2091
2106
                         inv,
2095
2110
                         _control_files=control_files)
2096
2111
        wt.lock_tree_write()
2097
2112
        try:
2098
 
            wt.set_root_id(inv.root.file_id)
2099
2113
            basis_tree = branch.repository.revision_tree(revision_id)
 
2114
            # only set an explicit root id if there is one to set.
 
2115
            if basis_tree.inventory.root is not None:
 
2116
                wt.set_root_id(basis_tree.inventory.root.file_id)
2100
2117
            if revision_id == NULL_REVISION:
2101
2118
                wt.set_parent_trees([])
2102
2119
            else: