902
902
"""Test that DirState adds entries in the right order."""
904
904
def test_add_sorting(self):
905
"""Add entries in lexicographical order, we get path sorted order."""
906
dirs = ['a', 'a-a', 'a-z',
907
'a/a', 'a/a-a', 'a/a-z', 'a/a/a', 'a/a/z',
908
'a/z', 'a/z-a', 'a/z-z', 'a/z/a', 'a/z/z',
905
"""Add entries in lexicographical order, we get path sorted order.
907
This tests it to a depth of 4, to make sure we don't just get it right
908
at a single depth. 'a/a' should come before 'a-a', even though it
909
doesn't lexicographically.
911
dirs = ['a', 'a/a', 'a/a/a', 'a/a/a/a',
912
'a-a', 'a/a-a', 'a/a/a-a', 'a/a/a/a-a',
912
915
state = dirstate.DirState.initialize('dirstate')
921
924
state.add(file_path, file_id, 'file', fake_stat, null_sha)
923
926
expected = ['', '', 'a',
924
'a/a', 'a/a/a', 'a/a/z', 'a/a-a', 'a/a-z',
925
'a/z', 'a/z/a', 'a/z/z', 'a/z-a', 'a/z-z',
927
'a/a', 'a/a/a', 'a/a/a/a',
928
'a/a/a/a-a', 'a/a/a-a', 'a/a-a', 'a-a',
930
split = lambda p:p.split('/')
931
self.assertEqual(sorted(expected, key=split), expected)
932
dirblock_names = [d[0] for d in state._dirblocks]
933
self.assertEqual(expected, dirblock_names)
935
def test_set_parent_trees_correct_order(self):
936
"""After calling set_parent_trees() we should maintain the order."""
937
dirs = ['a', 'a-a', 'a/a']
939
state = dirstate.DirState.initialize('dirstate')
940
self.addCleanup(state.unlock)
942
fake_stat = os.stat('dirstate')
944
d_id = d.replace('/', '_')+'-id'
946
file_id = file_path.replace('/', '_')+'-id'
947
state.add(d, d_id, 'directory', fake_stat, null_sha)
948
state.add(file_path, file_id, 'file', fake_stat, null_sha)
950
expected = ['', '', 'a', 'a/a', 'a-a']
951
dirblock_names = [d[0] for d in state._dirblocks]
952
self.assertEqual(expected, dirblock_names)
954
# *really* cheesy way to just get an empty tree
955
repo = self.make_repository('repo')
956
empty_tree = repo.revision_tree(None)
957
state.set_parent_trees([('null:', empty_tree)], [])
928
959
dirblock_names = [d[0] for d in state._dirblocks]
929
960
self.assertEqual(expected, dirblock_names)