~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-18 20:25:52 UTC
  • mfrom: (4413.5.15 1.16-chk-direct)
  • Revision ID: pqm@pqm.ubuntu.com-20090618202552-xyl6tcvbxtm8bupf
(jam) Improve initial commit performance by creating a CHKMap in bulk,
        rather than via O(tree) map() calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
64
64
    def setUp(self):
65
65
        tests.TestCaseWithTransport.setUp(self)
66
66
 
67
 
        self.overrideAttr(osutils,
68
 
                          '_selected_dir_reader', self._dir_reader_class())
 
67
        # Save platform specific info and reset it
 
68
        cur_dir_reader = osutils._selected_dir_reader
 
69
 
 
70
        def restore():
 
71
            osutils._selected_dir_reader = cur_dir_reader
 
72
        self.addCleanup(restore)
 
73
 
 
74
        osutils._selected_dir_reader = self._dir_reader_class()
69
75
 
70
76
    def create_empty_dirstate(self):
71
77
        """Return a locked but empty dirstate"""
413
419
            (('', '', tree.get_root_id()), # common details
414
420
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
415
421
              ('d', '', 0, False, rev_id), # first parent details
416
 
              ('d', '', 0, False, rev_id), # second parent details
 
422
              ('d', '', 0, False, rev_id2), # second parent details
417
423
             ])])
418
424
        state = dirstate.DirState.from_tree(tree, 'dirstate')
419
425
        self.check_state_with_reopen(expected_result, state)
494
500
            (('', '', tree.get_root_id()), # common details
495
501
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
496
502
              ('d', '', 0, False, rev_id), # first parent details
497
 
              ('d', '', 0, False, rev_id), # second parent details
 
503
              ('d', '', 0, False, rev_id2), # second parent details
498
504
             ]),
499
505
            (('', 'a file', 'a-file-id'), # common
500
506
             [('f', '', 0, False, dirstate.DirState.NULLSTAT), # current
730
736
 
731
737
class TestDirStateManipulations(TestCaseWithDirState):
732
738
 
733
 
    def test_update_minimal_updates_id_index(self):
734
 
        state = self.create_dirstate_with_root_and_subdir()
735
 
        self.addCleanup(state.unlock)
736
 
        id_index = state._get_id_index()
737
 
        self.assertEqual(['a-root-value', 'subdir-id'], sorted(id_index))
738
 
        state.add('file-name', 'file-id', 'file', None, '')
739
 
        self.assertEqual(['a-root-value', 'file-id', 'subdir-id'],
740
 
                         sorted(id_index))
741
 
        state.update_minimal(('', 'new-name', 'file-id'), 'f',
742
 
                             path_utf8='new-name')
743
 
        self.assertEqual(['a-root-value', 'file-id', 'subdir-id'],
744
 
                         sorted(id_index))
745
 
        self.assertEqual([('', 'new-name', 'file-id')],
746
 
                         sorted(id_index['file-id']))
747
 
        state._validate()
748
 
 
749
739
    def test_set_state_from_inventory_no_content_no_parents(self):
750
740
        # setting the current inventory is a slow but important api to support.
751
741
        tree1 = self.make_branch_and_memory_tree('tree1')
837
827
        finally:
838
828
            tree.unlock()
839
829
 
 
830
 
840
831
    def test_set_state_from_inventory_mixed_paths(self):
841
832
        tree1 = self.make_branch_and_tree('tree1')
842
833
        self.build_tree(['tree1/a/', 'tree1/a/b/', 'tree1/a-b/',
883
874
        state = dirstate.DirState.initialize('dirstate')
884
875
        try:
885
876
            # check precondition to be sure the state does change appropriately.
886
 
            root_entry = (('', '', 'TREE_ROOT'), [('d', '', 0, False, 'x'*32)])
887
 
            self.assertEqual([root_entry], list(state._iter_entries()))
888
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
889
 
            self.assertEqual(root_entry,
890
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
891
 
            self.assertEqual((None, None),
892
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
893
 
            state.set_path_id('', 'second-root-id')
894
 
            new_root_entry = (('', '', 'second-root-id'),
895
 
                              [('d', '', 0, False, 'x'*32)])
896
 
            expected_rows = [new_root_entry]
 
877
            self.assertEqual(
 
878
                [(('', '', 'TREE_ROOT'), [('d', '', 0, False,
 
879
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])],
 
880
                list(state._iter_entries()))
 
881
            state.set_path_id('', 'foobarbaz')
 
882
            expected_rows = [
 
883
                (('', '', 'foobarbaz'), [('d', '', 0, False,
 
884
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]
897
885
            self.assertEqual(expected_rows, list(state._iter_entries()))
898
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
899
 
            self.assertEqual(new_root_entry, 
900
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
901
 
            self.assertEqual((None, None),
902
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
903
886
            # should work across save too
904
887
            state.save()
905
888
        finally:
923
906
        state._validate()
924
907
        try:
925
908
            state.set_parent_trees([('parent-revid', rt)], ghosts=[])
926
 
            root_entry = (('', '', 'TREE_ROOT'),
927
 
                          [('d', '', 0, False, 'x'*32),
928
 
                           ('d', '', 0, False, 'parent-revid')])
929
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
930
 
            self.assertEqual(root_entry,
931
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
932
 
            self.assertEqual((None, None),
933
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
934
 
            state.set_path_id('', 'Asecond-root-id')
 
909
            state.set_path_id('', 'foobarbaz')
935
910
            state._validate()
936
911
            # now see that it is what we expected
937
 
            old_root_entry = (('', '', 'TREE_ROOT'),
938
 
                              [('a', '', 0, False, ''),
939
 
                               ('d', '', 0, False, 'parent-revid')])
940
 
            new_root_entry = (('', '', 'Asecond-root-id'),
941
 
                              [('d', '', 0, False, ''),
942
 
                               ('a', '', 0, False, '')])
943
 
            expected_rows = [new_root_entry, old_root_entry]
 
912
            expected_rows = [
 
913
                (('', '', 'TREE_ROOT'),
 
914
                    [('a', '', 0, False, ''),
 
915
                     ('d', '', 0, False, 'parent-revid'),
 
916
                     ]),
 
917
                (('', '', 'foobarbaz'),
 
918
                    [('d', '', 0, False, ''),
 
919
                     ('a', '', 0, False, ''),
 
920
                     ]),
 
921
                ]
944
922
            state._validate()
945
923
            self.assertEqual(expected_rows, list(state._iter_entries()))
946
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
947
 
            self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=''))
948
 
            self.assertEqual((None, None),
949
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
950
 
            self.assertEqual(old_root_entry,
951
 
                             state._get_entry(1, fileid_utf8='TREE_ROOT'))
952
 
            self.assertEqual(new_root_entry,
953
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
954
 
            self.assertEqual((None, None),
955
 
                             state._get_entry(1, fileid_utf8='Asecond-root-id'))
956
924
            # should work across save too
957
925
            state.save()
958
926
        finally:
974
942
        finally:
975
943
            state.unlock()
976
944
 
 
945
 
977
946
    def test_set_parent_trees_no_content(self):
978
947
        # set_parent_trees is a slow but important api to support.
979
948
        tree1 = self.make_branch_and_memory_tree('tree1')
1033
1002
                [(('', '', root_id), [
1034
1003
                  ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1035
1004
                  ('d', '', 0, False, revid1),
1036
 
                  ('d', '', 0, False, revid1)
 
1005
                  ('d', '', 0, False, revid2)
1037
1006
                  ])],
1038
1007
                list(state._iter_entries()))
1039
1008
        finally:
1067
1036
            (('', '', root_id), [
1068
1037
             ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1069
1038
             ('d', '', 0, False, revid1.encode('utf8')),
1070
 
             ('d', '', 0, False, revid1.encode('utf8'))
 
1039
             ('d', '', 0, False, revid2.encode('utf8'))
1071
1040
             ]),
1072
1041
            (('', 'a file', 'file-id'), [
1073
1042
             ('a', '', 0, False, ''),
1269
1238
        self.assertRaises(errors.BzrError,
1270
1239
            state.add, '..', 'ass-id', 'directory', None, None)
1271
1240
 
1272
 
    def test_set_state_with_rename_b_a_bug_395556(self):
1273
 
        # bug 395556 uncovered a bug where the dirstate ends up with a false
1274
 
        # relocation record - in a tree with no parents there should be no
1275
 
        # absent or relocated records. This then leads to further corruption
1276
 
        # when a commit occurs, as the incorrect relocation gathers an
1277
 
        # incorrect absent in tree 1, and future changes go to pot.
1278
 
        tree1 = self.make_branch_and_tree('tree1')
1279
 
        self.build_tree(['tree1/b'])
1280
 
        tree1.lock_write()
1281
 
        try:
1282
 
            tree1.add(['b'], ['b-id'])
1283
 
            root_id = tree1.get_root_id()
1284
 
            inv = tree1.inventory
1285
 
            state = dirstate.DirState.initialize('dirstate')
1286
 
            try:
1287
 
                # Set the initial state with 'b'
1288
 
                state.set_state_from_inventory(inv)
1289
 
                inv.rename('b-id', root_id, 'a')
1290
 
                # Set the new state with 'a', which currently corrupts.
1291
 
                state.set_state_from_inventory(inv)
1292
 
                expected_result1 = [('', '', root_id, 'd'),
1293
 
                                    ('', 'a', 'b-id', 'f'),
1294
 
                                   ]
1295
 
                values = []
1296
 
                for entry in state._iter_entries():
1297
 
                    values.append(entry[0] + entry[1][0][:1])
1298
 
                self.assertEqual(expected_result1, values)
1299
 
            finally:
1300
 
                state.unlock()
1301
 
        finally:
1302
 
            tree1.unlock()
1303
 
 
1304
1241
 
1305
1242
class TestGetLines(TestCaseWithDirState):
1306
1243