1515
1515
# children of non-root directories should not be renamed
1516
1516
self.assertEqual(2, transform_result.rename_count)
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')
1526
self.addCleanup(source.unlock)
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')])
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
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)))
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
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
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)
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)
1602
# Explicitly disallowing hardlinks should prevent them.
1603
target2 = self.make_branch_and_tree('target2')
1604
build_tree(revision_tree, target2, source, hardlink=False)
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)
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)
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)
1626
self.addCleanup(target.unlock)
1627
self.assertEqual([], list(target._iter_changes(revision_tree)))
1628
self.assertTrue(source.is_executable('file1-id'))
1589
1631
class MockTransform(object):