775
776
transform.finalize()
778
def test_rename_count(self):
779
transform, root = self.get_transform()
780
transform.new_file('name1', root, 'contents')
781
self.assertEqual(transform.rename_count, 0)
783
self.assertEqual(transform.rename_count, 1)
784
transform2, root = self.get_transform()
785
transform2.adjust_path('name2', root,
786
transform2.trans_id_tree_path('name1'))
787
self.assertEqual(transform2.rename_count, 0)
789
self.assertEqual(transform2.rename_count, 2)
791
def test_change_parent(self):
792
"""Ensure that after we change a parent, the results are still right.
794
Renames and parent changes on pending transforms can happen as part
795
of conflict resolution, and are explicitly permitted by the
798
This test ensures they work correctly with the rename-avoidance
801
transform, root = self.get_transform()
802
parent1 = transform.new_directory('parent1', root)
803
child1 = transform.new_file('child1', parent1, 'contents')
804
parent2 = transform.new_directory('parent2', root)
805
transform.adjust_path('child1', parent2, child1)
807
self.failIfExists(self.wt.abspath('parent1/child1'))
808
self.failUnlessExists(self.wt.abspath('parent2/child1'))
809
# rename limbo/new-1 => parent1, rename limbo/new-3 => parent2
810
# no rename for child1 (counting only renames during apply)
811
self.failUnlessEqual(2, transform.rename_count)
813
def test_cancel_parent(self):
814
"""Cancelling a parent doesn't cause deletion of a non-empty directory
816
This is like the test_change_parent, except that we cancel the parent
817
before adjusting the path. The transform must detect that the
818
directory is non-empty, and move children to safe locations.
820
transform, root = self.get_transform()
821
parent1 = transform.new_directory('parent1', root)
822
child1 = transform.new_file('child1', parent1, 'contents')
823
child2 = transform.new_file('child2', parent1, 'contents')
825
transform.cancel_creation(parent1)
827
self.fail('Failed to move child1 before deleting parent1')
828
transform.cancel_creation(child2)
829
transform.create_directory(parent1)
831
transform.cancel_creation(parent1)
832
# If the transform incorrectly believes that child2 is still in
833
# parent1's limbo directory, it will try to rename it and fail
834
# because was already moved by the first cancel_creation.
836
self.fail('Transform still thinks child2 is a child of parent1')
837
parent2 = transform.new_directory('parent2', root)
838
transform.adjust_path('child1', parent2, child1)
840
self.failIfExists(self.wt.abspath('parent1'))
841
self.failUnlessExists(self.wt.abspath('parent2/child1'))
842
# rename limbo/new-3 => parent2, rename limbo/new-2 => child1
843
self.failUnlessEqual(2, transform.rename_count)
845
def test_adjust_and_cancel(self):
846
"""Make sure adjust_path keeps track of limbo children properly"""
847
transform, root = self.get_transform()
848
parent1 = transform.new_directory('parent1', root)
849
child1 = transform.new_file('child1', parent1, 'contents')
850
parent2 = transform.new_directory('parent2', root)
851
transform.adjust_path('child1', parent2, child1)
852
transform.cancel_creation(child1)
854
transform.cancel_creation(parent1)
855
# if the transform thinks child1 is still in parent1's limbo
856
# directory, it will attempt to move it and fail.
858
self.fail('Transform still thinks child1 is a child of parent1')
861
def test_noname_contents(self):
862
"""TreeTransform should permit deferring naming files."""
863
transform, root = self.get_transform()
864
parent = transform.trans_id_file_id('parent-id')
866
transform.create_directory(parent)
868
self.fail("Can't handle contents with no name")
871
def test_noname_contents_nested(self):
872
"""TreeTransform should permit deferring naming files."""
873
transform, root = self.get_transform()
874
parent = transform.trans_id_file_id('parent-id')
876
transform.create_directory(parent)
878
self.fail("Can't handle contents with no name")
879
child = transform.new_directory('child', parent)
880
transform.adjust_path('parent', root, parent)
882
self.failUnlessExists(self.wt.abspath('parent/child'))
883
self.assertEqual(1, transform.rename_count)
885
def test_reuse_name(self):
886
"""Avoid reusing the same limbo name for different files"""
887
transform, root = self.get_transform()
888
parent = transform.new_directory('parent', root)
889
child1 = transform.new_directory('child', parent)
891
child2 = transform.new_directory('child', parent)
893
self.fail('Tranform tried to use the same limbo name twice')
894
transform.adjust_path('child2', parent, child2)
896
# limbo/new-1 => parent, limbo/new-3 => parent/child2
897
# child2 is put into top-level limbo because child1 has already
898
# claimed the direct limbo path when child2 is created. There is no
899
# advantage in renaming files once they're in top-level limbo, except
901
self.assertEqual(2, transform.rename_count)
903
def test_reuse_when_first_moved(self):
904
"""Don't avoid direct paths when it is safe to use them"""
905
transform, root = self.get_transform()
906
parent = transform.new_directory('parent', root)
907
child1 = transform.new_directory('child', parent)
908
transform.adjust_path('child1', parent, child1)
909
child2 = transform.new_directory('child', parent)
911
# limbo/new-1 => parent
912
self.assertEqual(1, transform.rename_count)
914
def test_reuse_after_cancel(self):
915
"""Don't avoid direct paths when it is safe to use them"""
916
transform, root = self.get_transform()
917
parent2 = transform.new_directory('parent2', root)
918
child1 = transform.new_directory('child1', parent2)
919
transform.cancel_creation(parent2)
920
transform.create_directory(parent2)
921
child2 = transform.new_directory('child1', parent2)
922
transform.adjust_path('child2', parent2, child1)
924
# limbo/new-1 => parent2, limbo/new-2 => parent2/child1
925
self.assertEqual(2, transform.rename_count)
927
def test_finalize_order(self):
928
"""Finalize must be done in child-to-parent order"""
929
transform, root = self.get_transform()
930
parent = transform.new_directory('parent', root)
931
child = transform.new_directory('child', parent)
935
self.fail('Tried to remove parent before child1')
937
def test_cancel_with_cancelled_child_should_succeed(self):
938
transform, root = self.get_transform()
939
parent = transform.new_directory('parent', root)
940
child = transform.new_directory('child', parent)
941
transform.cancel_creation(child)
942
transform.cancel_creation(parent)
777
946
class TransformGroup(object):
778
947
def __init__(self, dirname, root_id):
779
948
self.name = dirname