Rev 3528: Test that the lca_trees are passed down to the Merger object when appropriate. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/merge_lca_multi
John Arbash Meinel
john at arbash-meinel.com
Tue Jul 22 16:45:20 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/merge_lca_multi
------------------------------------------------------------
revno: 3528
revision-id: john at arbash-meinel.com-20080722154417-qoc7kmrv0i4orptm
parent: john at arbash-meinel.com-20080722143903-0pp0c0calpmaj3k6
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: merge_lca_multi
timestamp: Tue 2008-07-22 10:44:17 -0500
message:
Test that the lca_trees are passed down to the Merger object when appropriate.
-------------- next part --------------
=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py 2008-07-22 02:15:04 +0000
+++ b/bzrlib/merge.py 2008-07-22 15:44:17 +0000
@@ -425,6 +425,9 @@
if self.merge_type.supports_cherrypick:
kwargs['cherrypick'] = (not self.base_is_ancestor or
not self.base_is_other_ancestor)
+ if self._is_criss_cross and getattr(self.merge_type,
+ 'supports_lca_trees', False):
+ kwargs['lca_trees'] = self._lca_trees
return self.merge_type(pb=self._pb,
change_reporter=self.change_reporter,
**kwargs)
@@ -479,12 +482,13 @@
supports_cherrypick = True
supports_reverse_cherrypick = True
winner_idx = {"this": 2, "other": 1, "conflict": 1}
+ supports_lca_trees = True
def __init__(self, working_tree, this_tree, base_tree, other_tree,
interesting_ids=None, reprocess=False, show_base=False,
pb=DummyProgress(), pp=None, change_reporter=None,
interesting_files=None, do_merge=True,
- cherrypick=False):
+ cherrypick=False, lca_trees=None):
"""Initialize the merger object and perform the merge.
:param working_tree: The working tree to apply the merge to
@@ -506,6 +510,9 @@
be combined with interesting_ids. If neither interesting_files nor
interesting_ids is specified, all files may participate in the
merge.
+ :param lca_trees: Can be set to a dictionary of {revision_id:rev_tree}
+ if the ancestry was found to include a criss-cross merge.
+ Otherwise should be None.
"""
object.__init__(self)
if interesting_files is not None and interesting_ids is not None:
@@ -520,6 +527,7 @@
self.cooked_conflicts = []
self.reprocess = reprocess
self.show_base = show_base
+ self._lca_trees = lca_trees
self.pb = pb
self.pp = pp
self.change_reporter = change_reporter
=== modified file 'bzrlib/tests/test_merge.py'
--- a/bzrlib/tests/test_merge.py 2008-07-22 14:39:03 +0000
+++ b/bzrlib/tests/test_merge.py 2008-07-22 15:44:17 +0000
@@ -710,53 +710,118 @@
merge_type = _mod_merge.LCAMerger
+class LoggingMerger(object):
+ # These seem to be the required attributes
+ requires_base = False
+ supports_reprocess = False
+ supports_show_base = False
+ supports_cherrypick = False
+ # We intentionally do not define supports_lca_trees
+
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+
class TestMergerInMemory(TestCaseWithMemoryTransport):
"""Tests for Merger that can be done without hitting disk."""
- def test_find_base(self):
- # A
- # |\
- # B C
- tree = self.make_branch_and_memory_tree('tree')
- tree.lock_write()
- self.addCleanup(tree.unlock)
- tree.add('.')
- tree.commit('A', rev_id='A-id')
- tree.commit('C', rev_id='C-id')
- tree.set_parent_ids(['A-id'])
- tree.branch.set_last_revision_info(1, 'A-id')
- tree.commit('B', rev_id='B-id')
-
- merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
- tree, 'C-id')
- self.assertEqual('A-id', merger.base_rev_id)
- self.assertFalse(merger._is_criss_cross)
- self.assertIs(None, merger._lca_trees)
-
- def test_find_base_criss_cross(self):
- # A
- # |\
- # B C
- # |X|
- # D E
- tree = self.make_branch_and_memory_tree('tree')
- tree.lock_write()
- self.addCleanup(tree.unlock)
-
- tree.add('.')
- tree.commit('A', rev_id='A-id')
- tree.commit('B', rev_id='B-id')
- tree.set_parent_ids(['A-id'])
- tree.branch.set_last_revision_info(1, 'A-id')
- tree.commit('C', rev_id='C-id')
+ def setup_simple_graph(self):
+ """Create a simple 3-node graph.
+ A
+ |\\
+ B C
+
+ :return: A MemoryTree which is already write-locked, and an unlock has
+ been queued up.
+ """
+ tree = self.make_branch_and_memory_tree('tree')
+ tree.lock_write()
+ self.addCleanup(tree.unlock)
+ tree.add('.')
+ tree.commit('A', rev_id='A-id')
+ tree.commit('C', rev_id='C-id')
+ tree.set_parent_ids(['A-id'])
+ tree.branch.set_last_revision_info(1, 'A-id')
+ tree.commit('B', rev_id='B-id')
+ return tree
+
+ def setup_criss_cross_graph(self):
+ """Create a 5-node graph with a criss-cross.
+ A
+ |\\
+ B C
+ |X|
+ D E
+ :return: A write locked Memory Tree
+ """
+ tree = self.setup_simple_graph()
+ tree.branch.set_last_revision_info(2, 'C-id')
tree.set_parent_ids(['C-id', 'B-id'])
tree.commit('E', rev_id='E-id')
tree.set_parent_ids(['B-id', 'C-id'])
tree.branch.set_last_revision_info(2, 'B-id')
tree.commit('D', rev_id='D-id')
-
+ return tree
+
+ def test_find_base(self):
+ tree = self.setup_simple_graph()
+ merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
+ tree, 'C-id')
+ self.assertEqual('A-id', merger.base_rev_id)
+ self.assertFalse(merger._is_criss_cross)
+ self.assertIs(None, merger._lca_trees)
+
+
+ def test_find_base_criss_cross(self):
+ tree = self.setup_criss_cross_graph()
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
tree, 'E-id')
self.assertEqual('A-id', merger.base_rev_id)
self.assertTrue(merger._is_criss_cross)
self.assertEqual(['B-id', 'C-id'], sorted(merger._lca_trees.keys()))
+
+ def test_no_criss_cross_passed_to_merge_type(self):
+ class LCATreesMerger(LoggingMerger):
+ supports_lca_trees = True
+
+ tree = self.setup_simple_graph()
+ merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
+ tree, 'C-id')
+ merger.merge_type = LCATreesMerger
+ merge_obj = merger.make_merger()
+ self.assertIsInstance(merge_obj, LCATreesMerger)
+ self.assertFalse('lca_trees' in merge_obj.kwargs)
+
+ def test_criss_cross_passed_to_merge_type(self):
+ tree = self.setup_criss_cross_graph()
+ merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
+ tree, 'E-id')
+ merger.merge_type = _mod_merge.Merge3Merger
+ merge_obj = merger.make_merger()
+ self.assertEqual(['B-id', 'C-id'], sorted(merge_obj._lca_trees.keys()))
+
+ def test_criss_cross_not_supported_merge_type(self):
+ class NoLCATreesMerger(LoggingMerger):
+ # We intentionally do not define supports_lca_trees
+ pass
+
+ tree = self.setup_criss_cross_graph()
+ merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
+ tree, 'E-id')
+ merger.merge_type = NoLCATreesMerger
+ merge_obj = merger.make_merger()
+ self.assertIsInstance(merge_obj, NoLCATreesMerger)
+ self.assertFalse('lca_trees' in merge_obj.kwargs)
+
+ def test_criss_cross_unsupported_merge_type(self):
+ class UnsupportedLCATreesMerger(LoggingMerger):
+ supports_lca_trees = False
+
+ tree = self.setup_criss_cross_graph()
+ merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
+ tree, 'E-id')
+ merger.merge_type = UnsupportedLCATreesMerger
+ merge_obj = merger.make_merger()
+ self.assertIsInstance(merge_obj, UnsupportedLCATreesMerger)
+ self.assertFalse('lca_trees' in merge_obj.kwargs)
More information about the bazaar-commits
mailing list