~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-30 20:35:40 UTC
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080730203540-73uaw4di6m0yuxzh
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca

Show diffs side-by-side

added added

removed removed

Lines of Context:
1144
1144
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1145
1145
        return builder
1146
1146
 
1147
 
    def make_Merger(self, builder, other_revision_id):
 
1147
    def make_Merger(self, builder, other_revision_id,
 
1148
                    interesting_files=None, interesting_ids=None):
1148
1149
        """Make a Merger object from a branch builder"""
1149
1150
        mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1150
1151
        mem_tree.lock_write()
1151
1152
        self.addCleanup(mem_tree.unlock)
1152
1153
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1153
1154
            mem_tree, other_revision_id)
 
1155
        if interesting_files is not None:
 
1156
            merger.set_interesting_files(interesting_files)
 
1157
        if interesting_ids is not None:
 
1158
            # It seems there is no matching function for set_interesting_ids
 
1159
            merger.interesting_ids = interesting_ids
1154
1160
        merger.merge_type = _mod_merge.Merge3Merger
1155
1161
        return merger
1156
1162
 
1235
1241
 
1236
1242
class TestMergerEntriesLCA(TestMergerBase):
1237
1243
 
1238
 
    def make_merge_obj(self, builder, other_revision_id):
1239
 
        merger = self.make_Merger(builder, other_revision_id)
 
1244
    def make_merge_obj(self, builder, other_revision_id,
 
1245
                       interesting_files=None, interesting_ids=None):
 
1246
        merger = self.make_Merger(builder, other_revision_id,
 
1247
            interesting_files=interesting_files,
 
1248
            interesting_ids=interesting_ids)
1240
1249
        return merger.make_merger()
1241
1250
        
1242
1251
    def test_simple(self):
1455
1464
                           ((False, [False, False]), False, False)),
1456
1465
                         ], entries)
1457
1466
 
 
1467
    def test_interesting_files(self):
 
1468
        # Two files modified, but we should filter one of them
 
1469
        builder = self.get_builder()
 
1470
        builder.build_snapshot('A-id', None,
 
1471
            [('add', (u'', 'a-root-id', 'directory', None)),
 
1472
             ('add', (u'a', 'a-id', 'file', 'content\n')),
 
1473
             ('add', (u'b', 'b-id', 'file', 'content\n'))])
 
1474
        builder.build_snapshot('B-id', ['A-id'], [])
 
1475
        builder.build_snapshot('C-id', ['A-id'], [])
 
1476
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
 
1477
            [('modify', ('a-id', 'new-content\n')),
 
1478
             ('modify', ('b-id', 'new-content\n'))])
 
1479
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
 
1480
        merge_obj = self.make_merge_obj(builder, 'E-id',
 
1481
                                        interesting_files=['b'])
 
1482
        entries = list(merge_obj._entries_lca())
 
1483
        root_id = 'a-root-id'
 
1484
        self.assertEqual([('b-id', True,
 
1485
                           ((root_id, [root_id, root_id]), root_id, root_id),
 
1486
                           ((u'b', [u'b', u'b']), u'b', u'b'),
 
1487
                           ((False, [False, False]), False, False)),
 
1488
                         ], entries)
 
1489
 
 
1490
    def test_interesting_file_in_this(self):
 
1491
        # This renamed the file, but it should still match the entry in other
 
1492
        builder = self.get_builder()
 
1493
        builder.build_snapshot('A-id', None,
 
1494
            [('add', (u'', 'a-root-id', 'directory', None)),
 
1495
             ('add', (u'a', 'a-id', 'file', 'content\n')),
 
1496
             ('add', (u'b', 'b-id', 'file', 'content\n'))])
 
1497
        builder.build_snapshot('B-id', ['A-id'], [])
 
1498
        builder.build_snapshot('C-id', ['A-id'], [])
 
1499
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
 
1500
            [('modify', ('a-id', 'new-content\n')),
 
1501
             ('modify', ('b-id', 'new-content\n'))])
 
1502
        builder.build_snapshot('D-id', ['B-id', 'C-id'],
 
1503
            [('rename', ('b', 'c'))])
 
1504
        merge_obj = self.make_merge_obj(builder, 'E-id',
 
1505
                                        interesting_files=['c'])
 
1506
        entries = list(merge_obj._entries_lca())
 
1507
        root_id = 'a-root-id'
 
1508
        self.assertEqual([('b-id', True,
 
1509
                           ((root_id, [root_id, root_id]), root_id, root_id),
 
1510
                           ((u'b', [u'b', u'b']), u'b', u'c'),
 
1511
                           ((False, [False, False]), False, False)),
 
1512
                         ], entries)
 
1513
 
 
1514
    def test_interesting_file_in_base(self):
 
1515
        # This renamed the file, but it should still match the entry in BASE
 
1516
        builder = self.get_builder()
 
1517
        builder.build_snapshot('A-id', None,
 
1518
            [('add', (u'', 'a-root-id', 'directory', None)),
 
1519
             ('add', (u'a', 'a-id', 'file', 'content\n')),
 
1520
             ('add', (u'c', 'c-id', 'file', 'content\n'))])
 
1521
        builder.build_snapshot('B-id', ['A-id'],
 
1522
            [('rename', ('c', 'b'))])
 
1523
        builder.build_snapshot('C-id', ['A-id'],
 
1524
            [('rename', ('c', 'b'))])
 
1525
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
 
1526
            [('modify', ('a-id', 'new-content\n')),
 
1527
             ('modify', ('c-id', 'new-content\n'))])
 
1528
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
 
1529
        merge_obj = self.make_merge_obj(builder, 'E-id',
 
1530
                                        interesting_files=['c'])
 
1531
        entries = list(merge_obj._entries_lca())
 
1532
        root_id = 'a-root-id'
 
1533
        self.assertEqual([('c-id', True,
 
1534
                           ((root_id, [root_id, root_id]), root_id, root_id),
 
1535
                           ((u'c', [u'b', u'b']), u'b', u'b'),
 
1536
                           ((False, [False, False]), False, False)),
 
1537
                         ], entries)
 
1538
 
 
1539
    def test_interesting_file_in_lca(self):
 
1540
        # This renamed the file, but it should still match the entry in LCA
 
1541
        builder = self.get_builder()
 
1542
        builder.build_snapshot('A-id', None,
 
1543
            [('add', (u'', 'a-root-id', 'directory', None)),
 
1544
             ('add', (u'a', 'a-id', 'file', 'content\n')),
 
1545
             ('add', (u'b', 'b-id', 'file', 'content\n'))])
 
1546
        builder.build_snapshot('B-id', ['A-id'],
 
1547
            [('rename', ('b', 'c'))])
 
1548
        builder.build_snapshot('C-id', ['A-id'], [])
 
1549
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
 
1550
            [('modify', ('a-id', 'new-content\n')),
 
1551
             ('modify', ('b-id', 'new-content\n'))])
 
1552
        builder.build_snapshot('D-id', ['B-id', 'C-id'],
 
1553
            [('rename', ('c', 'b'))])
 
1554
        merge_obj = self.make_merge_obj(builder, 'E-id',
 
1555
                                        interesting_files=['c'])
 
1556
        entries = list(merge_obj._entries_lca())
 
1557
        root_id = 'a-root-id'
 
1558
        self.assertEqual([('b-id', True,
 
1559
                           ((root_id, [root_id, root_id]), root_id, root_id),
 
1560
                           ((u'b', [u'c', u'b']), u'b', u'b'),
 
1561
                           ((False, [False, False]), False, False)),
 
1562
                         ], entries)
 
1563
 
 
1564
    def test_interesting_ids(self):
 
1565
        # Two files modified, but we should filter one of them
 
1566
        builder = self.get_builder()
 
1567
        builder.build_snapshot('A-id', None,
 
1568
            [('add', (u'', 'a-root-id', 'directory', None)),
 
1569
             ('add', (u'a', 'a-id', 'file', 'content\n')),
 
1570
             ('add', (u'b', 'b-id', 'file', 'content\n'))])
 
1571
        builder.build_snapshot('B-id', ['A-id'], [])
 
1572
        builder.build_snapshot('C-id', ['A-id'], [])
 
1573
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
 
1574
            [('modify', ('a-id', 'new-content\n')),
 
1575
             ('modify', ('b-id', 'new-content\n'))])
 
1576
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
 
1577
        merge_obj = self.make_merge_obj(builder, 'E-id',
 
1578
                                        interesting_ids=['b-id'])
 
1579
        entries = list(merge_obj._entries_lca())
 
1580
        root_id = 'a-root-id'
 
1581
        self.assertEqual([('b-id', True,
 
1582
                           ((root_id, [root_id, root_id]), root_id, root_id),
 
1583
                           ((u'b', [u'b', u'b']), u'b', u'b'),
 
1584
                           ((False, [False, False]), False, False)),
 
1585
                         ], entries)
 
1586
 
 
1587
 
1458
1588
 
1459
1589
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
1460
1590
 
1608
1738
    #       x-x Only executable bit changed, not really possible to test via
1609
1739
    #           builder api, only TreeTransform supports executable on all
1610
1740
    #           platforms.
 
1741
    #       x-x Handle 'interesting_files' or 'interesting_ids'
1611
1742
 
1612
1743
class TestLCAMultiWay(tests.TestCase):
1613
1744