/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Aaron Bentley
  • Date: 2007-12-20 20:19:22 UTC
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: abentley@panoramicfeedback.com-20071220201922-r6a2vsx612x87yf6
Implement hard-linking for build_tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1515
1515
        # children of non-root directories should not be renamed
1516
1516
        self.assertEqual(2, transform_result.rename_count)
1517
1517
 
 
1518
    def create_ab_tree(self):
 
1519
        """Create a committed test tree with two files"""
 
1520
        source = self.make_branch_and_tree('source')
 
1521
        self.build_tree_contents([('source/file1', 'A')])
 
1522
        self.build_tree_contents([('source/file2', 'B')])
 
1523
        source.add(['file1', 'file2'], ['file1-id', 'file2-id'])
 
1524
        source.commit('commit files')
 
1525
        source.lock_write()
 
1526
        self.addCleanup(source.unlock)
 
1527
        return source
 
1528
 
1518
1529
    def test_build_tree_accelerator_tree(self):
1519
 
        source = self.make_branch_and_tree('source')
1520
 
        self.build_tree_contents([('source/file1', 'A')])
1521
 
        self.build_tree_contents([('source/file2', 'B')])
1522
 
        source.add(['file1', 'file2'], ['file1-id', 'file2-id'])
1523
 
        source.commit('commit files')
 
1530
        source = self.create_ab_tree()
1524
1531
        self.build_tree_contents([('source/file2', 'C')])
1525
1532
        calls = []
1526
1533
        real_source_get_file = source.get_file
1528
1535
            calls.append(file_id)
1529
1536
            return real_source_get_file(file_id, path)
1530
1537
        source.get_file = get_file
1531
 
        source.lock_read()
1532
 
        self.addCleanup(source.unlock)
1533
1538
        target = self.make_branch_and_tree('target')
1534
1539
        revision_tree = source.basis_tree()
1535
1540
        revision_tree.lock_read()
1541
1546
        self.assertEqual([], list(target._iter_changes(revision_tree)))
1542
1547
 
1543
1548
    def test_build_tree_accelerator_tree_missing_file(self):
1544
 
        source = self.make_branch_and_tree('source')
1545
 
        self.build_tree_contents([('source/file1', 'A')])
1546
 
        self.build_tree_contents([('source/file2', 'B')])
1547
 
        source.add(['file1', 'file2'])
1548
 
        source.commit('commit files')
 
1549
        source = self.create_ab_tree()
1549
1550
        os.unlink('source/file1')
1550
1551
        source.remove(['file2'])
1551
1552
        target = self.make_branch_and_tree('target')
1573
1574
            calls.append(file_id)
1574
1575
            return real_source_get_file(file_id, path)
1575
1576
        source.get_file = get_file
1576
 
        source.lock_read()
1577
 
        self.addCleanup(source.unlock)
1578
1577
        target = self.make_branch_and_tree('target')
1579
1578
        revision_tree = source.basis_tree()
1580
1579
        revision_tree.lock_read()
1585
1584
        self.addCleanup(target.unlock)
1586
1585
        self.assertEqual([], list(target._iter_changes(revision_tree)))
1587
1586
 
 
1587
    def test_build_tree_hardlink(self):
 
1588
        self.requireFeature(HardlinkFeature)
 
1589
        source = self.create_ab_tree()
 
1590
        target = self.make_branch_and_tree('target')
 
1591
        revision_tree = source.basis_tree()
 
1592
        revision_tree.lock_read()
 
1593
        self.addCleanup(revision_tree.unlock)
 
1594
        build_tree(revision_tree, target, source, hardlink=True)
 
1595
        target.lock_read()
 
1596
        self.addCleanup(target.unlock)
 
1597
        self.assertEqual([], list(target._iter_changes(revision_tree)))
 
1598
        source_stat = os.stat('source/file1')
 
1599
        target_stat = os.stat('target/file1')
 
1600
        self.assertEqual(source_stat, target_stat)
 
1601
 
 
1602
        # Explicitly disallowing hardlinks should prevent them.
 
1603
        target2 = self.make_branch_and_tree('target2')
 
1604
        build_tree(revision_tree, target2, source, hardlink=False)
 
1605
        target2.lock_read()
 
1606
        self.addCleanup(target2.unlock)
 
1607
        self.assertEqual([], list(target2._iter_changes(revision_tree)))
 
1608
        source_stat = os.stat('source/file1')
 
1609
        target2_stat = os.stat('target2/file1')
 
1610
        self.assertNotEqual(source_stat, target2_stat)
 
1611
 
 
1612
    def test_build_tree_hardlinks_preserve_execute(self):
 
1613
        self.requireFeature(HardlinkFeature)
 
1614
        source = self.create_ab_tree()
 
1615
        tt = TreeTransform(source)
 
1616
        trans_id = tt.trans_id_tree_file_id('file1-id')
 
1617
        tt.set_executability(True, trans_id)
 
1618
        tt.apply()
 
1619
        self.assertTrue(source.is_executable('file1-id'))
 
1620
        target = self.make_branch_and_tree('target')
 
1621
        revision_tree = source.basis_tree()
 
1622
        revision_tree.lock_read()
 
1623
        self.addCleanup(revision_tree.unlock)
 
1624
        build_tree(revision_tree, target, source, hardlink=True)
 
1625
        target.lock_read()
 
1626
        self.addCleanup(target.unlock)
 
1627
        self.assertEqual([], list(target._iter_changes(revision_tree)))
 
1628
        self.assertTrue(source.is_executable('file1-id'))
 
1629
 
1588
1630
 
1589
1631
class MockTransform(object):
1590
1632