~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-09-04 08:00:00 UTC
  • mto: (1981.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1982.
  • Revision ID: robertc@robertcollins.net-20060904080000-1152da5eed765694
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
693
693
            If the revision_id is a ghost, pass None for the tree.
694
694
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
695
695
        """
696
 
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]],
 
696
        parent_ids = self.get_parent_ids() + [parent_tuple[0]]
 
697
        if len(parent_ids) > 1:
 
698
            # the leftmost may have already been a ghost, preserve that if it
 
699
            # was.
 
700
            allow_leftmost_as_ghost = True
 
701
        self.set_parent_ids(parent_ids,
697
702
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
698
703
 
699
704
    @needs_write_lock
775
780
        my_file = rio_file(stanzas, header)
776
781
        self._control_files.put(filename, my_file)
777
782
 
 
783
    @needs_write_lock
 
784
    def merge_from_branch(self, branch, to_revision=None):
 
785
        """Merge from a branch into this working tree.
 
786
 
 
787
        :param branch: The branch to merge from.
 
788
        :param to_revision: If non-None, the merge will merge to to_revision, but 
 
789
            not beyond it. to_revision does not need to be in the history of
 
790
            the branch when it is supplied. If None, to_revision defaults to
 
791
            branch.last_revision().
 
792
        """
 
793
        from bzrlib.merge import Merger, Merge3Merger
 
794
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
795
        try:
 
796
            merger = Merger(self.branch, this_tree=self, pb=pb)
 
797
            merger.pp = ProgressPhase("Merge phase", 5, pb)
 
798
            merger.pp.next_phase()
 
799
            # check that there are no
 
800
            # local alterations
 
801
            merger.check_basis(check_clean=True, require_commits=False)
 
802
            if to_revision is None:
 
803
                to_revision = branch.last_revision()
 
804
            merger.other_rev_id = to_revision
 
805
            if merger.other_rev_id is None:
 
806
                raise error.NoCommits(branch)
 
807
            self.branch.fetch(branch, last_revision=merger.other_rev_id)
 
808
            merger.other_basis = merger.other_rev_id
 
809
            merger.other_tree = self.branch.repository.revision_tree(
 
810
                merger.other_rev_id)
 
811
            merger.pp.next_phase()
 
812
            merger.find_base()
 
813
            if merger.base_rev_id == merger.other_rev_id:
 
814
                raise errors.PointlessMerge
 
815
            merger.backup_files = False
 
816
            merger.merge_type = Merge3Merger
 
817
            merger.set_interesting_files(None)
 
818
            merger.show_base = False
 
819
            merger.reprocess = False
 
820
            conflicts = merger.do_merge()
 
821
            merger.set_pending()
 
822
        finally:
 
823
            pb.finished()
 
824
        return conflicts
 
825
 
778
826
    @needs_read_lock
779
827
    def merge_modified(self):
780
828
        try: