[MERGE] WorkingTree.merge_from_branch

Martin Pool mbp at canonical.com
Mon Sep 4 08:40:26 BST 2006


On  4 Sep 2006, Robert Collins <robertc at robertcollins.net> wrote:
> This patch adds a convenience method 'merge_from_branch' to WorkingTree.
> 
> I've added only the minimal functionality for now, but the plan is to
> extend this api with portions of merge_inner and builtins.merge that
> support library users. This is not a generic merge helper - its specific
> to the use case of 'merge_from_branch'.
> 
> I've converted the current code base's use of TestCase.merge to use this
> api, as its easier to understand and remember - I've also deprecated the
> TestCase helper function.


> === added file 'bzrlib/tests/workingtree_implementations/test_merge_from_branch.py'
> --- bzrlib/tests/workingtree_implementations/test_merge_from_branch.py	1970-01-01 00:00:00 +0000
> +++ bzrlib/tests/workingtree_implementations/test_merge_from_branch.py	2006-09-04 06:05:11 +0000
> @@ -0,0 +1,51 @@
> +# (C) 2006 Canonical Ltd
     ^ "Copyright"

> +# Authors:  Robert Collins <robert.collins at canonical.com>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +
> +"""Tests for the WorkingTree.merge_from_branch api."""
> +
> +from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
> +
> +
> +class TestMergeFromBranch(TestCaseWithWorkingTree):
> +
> +    def create_two_trees_for_merging(self):
> +        """Create two trees that can be merged from.
> +
> +        This sets self.tree_from, self.first_rev, self.tree_to, self.second_rev
> +        and self.to_second_rev.
> +        """
> +        self.tree_from = self.make_branch_and_tree('from')
> +        self.first_rev = self.tree_from.commit('first post')
> +        self.tree_to = self.tree_from.bzrdir.sprout('to').open_workingtree()
> +        self.second_rev = self.tree_from.commit('second rev', allow_pointless=True)
> +        self.to_second_rev = self.tree_to.commit('second rev', allow_pointless=True)
> +
> +    def test_smoking_merge(self):
> +        """Smoke test of merge_from_branch."""
> +        self.create_two_trees_for_merging()
> +        self.tree_to.merge_from_branch(self.tree_from.branch)
> +        self.assertEqual([self.to_second_rev, self.second_rev],
> +            self.tree_to.get_parent_ids())
> +
> +    def test_merge_to_revision(self):
> +        """Merge from a branch to a revision that is not the tip."""
> +        self.create_two_trees_for_merging()
> +        self.third_rev = self.tree_from.commit('real_tip')
> +        self.tree_to.merge_from_branch(self.tree_from.branch,
> +            to_revision=self.second_rev)
> +        self.assertEqual([self.to_second_rev, self.second_rev],
> +            self.tree_to.get_parent_ids())
> 
> === modified file 'bzrlib/errors.py'
> --- bzrlib/errors.py	2006-08-31 18:18:09 +0000
> +++ bzrlib/errors.py	2006-09-01 07:18:52 +0000
> @@ -967,6 +967,10 @@
>          DependencyNotPresent.__init__(self, 'paramiko', error)
>  
>  
> +class PointlessMerge(BzrNewError):
> +    """Nothing to merge."""
> +
> +

It might be more user friendly to say 

  "No new revisions to merge from %s into %s"

if that's practical.

> === modified file 'bzrlib/tests/blackbox/test_commit.py'
> --- bzrlib/tests/blackbox/test_commit.py	2006-07-28 16:05:23 +0000
> +++ bzrlib/tests/blackbox/test_commit.py	2006-09-04 06:37:13 +0000
> @@ -187,7 +187,7 @@
>              other_tree.commit('modify all sample files and dirs.')
>          finally:
>              other_tree.unlock()
> -        self.merge(other_tree.branch, this_tree)
> +        this_tree.merge_from_branch(other_tree.branch)
>          os.chdir('this')
>          out,err = self.run_bzr("commit", "-m", "added")
>          os.chdir('..')

(Golf clap (non-sarcastic))

> +    @needs_write_lock
> +    def merge_from_branch(self, branch, to_revision=None):
> +        """Merge from a branch.
                                 into this working tree.

> +
> +        :branch: The branch to merge from.
> +        :to_revision: If non-None, the merge will merge to to_revision, but 
> +            not beyond it. to_revision does not need to be in the history of
> +            the branch when it is supplied. If None, to_revision defaults to
> +            branch.last_revision().
> +        """

Shouldn't those be :param branch: etc?

+1

-- 
Martin




More information about the bazaar mailing list