134
135
transform.finalize()
135
136
transform.finalize()
138
def test_hardlink(self):
139
self.requireFeature(HardlinkFeature)
140
transform, root = self.get_transform()
141
transform.new_file('file1', root, 'contents')
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)
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)
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')
1600
self.addCleanup(source.unlock)
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')])
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
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)))
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
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)))
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)
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)
1677
# Explicitly disallowing hardlinks should prevent them.
1678
target2 = self.make_branch_and_tree('target2')
1679
build_tree(revision_tree, target2, source, hardlink=False)
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)
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)))
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)
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)
1718
self.addCleanup(target.unlock)
1719
self.assertEqual([], list(target._iter_changes(revision_tree)))
1720
self.assertTrue(source.is_executable('file1-id'))
1665
1723
class MockTransform(object):