/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

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
821
827
        finally:
822
828
            tree.unlock()
823
829
 
 
830
 
824
831
    def test_set_state_from_inventory_mixed_paths(self):
825
832
        tree1 = self.make_branch_and_tree('tree1')
826
833
        self.build_tree(['tree1/a/', 'tree1/a/b/', 'tree1/a-b/',
867
874
        state = dirstate.DirState.initialize('dirstate')
868
875
        try:
869
876
            # check precondition to be sure the state does change appropriately.
870
 
            root_entry = (('', '', 'TREE_ROOT'), [('d', '', 0, False, 'x'*32)])
871
 
            self.assertEqual([root_entry], list(state._iter_entries()))
872
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
873
 
            self.assertEqual(root_entry,
874
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
875
 
            self.assertEqual((None, None),
876
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
877
 
            state.set_path_id('', 'second-root-id')
878
 
            new_root_entry = (('', '', 'second-root-id'),
879
 
                              [('d', '', 0, False, 'x'*32)])
880
 
            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')])]
881
885
            self.assertEqual(expected_rows, list(state._iter_entries()))
882
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
883
 
            self.assertEqual(new_root_entry, 
884
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
885
 
            self.assertEqual((None, None),
886
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
887
886
            # should work across save too
888
887
            state.save()
889
888
        finally:
907
906
        state._validate()
908
907
        try:
909
908
            state.set_parent_trees([('parent-revid', rt)], ghosts=[])
910
 
            root_entry = (('', '', 'TREE_ROOT'),
911
 
                          [('d', '', 0, False, 'x'*32),
912
 
                           ('d', '', 0, False, 'parent-revid')])
913
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
914
 
            self.assertEqual(root_entry,
915
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
916
 
            self.assertEqual((None, None),
917
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
918
 
            state.set_path_id('', 'Asecond-root-id')
 
909
            state.set_path_id('', 'foobarbaz')
919
910
            state._validate()
920
911
            # now see that it is what we expected
921
 
            old_root_entry = (('', '', 'TREE_ROOT'),
922
 
                              [('a', '', 0, False, ''),
923
 
                               ('d', '', 0, False, 'parent-revid')])
924
 
            new_root_entry = (('', '', 'Asecond-root-id'),
925
 
                              [('d', '', 0, False, ''),
926
 
                               ('a', '', 0, False, '')])
927
 
            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
                ]
928
922
            state._validate()
929
923
            self.assertEqual(expected_rows, list(state._iter_entries()))
930
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
931
 
            self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=''))
932
 
            self.assertEqual((None, None),
933
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
934
 
            self.assertEqual(old_root_entry,
935
 
                             state._get_entry(1, fileid_utf8='TREE_ROOT'))
936
 
            self.assertEqual(new_root_entry,
937
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
938
 
            self.assertEqual((None, None),
939
 
                             state._get_entry(1, fileid_utf8='Asecond-root-id'))
940
924
            # should work across save too
941
925
            state.save()
942
926
        finally:
958
942
        finally:
959
943
            state.unlock()
960
944
 
 
945
 
961
946
    def test_set_parent_trees_no_content(self):
962
947
        # set_parent_trees is a slow but important api to support.
963
948
        tree1 = self.make_branch_and_memory_tree('tree1')
1017
1002
                [(('', '', root_id), [
1018
1003
                  ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1019
1004
                  ('d', '', 0, False, revid1),
1020
 
                  ('d', '', 0, False, revid1)
 
1005
                  ('d', '', 0, False, revid2)
1021
1006
                  ])],
1022
1007
                list(state._iter_entries()))
1023
1008
        finally:
1051
1036
            (('', '', root_id), [
1052
1037
             ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1053
1038
             ('d', '', 0, False, revid1.encode('utf8')),
1054
 
             ('d', '', 0, False, revid1.encode('utf8'))
 
1039
             ('d', '', 0, False, revid2.encode('utf8'))
1055
1040
             ]),
1056
1041
            (('', 'a file', 'file-id'), [
1057
1042
             ('a', '', 0, False, ''),
1253
1238
        self.assertRaises(errors.BzrError,
1254
1239
            state.add, '..', 'ass-id', 'directory', None, None)
1255
1240
 
1256
 
    def test_set_state_with_rename_b_a_bug_395556(self):
1257
 
        # bug 395556 uncovered a bug where the dirstate ends up with a false
1258
 
        # relocation record - in a tree with no parents there should be no
1259
 
        # absent or relocated records. This then leads to further corruption
1260
 
        # when a commit occurs, as the incorrect relocation gathers an
1261
 
        # incorrect absent in tree 1, and future changes go to pot.
1262
 
        tree1 = self.make_branch_and_tree('tree1')
1263
 
        self.build_tree(['tree1/b'])
1264
 
        tree1.lock_write()
1265
 
        try:
1266
 
            tree1.add(['b'], ['b-id'])
1267
 
            root_id = tree1.get_root_id()
1268
 
            inv = tree1.inventory
1269
 
            state = dirstate.DirState.initialize('dirstate')
1270
 
            try:
1271
 
                # Set the initial state with 'b'
1272
 
                state.set_state_from_inventory(inv)
1273
 
                inv.rename('b-id', root_id, 'a')
1274
 
                # Set the new state with 'a', which currently corrupts.
1275
 
                state.set_state_from_inventory(inv)
1276
 
                expected_result1 = [('', '', root_id, 'd'),
1277
 
                                    ('', 'a', 'b-id', 'f'),
1278
 
                                   ]
1279
 
                values = []
1280
 
                for entry in state._iter_entries():
1281
 
                    values.append(entry[0] + entry[1][0][:1])
1282
 
                self.assertEqual(expected_result1, values)
1283
 
            finally:
1284
 
                state.unlock()
1285
 
        finally:
1286
 
            tree1.unlock()
1287
 
 
1288
1241
 
1289
1242
class TestGetLines(TestCaseWithDirState):
1290
1243