471
471
TestCaseWithMemoryTransport.setUp(self)
472
self.vf = knit.make_file_knit('root', self.get_transport(),
474
self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root',
477
def add_version(self, version_id, parents, text):
478
self.vf.add_lines(version_id, parents, [c+'\n' for c in text])
480
def add_uncommitted_version(self, version_id, parents, text):
481
self.plan_merge_vf.add_lines(version_id, parents,
472
mapper = versionedfile.PrefixMapper()
473
factory = knit.make_file_factory(True, mapper)
474
self.vf = factory(self.get_transport())
475
self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root')
476
self.plan_merge_vf.fallback_versionedfiles.append(self.vf)
478
def add_version(self, key, parents, text):
479
self.vf.add_lines(key, parents, [c+'\n' for c in text])
481
def add_uncommitted_version(self, key, parents, text):
482
self.plan_merge_vf.add_lines(key, parents,
482
483
[c+'\n' for c in text])
484
485
def setup_plan_merge(self):
485
self.add_version('A', [], 'abc')
486
self.add_version('B', ['A'], 'acehg')
487
self.add_version('C', ['A'], 'fabg')
488
return _PlanMerge('B', 'C', self.plan_merge_vf)
486
self.add_version(('root', 'A'), [], 'abc')
487
self.add_version(('root', 'B'), [('root', 'A')], 'acehg')
488
self.add_version(('root', 'C'), [('root', 'A')], 'fabg')
489
return _PlanMerge('B', 'C', self.plan_merge_vf, ('root',))
490
491
def setup_plan_merge_uncommitted(self):
491
self.add_version('A', [], 'abc')
492
self.add_uncommitted_version('B:', ['A'], 'acehg')
493
self.add_uncommitted_version('C:', ['A'], 'fabg')
494
return _PlanMerge('B:', 'C:', self.plan_merge_vf)
492
self.add_version(('root', 'A'), [], 'abc')
493
self.add_uncommitted_version(('root', 'B:'), [('root', 'A')], 'acehg')
494
self.add_uncommitted_version(('root', 'C:'), [('root', 'A')], 'fabg')
495
return _PlanMerge('B:', 'C:', self.plan_merge_vf, ('root',))
496
497
def test_unique_lines(self):
497
498
plan = self.setup_plan_merge()
505
506
self.assertEqual(set([0, 3]), plan._find_new('C'))
507
508
def test_find_new2(self):
508
self.add_version('A', [], 'abc')
509
self.add_version('B', ['A'], 'abcde')
510
self.add_version('C', ['A'], 'abcefg')
511
self.add_version('D', ['A', 'B', 'C'], 'abcdegh')
512
my_plan = _PlanMerge('B', 'D', self.plan_merge_vf)
509
self.add_version(('root', 'A'), [], 'abc')
510
self.add_version(('root', 'B'), [('root', 'A')], 'abcde')
511
self.add_version(('root', 'C'), [('root', 'A')], 'abcefg')
512
self.add_version(('root', 'D'),
513
[('root', 'A'), ('root', 'B'), ('root', 'C')], 'abcdegh')
514
my_plan = _PlanMerge('B', 'D', self.plan_merge_vf, ('root',))
513
515
self.assertEqual(set([5, 6]), my_plan._find_new('D'))
514
516
self.assertEqual(set(), my_plan._find_new('A'))
516
518
def test_find_new_no_ancestors(self):
517
self.add_version('A', [], 'abc')
518
self.add_version('B', [], 'xyz')
519
my_plan = _PlanMerge('A', 'B', self.vf)
519
self.add_version(('root', 'A'), [], 'abc')
520
self.add_version(('root', 'B'), [], 'xyz')
521
my_plan = _PlanMerge('A', 'B', self.vf, ('root',))
520
522
self.assertEqual(set([0, 1, 2]), my_plan._find_new('A'))
522
524
def test_plan_merge(self):
576
578
list(_PlanMerge._subtract_plans(old_plan, new_plan)))
578
580
def setup_merge_with_base(self):
579
self.add_version('COMMON', [], 'abc')
580
self.add_version('THIS', ['COMMON'], 'abcd')
581
self.add_version('BASE', ['COMMON'], 'eabc')
582
self.add_version('OTHER', ['BASE'], 'eafb')
581
self.add_version(('root', 'COMMON'), [], 'abc')
582
self.add_version(('root', 'THIS'), [('root', 'COMMON')], 'abcd')
583
self.add_version(('root', 'BASE'), [('root', 'COMMON')], 'eabc')
584
self.add_version(('root', 'OTHER'), [('root', 'BASE')], 'eafb')
584
586
def test_plan_merge_with_base(self):
585
587
self.setup_merge_with_base()
630
632
def test_plan_lca_merge_with_criss_cross(self):
631
self.add_version('ROOT', [], 'abc')
633
self.add_version(('root', 'ROOT'), [], 'abc')
632
634
# each side makes a change
633
self.add_version('REV1', ['ROOT'], 'abcd')
634
self.add_version('REV2', ['ROOT'], 'abce')
635
self.add_version(('root', 'REV1'), [('root', 'ROOT')], 'abcd')
636
self.add_version(('root', 'REV2'), [('root', 'ROOT')], 'abce')
635
637
# both sides merge, discarding others' changes
636
self.add_version('LCA1', ['REV1', 'REV2'], 'abcd')
637
self.add_version('LCA2', ['REV1', 'REV2'], 'fabce')
638
self.add_version(('root', 'LCA1'),
639
[('root', 'REV1'), ('root', 'REV2')], 'abcd')
640
self.add_version(('root', 'LCA2'),
641
[('root', 'REV1'), ('root', 'REV2')], 'fabce')
638
642
plan = self.plan_merge_vf.plan_lca_merge('LCA1', 'LCA2')
639
643
self.assertEqual([('new-b', 'f\n'),
640
644
('unchanged', 'a\n'),