/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: Alexander Belchenko
  • Date: 2008-02-28 21:25:30 UTC
  • mfrom: (3243 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3246.
  • Revision ID: bialix@ukr.net-20080228212530-pcrt1sc4vcezapgr
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
from bzrlib.merge import Merge3Merger
44
44
from bzrlib.tests import (
45
45
    CaseInsensitiveFilesystemFeature,
 
46
    HardlinkFeature,
46
47
    SymlinkFeature,
47
48
    TestCase,
48
49
    TestCaseInTempDir,
134
135
        transform.finalize()
135
136
        transform.finalize()
136
137
 
 
138
    def test_hardlink(self):
 
139
        self.requireFeature(HardlinkFeature)
 
140
        transform, root = self.get_transform()
 
141
        transform.new_file('file1', root, 'contents')
 
142
        transform.apply()
 
143
        target = self.make_branch_and_tree('target')
 
144
        target_transform = TreeTransform(target)
 
145
        trans_id = target_transform.create_path('file1', target_transform.root)
 
146
        target_transform.create_hardlink(self.wt.abspath('file1'), trans_id)
 
147
        target_transform.apply()
 
148
        self.failUnlessExists('target/file1')
 
149
        source_stat = os.stat(self.wt.abspath('file1'))
 
150
        target_stat = os.stat('target/file1')
 
151
        self.assertEqual(source_stat, target_stat)
 
152
 
137
153
    def test_convenience(self):
138
154
        transform, root = self.get_transform()
139
155
        self.wt.lock_tree_write()
1573
1589
        # children of non-root directories should not be renamed
1574
1590
        self.assertEqual(2, transform_result.rename_count)
1575
1591
 
 
1592
    def create_ab_tree(self):
 
1593
        """Create a committed test tree with two files"""
 
1594
        source = self.make_branch_and_tree('source')
 
1595
        self.build_tree_contents([('source/file1', 'A')])
 
1596
        self.build_tree_contents([('source/file2', 'B')])
 
1597
        source.add(['file1', 'file2'], ['file1-id', 'file2-id'])
 
1598
        source.commit('commit files')
 
1599
        source.lock_write()
 
1600
        self.addCleanup(source.unlock)
 
1601
        return source
 
1602
 
1576
1603
    def test_build_tree_accelerator_tree(self):
1577
 
        source = self.make_branch_and_tree('source')
1578
 
        self.build_tree_contents([('source/file1', 'A')])
1579
 
        self.build_tree_contents([('source/file2', 'B')])
1580
 
        source.add(['file1', 'file2'], ['file1-id', 'file2-id'])
1581
 
        source.commit('commit files')
 
1604
        source = self.create_ab_tree()
1582
1605
        self.build_tree_contents([('source/file2', 'C')])
1583
1606
        calls = []
1584
1607
        real_source_get_file = source.get_file
1586
1609
            calls.append(file_id)
1587
1610
            return real_source_get_file(file_id, path)
1588
1611
        source.get_file = get_file
1589
 
        source.lock_read()
1590
 
        self.addCleanup(source.unlock)
1591
1612
        target = self.make_branch_and_tree('target')
1592
1613
        revision_tree = source.basis_tree()
1593
1614
        revision_tree.lock_read()
1599
1620
        self.assertEqual([], list(target._iter_changes(revision_tree)))
1600
1621
 
1601
1622
    def test_build_tree_accelerator_tree_missing_file(self):
1602
 
        source = self.make_branch_and_tree('source')
1603
 
        self.build_tree_contents([('source/file1', 'A')])
1604
 
        self.build_tree_contents([('source/file2', 'B')])
1605
 
        source.add(['file1', 'file2'])
1606
 
        source.commit('commit files')
 
1623
        source = self.create_ab_tree()
1607
1624
        os.unlink('source/file1')
1608
1625
        source.remove(['file2'])
1609
1626
        target = self.make_branch_and_tree('target')
1632
1649
            calls.append(file_id)
1633
1650
            return real_source_get_file(file_id, path)
1634
1651
        source.get_file = get_file
1635
 
        source.lock_read()
1636
 
        self.addCleanup(source.unlock)
1637
1652
        target = self.make_branch_and_tree('target')
1638
1653
        revision_tree = source.basis_tree()
1639
1654
        revision_tree.lock_read()
1644
1659
        self.addCleanup(target.unlock)
1645
1660
        self.assertEqual([], list(target._iter_changes(revision_tree)))
1646
1661
 
 
1662
    def test_build_tree_hardlink(self):
 
1663
        self.requireFeature(HardlinkFeature)
 
1664
        source = self.create_ab_tree()
 
1665
        target = self.make_branch_and_tree('target')
 
1666
        revision_tree = source.basis_tree()
 
1667
        revision_tree.lock_read()
 
1668
        self.addCleanup(revision_tree.unlock)
 
1669
        build_tree(revision_tree, target, source, hardlink=True)
 
1670
        target.lock_read()
 
1671
        self.addCleanup(target.unlock)
 
1672
        self.assertEqual([], list(target._iter_changes(revision_tree)))
 
1673
        source_stat = os.stat('source/file1')
 
1674
        target_stat = os.stat('target/file1')
 
1675
        self.assertEqual(source_stat, target_stat)
 
1676
 
 
1677
        # Explicitly disallowing hardlinks should prevent them.
 
1678
        target2 = self.make_branch_and_tree('target2')
 
1679
        build_tree(revision_tree, target2, source, hardlink=False)
 
1680
        target2.lock_read()
 
1681
        self.addCleanup(target2.unlock)
 
1682
        self.assertEqual([], list(target2._iter_changes(revision_tree)))
 
1683
        source_stat = os.stat('source/file1')
 
1684
        target2_stat = os.stat('target2/file1')
 
1685
        self.assertNotEqual(source_stat, target2_stat)
 
1686
 
1647
1687
    def test_build_tree_accelerator_tree_moved(self):
1648
1688
        source = self.make_branch_and_tree('source')
1649
1689
        self.build_tree_contents([('source/file1', 'A')])
1661
1701
        self.addCleanup(target.unlock)
1662
1702
        self.assertEqual([], list(target._iter_changes(revision_tree)))
1663
1703
 
 
1704
    def test_build_tree_hardlinks_preserve_execute(self):
 
1705
        self.requireFeature(HardlinkFeature)
 
1706
        source = self.create_ab_tree()
 
1707
        tt = TreeTransform(source)
 
1708
        trans_id = tt.trans_id_tree_file_id('file1-id')
 
1709
        tt.set_executability(True, trans_id)
 
1710
        tt.apply()
 
1711
        self.assertTrue(source.is_executable('file1-id'))
 
1712
        target = self.make_branch_and_tree('target')
 
1713
        revision_tree = source.basis_tree()
 
1714
        revision_tree.lock_read()
 
1715
        self.addCleanup(revision_tree.unlock)
 
1716
        build_tree(revision_tree, target, source, hardlink=True)
 
1717
        target.lock_read()
 
1718
        self.addCleanup(target.unlock)
 
1719
        self.assertEqual([], list(target._iter_changes(revision_tree)))
 
1720
        self.assertTrue(source.is_executable('file1-id'))
 
1721
 
1664
1722
 
1665
1723
class MockTransform(object):
1666
1724