~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-08-14 05:49:27 UTC
  • mfrom: (4476.3.86 inventory-delta)
  • Revision ID: pqm@pqm.ubuntu.com-20090814054927-k0k18dn46ax4b91f
(andrew) Add inventory-delta streaming for cross-format fetch.

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
867
873
        state = dirstate.DirState.initialize('dirstate')
868
874
        try:
869
875
            # 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]
 
876
            self.assertEqual(
 
877
                [(('', '', 'TREE_ROOT'), [('d', '', 0, False,
 
878
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])],
 
879
                list(state._iter_entries()))
 
880
            state.set_path_id('', 'foobarbaz')
 
881
            expected_rows = [
 
882
                (('', '', 'foobarbaz'), [('d', '', 0, False,
 
883
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]
881
884
            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
885
            # should work across save too
888
886
            state.save()
889
887
        finally:
907
905
        state._validate()
908
906
        try:
909
907
            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')
 
908
            state.set_path_id('', 'foobarbaz')
919
909
            state._validate()
920
910
            # 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]
 
911
            expected_rows = [
 
912
                (('', '', 'TREE_ROOT'),
 
913
                    [('a', '', 0, False, ''),
 
914
                     ('d', '', 0, False, 'parent-revid'),
 
915
                     ]),
 
916
                (('', '', 'foobarbaz'),
 
917
                    [('d', '', 0, False, ''),
 
918
                     ('a', '', 0, False, ''),
 
919
                     ]),
 
920
                ]
928
921
            state._validate()
929
922
            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
923
            # should work across save too
941
924
            state.save()
942
925
        finally:
1017
1000
                [(('', '', root_id), [
1018
1001
                  ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1019
1002
                  ('d', '', 0, False, revid1),
1020
 
                  ('d', '', 0, False, revid1)
 
1003
                  ('d', '', 0, False, revid2)
1021
1004
                  ])],
1022
1005
                list(state._iter_entries()))
1023
1006
        finally:
1051
1034
            (('', '', root_id), [
1052
1035
             ('d', '', 0, False, dirstate.DirState.NULLSTAT),
1053
1036
             ('d', '', 0, False, revid1.encode('utf8')),
1054
 
             ('d', '', 0, False, revid1.encode('utf8'))
 
1037
             ('d', '', 0, False, revid2.encode('utf8'))
1055
1038
             ]),
1056
1039
            (('', 'a file', 'file-id'), [
1057
1040
             ('a', '', 0, False, ''),