820
836
transform.apply()
821
837
transform, root = self.get_transform()
823
self.assertEqual([], list(transform._iter_changes()))
839
self.assertEqual([], list(transform.iter_changes()))
824
840
old = transform.trans_id_tree_file_id('id-1')
825
841
transform.unversion_file(old)
826
842
self.assertEqual([('id-1', ('old', None), False, (True, False),
827
843
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
828
(True, True))], list(transform._iter_changes()))
844
(True, True))], list(transform.iter_changes()))
829
845
transform.new_directory('new', root, 'id-1')
830
846
self.assertEqual([('id-1', ('old', 'new'), True, (True, True),
831
847
('eert_toor', 'eert_toor'), ('old', 'new'),
832
848
('file', 'directory'),
833
(True, False))], list(transform._iter_changes()))
849
(True, False))], list(transform.iter_changes()))
835
851
transform.finalize()
861
877
old = transform.trans_id_tree_path('old')
862
878
subdir = transform.trans_id_tree_file_id('subdir-id')
863
879
new = transform.trans_id_tree_path('new')
864
self.assertEqual([], list(transform._iter_changes()))
880
self.assertEqual([], list(transform.iter_changes()))
866
882
#content deletion
867
883
transform.delete_contents(old)
868
884
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
869
885
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', None),
870
(False, False))], list(transform._iter_changes()))
886
(False, False))], list(transform.iter_changes()))
873
889
transform.create_file('blah', old)
874
890
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
875
891
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
876
(False, False))], list(transform._iter_changes()))
892
(False, False))], list(transform.iter_changes()))
877
893
transform.cancel_deletion(old)
878
894
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
879
895
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
880
(False, False))], list(transform._iter_changes()))
896
(False, False))], list(transform.iter_changes()))
881
897
transform.cancel_creation(old)
883
899
# move file_id to a different file
884
self.assertEqual([], list(transform._iter_changes()))
900
self.assertEqual([], list(transform.iter_changes()))
885
901
transform.unversion_file(old)
886
902
transform.version_file('id-1', new)
887
903
transform.adjust_path('old', root, new)
888
904
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
889
905
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
890
(False, False))], list(transform._iter_changes()))
906
(False, False))], list(transform.iter_changes()))
891
907
transform.cancel_versioning(new)
892
908
transform._removed_id = set()
895
self.assertEqual([], list(transform._iter_changes()))
911
self.assertEqual([], list(transform.iter_changes()))
896
912
transform.set_executability(True, old)
897
913
self.assertEqual([('id-1', ('old', 'old'), False, (True, True),
898
914
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
899
(False, True))], list(transform._iter_changes()))
915
(False, True))], list(transform.iter_changes()))
900
916
transform.set_executability(None, old)
903
self.assertEqual([], list(transform._iter_changes()))
919
self.assertEqual([], list(transform.iter_changes()))
904
920
transform.adjust_path('new', root, old)
905
921
transform._new_parent = {}
906
922
self.assertEqual([('id-1', ('old', 'new'), False, (True, True),
907
923
('eert_toor', 'eert_toor'), ('old', 'new'), ('file', 'file'),
908
(False, False))], list(transform._iter_changes()))
924
(False, False))], list(transform.iter_changes()))
909
925
transform._new_name = {}
911
927
# parent directory
912
self.assertEqual([], list(transform._iter_changes()))
928
self.assertEqual([], list(transform.iter_changes()))
913
929
transform.adjust_path('new', subdir, old)
914
930
transform._new_name = {}
915
931
self.assertEqual([('id-1', ('old', 'subdir/old'), False,
916
932
(True, True), ('eert_toor', 'subdir-id'), ('old', 'old'),
917
933
('file', 'file'), (False, False))],
918
list(transform._iter_changes()))
934
list(transform.iter_changes()))
919
935
transform._new_path = {}
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
1642
1657
self.assertEqual([], calls)
1643
1658
target.lock_read()
1644
1659
self.addCleanup(target.unlock)
1645
self.assertEqual([], list(target._iter_changes(revision_tree)))
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')
1659
1699
build_tree(revision_tree, target, source)
1660
1700
target.lock_read()
1661
1701
self.addCleanup(target.unlock)
1662
self.assertEqual([], list(target._iter_changes(revision_tree)))
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):
1897
1955
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
1898
1956
(root, root), ('a', 'a'), ('file', 'file'),
1899
1957
(False, False))],
1900
list(preview_tree._iter_changes(revision_tree)))
1958
list(preview_tree.iter_changes(revision_tree)))
1902
1960
def test_wrong_tree_value_error(self):
1903
1961
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1904
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1962
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1906
1964
self.assertEqual('from_tree must be transform source tree.', str(e))
1908
1966
def test_include_unchanged_value_error(self):
1909
1967
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1910
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1968
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1911
1969
revision_tree, include_unchanged=True)
1912
1970
self.assertEqual('include_unchanged is not supported', str(e))
1914
1972
def test_specific_files(self):
1915
1973
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1916
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1974
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1917
1975
revision_tree, specific_files=['pete'])
1918
1976
self.assertEqual('specific_files is not supported', str(e))
1920
1978
def test_want_unversioned_value_error(self):
1921
1979
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1922
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1980
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1923
1981
revision_tree, want_unversioned=True)
1924
1982
self.assertEqual('want_unversioned is not supported', str(e))
1927
1985
# extra_trees is harmless without specific_files, so we'll silently
1928
1986
# accept it, even though we won't use it.
1929
1987
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1930
preview_tree._iter_changes(revision_tree, extra_trees=[preview_tree])
1988
preview_tree.iter_changes(revision_tree, extra_trees=[preview_tree])
1932
1990
def test_ignore_require_versioned_no_specific_files(self):
1933
1991
# require_versioned is meaningless without specific_files.
1934
1992
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1935
preview_tree._iter_changes(revision_tree, require_versioned=False)
1993
preview_tree.iter_changes(revision_tree, require_versioned=False)
1937
1995
def test_ignore_pb(self):
1938
1996
# pb could be supported, but TT.iter_changes doesn't support it.
1939
1997
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1940
preview_tree._iter_changes(revision_tree, pb=progress.DummyProgress())
1998
preview_tree.iter_changes(revision_tree, pb=progress.DummyProgress())
1942
2000
def test_kind(self):
1943
2001
revision_tree = self.create_tree()