~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-30 04:38:44 UTC
  • mfrom: (1908.6.14 use set_parent_trees.)
  • Revision ID: pqm@pqm.ubuntu.com-20060830043844-d570350402a5ad15
Use the new WorkingTree parent-management apis throughout the codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
491
491
            parents = []
492
492
        else:
493
493
            parents = [last_rev]
494
 
        other_parents = self.pending_merges()
495
 
        return parents + other_parents
 
494
        try:
 
495
            merges_file = self._control_files.get_utf8('pending-merges')
 
496
        except NoSuchFile:
 
497
            pass
 
498
        else:
 
499
            for l in merges_file.readlines():
 
500
                parents.append(l.rstrip('\n'))
 
501
        return parents
496
502
 
497
503
    def get_root_id(self):
498
504
        """Return the id of this trees root"""
532
538
        if revision_id is None:
533
539
            transform_tree(tree, self)
534
540
        else:
535
 
            # TODO now merge from tree.last_revision to revision
 
541
            # TODO now merge from tree.last_revision to revision (to preserve
 
542
            # user local changes)
536
543
            transform_tree(tree, self)
537
 
            tree.set_last_revision(revision_id)
 
544
            tree.set_parent_ids([revision_id])
538
545
 
539
546
    @needs_write_lock
540
547
    def commit(self, message=None, revprops=None, *args, **kwargs):
693
700
    def add_pending_merge(self, *revision_ids):
694
701
        # TODO: Perhaps should check at this point that the
695
702
        # history of the revision is actually present?
696
 
        p = self.pending_merges()
697
 
        existing_parents = self.get_parent_ids()
 
703
        parents = self.get_parent_ids()
698
704
        updated = False
699
705
        for rev_id in revision_ids:
700
 
            if rev_id in p:
701
 
                continue
702
 
            if rev_id in existing_parents:
703
 
                continue
704
 
            p.append(rev_id)
 
706
            if rev_id in parents:
 
707
                continue
 
708
            parents.append(rev_id)
705
709
            updated = True
706
710
        if updated:
707
 
            self.set_pending_merges(p)
 
711
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
708
712
 
709
713
    @needs_read_lock
710
714
    def pending_merges(self):
713
717
        These are revisions that have been merged into the working
714
718
        directory but not yet committed.
715
719
        """
716
 
        try:
717
 
            merges_file = self._control_files.get_utf8('pending-merges')
718
 
        except NoSuchFile:
719
 
            return []
720
 
        p = []
721
 
        for l in merges_file.readlines():
722
 
            p.append(l.rstrip('\n'))
723
 
        return p
 
720
        return self.get_parent_ids()[1:]
724
721
 
725
722
    @needs_write_lock
726
723
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
735
732
        :param revision_ids: The revision_ids to set as the parent ids of this
736
733
            working tree. Any of these may be ghosts.
737
734
        """
738
 
        trees = []
739
 
        for rev_id in revision_ids:
740
 
            try:
741
 
                trees.append(
742
 
                    (rev_id, self.branch.repository.revision_tree(rev_id)))
743
 
            except errors.RevisionNotPresent:
744
 
                trees.append((rev_id, None))
745
 
        self.set_parent_trees(trees,
746
 
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
735
        if len(revision_ids) > 0:
 
736
            leftmost_id = revision_ids[0]
 
737
            if (not allow_leftmost_as_ghost and not
 
738
                self.branch.repository.has_revision(leftmost_id)):
 
739
                raise errors.GhostRevisionUnusableHere(leftmost_id)
 
740
            self.set_last_revision(leftmost_id)
 
741
        else:
 
742
            self.set_last_revision(None)
 
743
        merges = revision_ids[1:]
 
744
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
747
745
 
748
746
    @needs_write_lock
749
747
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
753
751
            If tree is None, then that element is treated as an unreachable
754
752
            parent tree - i.e. a ghost.
755
753
        """
756
 
        if len(parents_list) > 0:
757
 
            leftmost_id = parents_list[0][0]
758
 
            if (not allow_leftmost_as_ghost and not
759
 
                self.branch.repository.has_revision(leftmost_id)):
760
 
                raise errors.GhostRevisionUnusableHere(leftmost_id)
761
 
            self.set_last_revision(leftmost_id)
762
 
        else:
763
 
            self.set_last_revision(None)
764
 
        merges = parents_list[1:]
765
 
        self.set_pending_merges([revid for revid, tree in merges])
 
754
        # parent trees are not used in current format trees, delegate to
 
755
        # set_parent_ids
 
756
        self.set_parent_ids([rev for (rev, tree) in parents_list],
 
757
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
766
758
 
767
759
    @needs_write_lock
768
760
    def set_pending_merges(self, rev_list):
769
 
        if self.last_revision() is None:
770
 
            new_last_list = rev_list[:1]
771
 
            rev_list = rev_list[1:]
772
 
            if new_last_list:
773
 
                self.set_last_revision(new_last_list[0])
774
 
        self._control_files.put_utf8('pending-merges', '\n'.join(rev_list))
 
761
        parents = self.get_parent_ids()
 
762
        leftmost = parents[:1]
 
763
        new_parents = leftmost + rev_list
 
764
        self.set_parent_ids(new_parents)
775
765
 
776
766
    @needs_write_lock
777
767
    def set_merge_modified(self, modified_hashes):
1092
1082
                repository = self.branch.repository
1093
1083
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
1094
1084
                try:
 
1085
                    new_basis_tree = self.branch.basis_tree()
1095
1086
                    merge_inner(self.branch,
1096
 
                                self.branch.basis_tree(),
1097
 
                                basis_tree, 
1098
 
                                this_tree=self, 
 
1087
                                new_basis_tree,
 
1088
                                basis_tree,
 
1089
                                this_tree=self,
1099
1090
                                pb=pb)
1100
1091
                finally:
1101
1092
                    pb.finished()
1102
 
                self.set_last_revision(self.branch.last_revision())
 
1093
                # TODO - dedup parents list with things merged by pull ?
 
1094
                # reuse the revisiontree we merged against to set the new
 
1095
                # tree data.
 
1096
                parent_trees = [(self.branch.last_revision(), new_basis_tree)]
 
1097
                # we have to pull the merge trees out again, because 
 
1098
                # merge_inner has set the ids. - this corner is not yet 
 
1099
                # layered well enough to prevent double handling.
 
1100
                merges = self.get_parent_ids()[1:]
 
1101
                parent_trees.extend([
 
1102
                    (parent, repository.revision_tree(parent)) for
 
1103
                     parent in merges])
 
1104
                self.set_parent_trees(parent_trees)
1103
1105
            return count
1104
1106
        finally:
1105
1107
            source.unlock()
1422
1424
            old_tree = self.basis_tree()
1423
1425
        conflicts = revert(self, old_tree, filenames, backups, pb)
1424
1426
        if not len(filenames):
1425
 
            self.set_pending_merges([])
 
1427
            self.set_parent_ids(self.get_parent_ids()[:1])
1426
1428
            resolve(self)
1427
1429
        else:
1428
1430
            resolve(self, filenames, ignore_misses=True)
1518
1520
                                  to_tree,
1519
1521
                                  basis,
1520
1522
                                  this_tree=self)
1521
 
            # when we have set_parent_ids/set_parent_trees we can
1522
 
            # set the pending merge from old tip here if needed.  We cant
1523
 
            # set a pending merge for old tip until we've changed the
1524
 
            # primary parent because it will typically have the same value.
1525
 
            try:
1526
 
                self.set_last_revision(self.branch.last_revision())
1527
 
            finally:
1528
 
                if old_tip is not None:
1529
 
                    self.add_pending_merge(old_tip)
 
1523
            # TODO - dedup parents list with things merged by pull ?
 
1524
            # reuse the tree we've updated to to set the basis:
 
1525
            parent_trees = [(self.branch.last_revision(), to_tree)]
 
1526
            merges = self.get_parent_ids()[1:]
 
1527
            # Ideally we ask the tree for the trees here, that way the working
 
1528
            # tree can decide whether to give us teh entire tree or give us a
 
1529
            # lazy initialised tree. dirstate for instance will have the trees
 
1530
            # in ram already, whereas a last-revision + basis-inventory tree
 
1531
            # will not, but also does not need them when setting parents.
 
1532
            for parent in merges:
 
1533
                parent_trees.append(
 
1534
                    (parent, self.branch.repository.revision_tree(parent)))
 
1535
            if old_tip is not None:
 
1536
                parent_trees.append(
 
1537
                    (old_tip, self.branch.repository.revision_tree(old_tip)))
 
1538
            self.set_parent_trees(parent_trees)
1530
1539
        else:
1531
1540
            # the working tree had the same last-revision as the master
1532
1541
            # branch did. We may still have pivot local work from the local
1533
1542
            # branch into old_tip:
1534
1543
            if old_tip is not None:
1535
 
                self.add_pending_merge(old_tip)
 
1544
                self.add_parent_tree_id(old_tip)
1536
1545
        if old_tip and old_tip != self.last_revision():
1537
1546
            # our last revision was not the prior branch last revision
1538
1547
            # and we have converted that last revision to a pending merge.
1816
1825
            finally:
1817
1826
                branch.unlock()
1818
1827
        revision = branch.last_revision()
1819
 
        inv = Inventory() 
 
1828
        inv = Inventory()
1820
1829
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
1821
1830
                         branch,
1822
1831
                         inv,
1825
1834
                         _bzrdir=a_bzrdir)
1826
1835
        wt._write_inventory(inv)
1827
1836
        wt.set_root_id(inv.root.file_id)
1828
 
        wt.set_last_revision(revision)
1829
 
        wt.set_pending_merges([])
1830
 
        build_tree(wt.basis_tree(), wt)
 
1837
        basis_tree = branch.repository.revision_tree(revision)
 
1838
        wt.set_parent_trees([(revision, basis_tree)])
 
1839
        build_tree(basis_tree, wt)
1831
1840
        return wt
1832
1841
 
1833
1842
    def __init__(self):
1907
1916
        try:
1908
1917
            wt._write_inventory(inv)
1909
1918
            wt.set_root_id(inv.root.file_id)
1910
 
            wt.set_last_revision(revision_id)
1911
 
            wt.set_pending_merges([])
1912
 
            build_tree(wt.basis_tree(), wt)
 
1919
            basis_tree = branch.repository.revision_tree(revision_id)
 
1920
            wt.set_parent_trees([(revision_id, basis_tree)])
 
1921
            build_tree(basis_tree, wt)
1913
1922
        finally:
1914
1923
            wt.unlock()
1915
1924
            control_files.unlock()