~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import tempfile
21
21
 
22
22
from bzrlib import (
23
 
    bzrdir,
 
23
    controldir,
24
24
    dirstate,
25
25
    errors,
26
26
    inventory,
31
31
    tests,
32
32
    workingtree_4,
33
33
    )
34
 
from bzrlib.transport import memory
35
34
from bzrlib.tests import (
36
35
    features,
37
36
    test_osutils,
65
64
    _native_to_unicode = None # Not used yet
66
65
 
67
66
    def setUp(self):
68
 
        tests.TestCaseWithTransport.setUp(self)
69
 
 
 
67
        super(TestCaseWithDirState, self).setUp()
70
68
        self.overrideAttr(osutils,
71
69
                          '_selected_dir_reader', self._dir_reader_class())
72
70
 
756
754
    def test_set_state_from_inventory_no_content_no_parents(self):
757
755
        # setting the current inventory is a slow but important api to support.
758
756
        tree1, revid1 = self.make_minimal_tree()
759
 
        inv = tree1.inventory
 
757
        inv = tree1.root_inventory
760
758
        root_id = inv.path2id('')
761
759
        expected_result = [], [
762
760
            (('', '', root_id), [
777
775
 
778
776
    def test_set_state_from_scratch_no_parents(self):
779
777
        tree1, revid1 = self.make_minimal_tree()
780
 
        inv = tree1.inventory
 
778
        inv = tree1.root_inventory
781
779
        root_id = inv.path2id('')
782
780
        expected_result = [], [
783
781
            (('', '', root_id), [
798
796
 
799
797
    def test_set_state_from_scratch_identical_parent(self):
800
798
        tree1, revid1 = self.make_minimal_tree()
801
 
        inv = tree1.inventory
 
799
        inv = tree1.root_inventory
802
800
        root_id = inv.path2id('')
803
801
        rev_tree1 = tree1.branch.repository.revision_tree(revid1)
804
802
        d_entry = ('d', '', 0, False, dirstate.DirState.NULLSTAT)
856
854
                tree._dirstate._get_entry(0, 'foo-id'))
857
855
 
858
856
            # extract the inventory, and add something to it
859
 
            inv = tree._get_inventory()
 
857
            inv = tree._get_root_inventory()
860
858
            # should see the file we poked in...
861
859
            self.assertTrue(inv.has_id('foo-id'))
862
860
            self.assertTrue(inv.has_filename('foo'))
892
890
                      ['a-id', 'b-id', 'a-b-id', 'foo-id', 'bar-id'])
893
891
            tree1.commit('rev1', rev_id='rev1')
894
892
            root_id = tree1.get_root_id()
895
 
            inv = tree1.inventory
 
893
            inv = tree1.root_inventory
896
894
        finally:
897
895
            tree1.unlock()
898
896
        expected_result1 = [('', '', root_id, 'd'),
1326
1324
        try:
1327
1325
            tree1.add(['b'], ['b-id'])
1328
1326
            root_id = tree1.get_root_id()
1329
 
            inv = tree1.inventory
 
1327
            inv = tree1.root_inventory
1330
1328
            state = dirstate.DirState.initialize('dirstate')
1331
1329
            try:
1332
1330
                # Set the initial state with 'b'
2210
2208
class TestDirstateTreeReference(TestCaseWithDirState):
2211
2209
 
2212
2210
    def test_reference_revision_is_none(self):
2213
 
        tree = self.make_branch_and_tree('tree', format='dirstate-with-subtree')
 
2211
        tree = self.make_branch_and_tree('tree', format='development-subtree')
2214
2212
        subtree = self.make_branch_and_tree('tree/subtree',
2215
 
                            format='dirstate-with-subtree')
 
2213
                            format='development-subtree')
2216
2214
        subtree.set_root_id('subtree')
2217
2215
        tree.add_reference(subtree)
2218
2216
        tree.add('subtree')
2444
2442
    """A minimal api to get InventoryRevisionTree to work."""
2445
2443
 
2446
2444
    def __init__(self):
2447
 
        default_format = bzrdir.format_registry.make_bzrdir('default')
 
2445
        default_format = controldir.format_registry.make_bzrdir('default')
2448
2446
        self._format = default_format.repository_format
2449
2447
 
2450
2448
    def lock_read(self):
2480
2478
    def create_tree_from_shape(self, rev_id, shape):
2481
2479
        dir_ids = {'': 'root-id'}
2482
2480
        inv = inventory.Inventory('root-id', rev_id)
2483
 
        for path, file_id in shape:
 
2481
        for info in shape:
 
2482
            if len(info) == 2:
 
2483
                path, file_id = info
 
2484
                ie_rev_id = rev_id
 
2485
            else:
 
2486
                path, file_id, ie_rev_id = info
2484
2487
            if path == '':
2485
2488
                # Replace the root entry
2486
2489
                del inv._byid[inv.root.file_id]
2488
2491
                inv._byid[file_id] = inv.root
2489
2492
                dir_ids[''] = file_id
2490
2493
                continue
2491
 
            inv.add(self.path_to_ie(path, file_id, rev_id, dir_ids))
 
2494
            inv.add(self.path_to_ie(path, file_id, ie_rev_id, dir_ids))
2492
2495
        return revisiontree.InventoryRevisionTree(_Repo(), inv, rev_id)
2493
2496
 
2494
2497
    def create_empty_dirstate(self):
2527
2530
        basis_tree = self.create_tree_from_shape('basis', basis)
2528
2531
        target_tree = self.create_tree_from_shape('target', target)
2529
2532
        state = self.create_empty_dirstate()
2530
 
        state.set_state_from_scratch(active_tree.inventory,
 
2533
        state.set_state_from_scratch(active_tree.root_inventory,
2531
2534
            [('basis', basis_tree)], [])
2532
 
        delta = target_tree.inventory._make_delta(basis_tree.inventory)
 
2535
        delta = target_tree.root_inventory._make_delta(
 
2536
            basis_tree.root_inventory)
2533
2537
        state.update_basis_by_delta(delta, 'target')
2534
2538
        state._validate()
2535
2539
        dirstate_tree = workingtree_4.DirStateRevisionTree(state,
2540
2544
        # And the dirblock state should be identical to the state if we created
2541
2545
        # it from scratch.
2542
2546
        state2 = self.create_empty_dirstate()
2543
 
        state2.set_state_from_scratch(active_tree.inventory,
 
2547
        state2.set_state_from_scratch(active_tree.root_inventory,
2544
2548
            [('target', target_tree)], [])
2545
2549
        self.assertEqual(state2._dirblocks, state._dirblocks)
2546
2550
        return state
2561
2565
        basis_tree = self.create_tree_from_shape('basis', basis)
2562
2566
        inv_delta = self.create_inv_delta(delta, 'target')
2563
2567
        state = self.create_empty_dirstate()
2564
 
        state.set_state_from_scratch(active_tree.inventory,
 
2568
        state.set_state_from_scratch(active_tree.root_inventory,
2565
2569
            [('basis', basis_tree)], [])
2566
2570
        self.assertRaises(errors.InconsistentDelta,
2567
2571
            state.update_basis_by_delta, inv_delta, 'target')
2616
2620
            target=[('file', 'file-id')],
2617
2621
            )
2618
2622
 
 
2623
    def test_add_file_in_empty_dir_not_matching_active_state(self):
 
2624
        state = self.assertUpdate(
 
2625
                active=[],
 
2626
                basis=[('dir/', 'dir-id')],
 
2627
                target=[('dir/', 'dir-id', 'basis'), ('dir/file', 'file-id')],
 
2628
                )
 
2629
 
2619
2630
    def test_add_file_missing_in_active_state(self):
2620
2631
        state = self.assertUpdate(
2621
2632
            active=[],