~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
500
500
            plan._get_matching_blocks('B', 'C')),
501
501
            ([1, 2, 3], [0, 2]))
502
502
 
503
 
    def test_find_new(self):
504
 
        plan = self.setup_plan_merge()
505
 
        self.assertEqual(set([2, 3, 4]), plan._find_new('B'))
506
 
        self.assertEqual(set([0, 3]), plan._find_new('C'))
507
 
 
508
 
    def test_find_new2(self):
 
503
    def test_plan_merge_cherrypick(self):
509
504
        self.add_version(('root', 'A'), [], 'abc')
510
505
        self.add_version(('root', 'B'), [('root', 'A')], 'abcde')
511
506
        self.add_version(('root', 'C'), [('root', 'A')], 'abcefg')
512
507
        self.add_version(('root', 'D'),
513
508
            [('root', 'A'), ('root', 'B'), ('root', 'C')], 'abcdegh')
514
509
        my_plan = _PlanMerge('B', 'D', self.plan_merge_vf, ('root',))
515
 
        self.assertEqual(set([5, 6]), my_plan._find_new('D'))
516
 
        self.assertEqual(set(), my_plan._find_new('A'))
 
510
        self.assertEqual([
 
511
                          ('unchanged', 'a\n'),
 
512
                          ('unchanged', 'b\n'),
 
513
                          ('unchanged', 'c\n'),
 
514
                          ('unchanged', 'd\n'),
 
515
                          ('unchanged', 'e\n'),
 
516
                          ('new-b', 'g\n'),
 
517
                          ('new-b', 'h\n')],
 
518
                          list(my_plan.plan_merge()))
517
519
 
518
 
    def test_find_new_no_ancestors(self):
 
520
    def test_plan_merge_no_common_ancestor(self):
519
521
        self.add_version(('root', 'A'), [], 'abc')
520
522
        self.add_version(('root', 'B'), [], 'xyz')
521
 
        my_plan = _PlanMerge('A', 'B', self.vf, ('root',))
522
 
        self.assertEqual(set([0, 1, 2]), my_plan._find_new('A'))
 
523
        my_plan = _PlanMerge('A', 'B', self.plan_merge_vf, ('root',))
 
524
        self.assertEqual([
 
525
                          ('new-a', 'a\n'),
 
526
                          ('new-a', 'b\n'),
 
527
                          ('new-a', 'c\n'),
 
528
                          ('new-b', 'x\n'),
 
529
                          ('new-b', 'y\n'),
 
530
                          ('new-b', 'z\n')],
 
531
                          list(my_plan.plan_merge()))
523
532
 
524
533
    def test_plan_merge(self):
525
534
        self.setup_plan_merge()
527
536
        self.assertEqual([
528
537
                          ('new-b', 'f\n'),
529
538
                          ('unchanged', 'a\n'),
 
539
                          ('killed-a', 'b\n'),
530
540
                          ('killed-b', 'c\n'),
531
541
                          ('new-a', 'e\n'),
532
542
                          ('new-a', 'h\n'),
533
 
                          ('killed-a', 'b\n'),
534
 
                          ('unchanged', 'g\n')],
 
543
                          ('new-a', 'g\n'),
 
544
                          ('new-b', 'g\n')],
535
545
                         list(plan))
536
546
 
537
547
    def test_plan_merge_uncommitted_files(self):
540
550
        self.assertEqual([
541
551
                          ('new-b', 'f\n'),
542
552
                          ('unchanged', 'a\n'),
 
553
                          ('killed-a', 'b\n'),
543
554
                          ('killed-b', 'c\n'),
544
555
                          ('new-a', 'e\n'),
545
556
                          ('new-a', 'h\n'),
546
 
                          ('killed-a', 'b\n'),
547
 
                          ('unchanged', 'g\n')],
 
557
                          ('new-a', 'g\n'),
 
558
                          ('new-b', 'g\n')],
548
559
                         list(plan))
549
560
 
550
561
    def test_subtract_plans(self):
662
673
        self.add_version(('root', 'A'), [('root', 'C')], 'b')
663
674
        self.add_version(('root', 'B'), [('root', 'C')], '')
664
675
        plan = self.plan_merge_vf.plan_merge('A', 'B')
665
 
        self.assertEqual([('new-a', 'b\n'),
666
 
                          ('killed-both', 'a\n')
 
676
        self.assertEqual([('killed-both', 'a\n'),
 
677
                          ('new-a', 'b\n'),
 
678
                         ], list(plan))
 
679
 
 
680
    def test_plan_merge_with_move_and_change(self):
 
681
        self.add_version(('root', 'C'), [], 'abcd')
 
682
        self.add_version(('root', 'A'), [('root', 'C')], 'acbd')
 
683
        self.add_version(('root', 'B'), [('root', 'C')], 'aBcd')
 
684
        plan = self.plan_merge_vf.plan_merge('A', 'B')
 
685
        self.assertEqual([('unchanged', 'a\n'),
 
686
                          ('new-a', 'c\n'),
 
687
                          ('killed-b', 'b\n'),
 
688
                          ('new-b', 'B\n'),
 
689
                          ('killed-a', 'c\n'),
 
690
                          ('unchanged', 'd\n'),
667
691
                         ], list(plan))
668
692
 
669
693
 
703
727
        self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
704
728
        self.assertFileEqual('d\na\nb\n', 'this/file2')
705
729
 
706
 
    def test_merge_delete_and_change(self):
 
730
    def test_merge_move_and_change(self):
707
731
        this_tree = self.make_branch_and_tree('this')
708
732
        this_tree.lock_write()
709
733
        self.addCleanup(this_tree.unlock)
710
734
        self.build_tree_contents([
711
 
            ('this/file1', 'a\nb\n'),
 
735
            ('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
712
736
        ])
713
737
        this_tree.add('file1',)
714
738
        this_tree.commit('Added file')
715
739
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
716
740
        self.build_tree_contents([
717
 
            ('other/file1', 'a\nc\n'),
 
741
            ('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
718
742
        ])
719
 
        other_tree.commit('Changed b to c')
 
743
        other_tree.commit('Swapped 2 & 3')
720
744
        self.build_tree_contents([
721
 
            ('this/file1', 'a\n'),
 
745
            ('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
722
746
        ])
723
 
        this_tree.commit('Deleted b')
 
747
        this_tree.commit('Changed 2 to 2.1')
724
748
        self.do_merge(this_tree, other_tree)
725
 
        self.assertFileEqual('a\n'
 
749
        self.assertFileEqual('line 1\n'
726
750
            '<<<<<<< TREE\n'
 
751
            'line 3\n'
 
752
            'line 2\n'
727
753
            '=======\n'
728
 
            'c\n'
729
 
            '>>>>>>> MERGE-SOURCE\n', 'this/file1')
 
754
            'line 2 to 2.1\n'
 
755
            'line 3\n'
 
756
            '>>>>>>> MERGE-SOURCE\n'
 
757
            'line 4\n', 'this/file1')
730
758
 
731
759
 
732
760
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
742
770
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
743
771
 
744
772
    merge_type = _mod_merge.LCAMerger
 
773
 
 
774
    def test_merge_move_and_change(self):
 
775
        self.expectFailure("lca merge doesn't conflict for move and change",
 
776
            super(TestLCAMerge, self).test_merge_move_and_change)