~jamesh/bzr/pending-revprops

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

(robertc) Add WorkingTree parent-management apis - set_parent_trees, set_parent_ids, add_parent_tree, add_parent_tree_id.

Show diffs side-by-side

added added

removed removed

Lines of Context:
657
657
        self._write_inventory(inv)
658
658
 
659
659
    @needs_write_lock
 
660
    def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
 
661
        """Add revision_id as a parent.
 
662
 
 
663
        This is equivalent to retrieving the current list of parent ids
 
664
        and setting the list to its value plus revision_id.
 
665
 
 
666
        :param revision_id: The revision id to add to the parent list. It may
 
667
        be a ghost revision as long as its not the first parent to be added,
 
668
        or the allow_leftmost_as_ghost parameter is set True.
 
669
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
 
670
        """
 
671
        parents = self.get_parent_ids() + [revision_id]
 
672
        self.set_parent_ids(parents,
 
673
            allow_leftmost_as_ghost=len(parents) > 1 or allow_leftmost_as_ghost)
 
674
 
 
675
    @needs_write_lock
 
676
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
 
677
        """Add revision_id, tree tuple as a parent.
 
678
 
 
679
        This is equivalent to retrieving the current list of parent trees
 
680
        and setting the list to its value plus parent_tuple. See also
 
681
        add_parent_tree_id - if you only have a parent id available it will be
 
682
        simpler to use that api. If you have the parent already available, using
 
683
        this api is preferred.
 
684
 
 
685
        :param parent_tuple: The (revision id, tree) to add to the parent list.
 
686
            If the revision_id is a ghost, pass None for the tree.
 
687
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
 
688
        """
 
689
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]],
 
690
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
691
 
 
692
    @needs_write_lock
660
693
    def add_pending_merge(self, *revision_ids):
661
694
        # TODO: Perhaps should check at this point that the
662
695
        # history of the revision is actually present?
690
723
        return p
691
724
 
692
725
    @needs_write_lock
 
726
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
 
727
        """Set the parent ids to revision_ids.
 
728
        
 
729
        See also set_parent_trees. This api will try to retrieve the tree data
 
730
        for each element of revision_ids from the trees repository. If you have
 
731
        tree data already available, it is more efficient to use
 
732
        set_parent_trees rather than set_parent_ids. set_parent_ids is however
 
733
        an easier API to use.
 
734
 
 
735
        :param revision_ids: The revision_ids to set as the parent ids of this
 
736
            working tree. Any of these may be ghosts.
 
737
        """
 
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)
 
747
 
 
748
    @needs_write_lock
 
749
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
 
750
        """Set the parents of the working tree.
 
751
 
 
752
        :param parents_list: A list of (revision_id, tree) tuples. 
 
753
            If tree is None, then that element is treated as an unreachable
 
754
            parent tree - i.e. a ghost.
 
755
        """
 
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])
 
766
 
 
767
    @needs_write_lock
693
768
    def set_pending_merges(self, rev_list):
694
769
        if self.last_revision() is None:
695
770
            new_last_list = rev_list[:1]
1184
1259
        for regex, mapping in rules:
1185
1260
            match = regex.match(filename)
1186
1261
            if match is not None:
1187
 
                # one or more of the groups in mapping will have a non-None group 
1188
 
                # match.
 
1262
                # one or more of the groups in mapping will have a non-None
 
1263
                # group match.
1189
1264
                groups = match.groups()
1190
1265
                rules = [mapping[group] for group in 
1191
1266
                    mapping if groups[group] is not None]