/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 breezy/tests/test_dirstate.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
    def test_dirstate_corrupt(self):
60
60
        error = dirstate.DirstateCorrupt('.bzr/checkout/dirstate',
61
 
                                       'trailing garbage: "x"')
 
61
                                         'trailing garbage: "x"')
62
62
        self.assertEqualDiff("The dirstate file (.bzr/checkout/dirstate)"
63
 
            " appears to be corrupt: trailing garbage: \"x\"",
64
 
            str(error))
 
63
                             " appears to be corrupt: trailing garbage: \"x\"",
 
64
                             str(error))
65
65
 
66
66
 
67
67
load_tests = load_tests_apply_scenarios
74
74
 
75
75
    # Set by load_tests
76
76
    _dir_reader_class = None
77
 
    _native_to_unicode = None # Not used yet
 
77
    _native_to_unicode = None  # Not used yet
78
78
 
79
79
    def setUp(self):
80
80
        super(TestCaseWithDirState, self).setUp()
196
196
        # some operation to get here.
197
197
        self.assertTrue(state._lock_token is not None)
198
198
        try:
199
 
            self.assertEqual(expected_result[0],  state.get_parent_ids())
 
199
            self.assertEqual(expected_result[0], state.get_parent_ids())
200
200
            # there should be no ghosts in this tree.
201
201
            self.assertEqual([], state.get_ghosts())
202
202
            # there should be one fileid in this tree - the root of the tree.
225
225
        """
226
226
        tree = self.make_branch_and_tree('tree')
227
227
        paths = ['a', 'b/', 'b/c', 'b/d/', 'b/d/e', 'b-c', 'f']
228
 
        file_ids = [b'a-id', b'b-id', b'c-id', b'd-id', b'e-id', b'b-c-id', b'f-id']
 
228
        file_ids = [b'a-id', b'b-id', b'c-id',
 
229
                    b'd-id', b'e-id', b'b-c-id', b'f-id']
229
230
        self.build_tree(['tree/' + p for p in paths])
230
231
        tree.set_root_id(b'TREE_ROOT')
231
232
        tree.add([p.rstrip('/') for p in paths], file_ids)
258
259
            b'': ((b'', b'', b'TREE_ROOT'), [
259
260
                  (b'd', b'', 0, False, null_stat),
260
261
                  (b'd', b'', 0, False, revision_id),
261
 
                ]),
 
262
                  ]),
262
263
            b'a': ((b'', b'a', b'a-id'), [
263
264
                   (b'f', b'', 0, False, null_stat),
264
265
                   (b'f', a_sha, a_len, False, revision_id),
265
 
                 ]),
 
266
                   ]),
266
267
            b'b': ((b'', b'b', b'b-id'), [
267
268
                  (b'd', b'', 0, False, null_stat),
268
269
                  (b'd', b'', 0, False, revision_id),
269
 
                 ]),
 
270
                ]),
270
271
            b'b/c': ((b'b', b'c', b'c-id'), [
271
272
                    (b'f', b'', 0, False, null_stat),
272
273
                    (b'f', c_sha, c_len, False, revision_id),
273
 
                   ]),
 
274
                ]),
274
275
            b'b/d': ((b'b', b'd', b'd-id'), [
275
276
                    (b'd', b'', 0, False, null_stat),
276
277
                    (b'd', b'', 0, False, revision_id),
277
 
                   ]),
 
278
                ]),
278
279
            b'b/d/e': ((b'b/d', b'e', b'e-id'), [
279
280
                      (b'f', b'', 0, False, null_stat),
280
281
                      (b'f', e_sha, e_len, False, revision_id),
281
 
                     ]),
 
282
                ]),
282
283
            b'b-c': ((b'', b'b-c', b'b-c-id'), [
283
 
                      (b'f', b'', 0, False, null_stat),
284
 
                      (b'f', b_c_sha, b_c_len, False, revision_id),
285
 
                     ]),
 
284
                (b'f', b'', 0, False, null_stat),
 
285
                (b'f', b_c_sha, b_c_len, False, revision_id),
 
286
                ]),
286
287
            b'f': ((b'', b'f', b'f-id'), [
287
 
                  (b'f', b'', 0, False, null_stat),
288
 
                  (b'f', f_sha, f_len, False, revision_id),
289
 
                 ]),
 
288
                (b'f', b'', 0, False, null_stat),
 
289
                (b'f', f_sha, f_len, False, revision_id),
 
290
                ]),
290
291
        }
291
292
        state = dirstate.DirState.from_tree(tree, 'dirstate')
292
293
        try:
326
327
            # This record was deleted in the current tree
327
328
            expected[path] = (orig[0], [dirstate.DirState.NULL_PARENT_DETAILS,
328
329
                                        orig[1][1]])
329
 
            new_key = (orig[0][0], orig[0][1], orig[0][2]+b'2')
 
330
            new_key = (orig[0][0], orig[0][1], orig[0][2] + b'2')
330
331
            # And didn't exist in the basis tree
331
332
            expected[path2] = (new_key, [orig[1][0],
332
333
                                         dirstate.DirState.NULL_PARENT_DETAILS])
358
359
        tree.rename_one('b/d', 'h')
359
360
 
360
361
        old_a = expected[b'a']
361
 
        expected[b'a'] = (old_a[0], [(b'r', b'b/g', 0, False, b''), old_a[1][1]])
 
362
        expected[b'a'] = (
 
363
            old_a[0], [(b'r', b'b/g', 0, False, b''), old_a[1][1]])
362
364
        expected[b'b/g'] = ((b'b', b'g', b'a-id'), [old_a[1][0],
363
 
                                                (b'r', b'a', 0, False, b'')])
 
365
                                                    (b'r', b'a', 0, False, b'')])
364
366
        old_d = expected[b'b/d']
365
 
        expected[b'b/d'] = (old_d[0], [(b'r', b'h', 0, False, b''), old_d[1][1]])
 
367
        expected[b'b/d'] = (old_d[0],
 
368
                            [(b'r', b'h', 0, False, b''), old_d[1][1]])
366
369
        expected[b'h'] = ((b'', b'h', b'd-id'), [old_d[1][0],
367
 
                                             (b'r', b'b/d', 0, False, b'')])
 
370
                                                 (b'r', b'b/d', 0, False, b'')])
368
371
 
369
372
        old_e = expected[b'b/d/e']
370
373
        expected[b'b/d/e'] = (old_e[0], [(b'r', b'h/e', 0, False, b''),
371
 
                             old_e[1][1]])
 
374
                                         old_e[1][1]])
372
375
        expected[b'h/e'] = ((b'h', b'e', b'e-id'), [old_e[1][0],
373
 
                                                (b'r', b'b/d/e', 0, False, b'')])
 
376
                                                    (b'r', b'b/d/e', 0, False, b'')])
374
377
 
375
378
        state.unlock()
376
379
        try:
391
394
        # There are no files on disk and no parents
392
395
        tree = self.make_branch_and_tree('tree')
393
396
        expected_result = ([], [
394
 
            ((b'', b'', tree.get_root_id()), # common details
395
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
396
 
             ])])
 
397
            ((b'', b'', tree.get_root_id()),  # common details
 
398
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
399
              ])])
397
400
        state = dirstate.DirState.from_tree(tree, 'dirstate')
398
401
        state._validate()
399
402
        self.check_state_with_reopen(expected_result, state)
404
407
        rev_id = tree.commit('first post')
405
408
        root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir))
406
409
        expected_result = ([rev_id], [
407
 
            ((b'', b'', tree.get_root_id()), # common details
408
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
409
 
              (b'd', b'', 0, False, rev_id), # first parent details
410
 
             ])])
 
410
            ((b'', b'', tree.get_root_id()),  # common details
 
411
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
412
              (b'd', b'', 0, False, rev_id),  # first parent details
 
413
              ])])
411
414
        state = dirstate.DirState.from_tree(tree, 'dirstate')
412
415
        self.check_state_with_reopen(expected_result, state)
413
416
        state.lock_read()
424
427
        rev_id2 = tree2.commit('second post', allow_pointless=True)
425
428
        tree.merge_from_branch(tree2.branch)
426
429
        expected_result = ([rev_id, rev_id2], [
427
 
            ((b'', b'', tree.get_root_id()), # common details
428
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
429
 
              (b'd', b'', 0, False, rev_id), # first parent details
430
 
              (b'd', b'', 0, False, rev_id), # second parent details
431
 
             ])])
 
430
            ((b'', b'', tree.get_root_id()),  # common details
 
431
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
432
              (b'd', b'', 0, False, rev_id),  # first parent details
 
433
              (b'd', b'', 0, False, rev_id),  # second parent details
 
434
              ])])
432
435
        state = dirstate.DirState.from_tree(tree, 'dirstate')
433
436
        self.check_state_with_reopen(expected_result, state)
434
437
        state.lock_read()
443
446
        tree = self.make_branch_and_tree('tree')
444
447
        self.build_tree(['tree/unknown'])
445
448
        expected_result = ([], [
446
 
            ((b'', b'', tree.get_root_id()), # common details
447
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
448
 
             ])])
 
449
            ((b'', b'', tree.get_root_id()),  # common details
 
450
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
451
              ])])
449
452
        state = dirstate.DirState.from_tree(tree, 'dirstate')
450
453
        self.check_state_with_reopen(expected_result, state)
451
454
 
460
463
        # There are files on disk and no parents
461
464
        tree = self.get_tree_with_a_file()
462
465
        expected_result = ([], [
463
 
            ((b'', b'', tree.get_root_id()), # common details
464
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
465
 
             ]),
466
 
            ((b'', b'a file', b'a-file-id'), # common
467
 
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT), # current
468
 
             ]),
 
466
            ((b'', b'', tree.get_root_id()),  # common details
 
467
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
468
              ]),
 
469
            ((b'', b'a file', b'a-file-id'),  # common
 
470
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT),  # current
 
471
              ]),
469
472
            ])
470
473
        state = dirstate.DirState.from_tree(tree, 'dirstate')
471
474
        self.check_state_with_reopen(expected_result, state)
478
481
        # and length:
479
482
        self.build_tree_contents([('tree/a file', b'new content\n')])
480
483
        expected_result = ([rev_id], [
481
 
            ((b'', b'', tree.get_root_id()), # common details
482
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
483
 
              (b'd', b'', 0, False, rev_id), # first parent details
484
 
             ]),
485
 
            ((b'', b'a file', b'a-file-id'), # common
486
 
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT), # current
 
484
            ((b'', b'', tree.get_root_id()),  # common details
 
485
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
486
              (b'd', b'', 0, False, rev_id),  # first parent details
 
487
              ]),
 
488
            ((b'', b'a file', b'a-file-id'),  # common
 
489
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT),  # current
487
490
              (b'f', b'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False,
488
 
               rev_id), # first parent
489
 
             ]),
 
491
               rev_id),  # first parent
 
492
              ]),
490
493
            ])
491
494
        state = dirstate.DirState.from_tree(tree, 'dirstate')
492
495
        self.check_state_with_reopen(expected_result, state)
505
508
        # and length again, giving us three distinct values:
506
509
        self.build_tree_contents([('tree/a file', b'new content\n')])
507
510
        expected_result = ([rev_id, rev_id2], [
508
 
            ((b'', b'', tree.get_root_id()), # common details
509
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
510
 
              (b'd', b'', 0, False, rev_id), # first parent details
511
 
              (b'd', b'', 0, False, rev_id), # second parent details
512
 
             ]),
513
 
            ((b'', b'a file', b'a-file-id'), # common
514
 
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT), # current
 
511
            ((b'', b'', tree.get_root_id()),  # common details
 
512
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
513
              (b'd', b'', 0, False, rev_id),  # first parent details
 
514
              (b'd', b'', 0, False, rev_id),  # second parent details
 
515
              ]),
 
516
            ((b'', b'a file', b'a-file-id'),  # common
 
517
             [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT),  # current
515
518
              (b'f', b'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False,
516
 
               rev_id), # first parent
 
519
               rev_id),  # first parent
517
520
              (b'f', b'314d796174c9412647c3ce07dfb5d36a94e72958', 14, False,
518
 
               rev_id2), # second parent
519
 
             ]),
 
521
               rev_id2),  # second parent
 
522
              ]),
520
523
            ])
521
524
        state = dirstate.DirState.from_tree(tree, 'dirstate')
522
525
        self.check_state_with_reopen(expected_result, state)
529
532
        parents = []
530
533
        for i in range(7):
531
534
            tree = self.make_branch_and_tree('tree%d' % i)
532
 
            self.build_tree(['tree%d/name' % i,])
 
535
            self.build_tree(['tree%d/name' % i, ])
533
536
            tree.add(['name'], [b'file-id%d' % i])
534
537
            revision_id = b'revid-%d' % i
535
538
            tree.commit('message', rev_id=revision_id)
536
539
            parents.append((revision_id,
537
 
                tree.branch.repository.revision_tree(revision_id)))
 
540
                            tree.branch.repository.revision_tree(revision_id)))
538
541
        # now fold these trees into a dirstate
539
542
        state = dirstate.DirState.initialize('dirstate')
540
543
        try:
570
573
        # get a state object
571
574
        # no parents, default tree content
572
575
        expected_result = ([], [
573
 
            ((b'', b'', tree.get_root_id()), # common details
 
576
            ((b'', b'', tree.get_root_id()),  # common details
574
577
             # current tree details, but new from_tree skips statting, it
575
578
             # uses set_state_from_inventory, and thus depends on the
576
579
             # inventory state.
577
580
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),
578
 
             ])
 
581
              ])
579
582
            ])
580
583
        state = dirstate.DirState.on_file('dirstate')
581
 
        state.lock_write() # check_state_with_reopen will save() and unlock it
 
584
        state.lock_write()  # check_state_with_reopen will save() and unlock it
582
585
        self.check_state_with_reopen(expected_result, state)
583
586
 
584
587
    def test_can_save_clean_on_file(self):
689
692
        # The dirstate should include TREE_ROOT and 'a-file' and nothing else
690
693
        expected_blocks = [
691
694
            (b'', [((b'', b'', b'TREE_ROOT'),
692
 
                   [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT)])]),
 
695
                    [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT)])]),
693
696
            (b'', [((b'', b'a-file', b'a-file-id'),
694
 
                   [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT)])]),
 
697
                    [(b'f', b'', 0, False, dirstate.DirState.NULLSTAT)])]),
695
698
        ]
696
699
 
697
700
        state = dirstate.DirState.on_file('dirstate')
720
723
 
721
724
    def test_initialize(self):
722
725
        expected_result = ([], [
723
 
            ((b'', b'', b'TREE_ROOT'), # common details
724
 
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
725
 
             ])
 
726
            ((b'', b'', b'TREE_ROOT'),  # common details
 
727
             [(b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
 
728
              ])
726
729
            ])
727
730
        state = dirstate.DirState.initialize('dirstate')
728
731
        try:
734
737
        # process. So we have to unlock and release before we check the file
735
738
        # contents.
736
739
        self.assertFileEqual(b''.join(lines), 'dirstate')
737
 
        state.lock_read() # check_state_with_reopen will unlock
 
740
        state.lock_read()  # check_state_with_reopen will unlock
738
741
        self.check_state_with_reopen(expected_result, state)
739
742
 
740
743
 
906
909
                            (b'a', b'b', b'b-id', b'd'),
907
910
                            (b'a/b', b'foo', b'foo-id', b'f'),
908
911
                            (b'a-b', b'bar', b'bar-id', b'f'),
909
 
                           ]
 
912
                            ]
910
913
        expected_result2 = [(b'', b'', root_id, b'd'),
911
914
                            (b'', b'a', b'a-id', b'd'),
912
915
                            (b'', b'a-b', b'a-b-id', b'd'),
913
916
                            (b'a-b', b'bar', b'bar-id', b'f'),
914
 
                           ]
 
917
                            ]
915
918
        state = dirstate.DirState.initialize('dirstate')
916
919
        try:
917
920
            state.set_state_from_inventory(inv)
933
936
        state = dirstate.DirState.initialize('dirstate')
934
937
        try:
935
938
            # check precondition to be sure the state does change appropriately.
936
 
            root_entry = ((b'', b'', b'TREE_ROOT'), [(b'd', b'', 0, False, b'x'*32)])
 
939
            root_entry = ((b'', b'', b'TREE_ROOT'), [
 
940
                          (b'd', b'', 0, False, b'x' * 32)])
937
941
            self.assertEqual([root_entry], list(state._iter_entries()))
938
942
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=b''))
939
943
            self.assertEqual(root_entry,
942
946
                             state._get_entry(0, fileid_utf8=b'second-root-id'))
943
947
            state.set_path_id(b'', b'second-root-id')
944
948
            new_root_entry = ((b'', b'', b'second-root-id'),
945
 
                              [(b'd', b'', 0, False, b'x'*32)])
 
949
                              [(b'd', b'', 0, False, b'x' * 32)])
946
950
            expected_rows = [new_root_entry]
947
951
            self.assertEqual(expected_rows, list(state._iter_entries()))
948
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=b''))
 
952
            self.assertEqual(
 
953
                new_root_entry, state._get_entry(0, path_utf8=b''))
949
954
            self.assertEqual(new_root_entry,
950
955
                             state._get_entry(0, fileid_utf8=b'second-root-id'))
951
956
            self.assertEqual((None, None),
974
979
        try:
975
980
            state.set_parent_trees([(b'parent-revid', rt)], ghosts=[])
976
981
            root_entry = ((b'', b'', b'TREE_ROOT'),
977
 
                          [(b'd', b'', 0, False, b'x'*32),
 
982
                          [(b'd', b'', 0, False, b'x' * 32),
978
983
                           (b'd', b'', 0, False, b'parent-revid')])
979
984
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=b''))
980
985
            self.assertEqual(root_entry,
993
998
            expected_rows = [new_root_entry, old_root_entry]
994
999
            state._validate()
995
1000
            self.assertEqual(expected_rows, list(state._iter_entries()))
996
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=b''))
997
 
            self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=b''))
 
1001
            self.assertEqual(
 
1002
                new_root_entry, state._get_entry(0, path_utf8=b''))
 
1003
            self.assertEqual(
 
1004
                old_root_entry, state._get_entry(1, path_utf8=b''))
998
1005
            self.assertEqual((None, None),
999
1006
                             state._get_entry(0, fileid_utf8=b'TREE_ROOT'))
1000
1007
            self.assertEqual(old_root_entry,
1073
1080
                ((revid1, tree1.branch.repository.revision_tree(revid1)),
1074
1081
                 (revid2, tree2.branch.repository.revision_tree(revid2)),
1075
1082
                 (b'ghost-rev', tree2.branch.repository.revision_tree(
1076
 
                                   _mod_revision.NULL_REVISION))),
 
1083
                     _mod_revision.NULL_REVISION))),
1077
1084
                [b'ghost-rev'])
1078
1085
            self.assertEqual([revid1, revid2, b'ghost-rev'],
1079
1086
                             state.get_parent_ids())
1141
1148
            # check_state_with_reopen will unlock
1142
1149
            self.check_state_with_reopen(expected_result, state)
1143
1150
 
1144
 
    ### add a path via _set_data - so we dont need delta work, just
 
1151
    # add a path via _set_data - so we dont need delta work, just
1145
1152
    # raw data in, and ensure that it comes out via get_lines happily.
1146
1153
 
1147
1154
    def test_add_path_to_root_no_parents_all_data(self):
1153
1160
        state = dirstate.DirState.initialize('dirstate')
1154
1161
        expected_entries = [
1155
1162
            ((b'', b'', b'TREE_ROOT'), [
1156
 
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
 
1163
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
1157
1164
             ]),
1158
1165
            ((b'', b'a file', b'a-file-id'), [
1159
 
             (b'f', b'1'*20, 19, False, dirstate.pack_stat(stat)), # current tree
 
1166
             (b'f', b'1' * 20, 19, False, dirstate.pack_stat(stat)),  # current tree
1160
1167
             ]),
1161
1168
            ]
1162
1169
        try:
1163
 
            state.add('a file', b'a-file-id', 'file', stat, b'1'*20)
 
1170
            state.add('a file', b'a-file-id', 'file', stat, b'1' * 20)
1164
1171
            # having added it, it should be in the output of iter_entries.
1165
1172
            self.assertEqual(expected_entries, list(state._iter_entries()))
1166
1173
            # saving and reloading should not affect this.
1192
1199
        stat = os.lstat('a dir')
1193
1200
        expected_entries = [
1194
1201
            ((b'', b'', b'TREE_ROOT'), [
1195
 
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
 
1202
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
1196
1203
             ]),
1197
1204
            ((b'', b'a dir', b'a dir id'), [
1198
 
             (b'd', b'', 0, False, dirstate.pack_stat(stat)), # current tree
 
1205
             (b'd', b'', 0, False, dirstate.pack_stat(stat)),  # current tree
1199
1206
             ]),
1200
1207
            ]
1201
1208
        state = dirstate.DirState.initialize('dirstate')
1222
1229
        stat = os.lstat(link_name)
1223
1230
        expected_entries = [
1224
1231
            ((b'', b'', b'TREE_ROOT'), [
1225
 
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
 
1232
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
1226
1233
             ]),
1227
1234
            ((b'', link_name.encode('UTF-8'), b'a link id'), [
1228
1235
             (b'l', target.encode('UTF-8'), stat[6],
1229
 
              False, dirstate.pack_stat(stat)), # current tree
 
1236
              False, dirstate.pack_stat(stat)),  # current tree
1230
1237
             ]),
1231
1238
            ]
1232
1239
        state = dirstate.DirState.initialize('dirstate')
1245
1252
        self.assertEqual(expected_entries, list(state._iter_entries()))
1246
1253
 
1247
1254
    def test_add_symlink_to_root_no_parents_all_data(self):
1248
 
        self._test_add_symlink_to_root_no_parents_all_data(u'a link', u'target')
 
1255
        self._test_add_symlink_to_root_no_parents_all_data(
 
1256
            u'a link', u'target')
1249
1257
 
1250
1258
    def test_add_symlink_unicode_to_root_no_parents_all_data(self):
1251
1259
        self.requireFeature(features.UnicodeFilenameFeature)
1259
1267
        filestat = os.lstat('a dir/a file')
1260
1268
        expected_entries = [
1261
1269
            ((b'', b'', b'TREE_ROOT'), [
1262
 
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT), # current tree
 
1270
             (b'd', b'', 0, False, dirstate.DirState.NULLSTAT),  # current tree
1263
1271
             ]),
1264
1272
            ((b'', b'a dir', b'a dir id'), [
1265
 
             (b'd', b'', 0, False, dirstate.pack_stat(dirstat)), # current tree
 
1273
             (b'd', b'', 0, False, dirstate.pack_stat(dirstat)),  # current tree
1266
1274
             ]),
1267
1275
            ((b'a dir', b'a file', b'a-file-id'), [
1268
 
             (b'f', b'1'*20, 25, False,
1269
 
              dirstate.pack_stat(filestat)), # current tree details
 
1276
             (b'f', b'1' * 20, 25, False,
 
1277
              dirstate.pack_stat(filestat)),  # current tree details
1270
1278
             ]),
1271
1279
            ]
1272
1280
        state = dirstate.DirState.initialize('dirstate')
1273
1281
        try:
1274
1282
            state.add('a dir', b'a dir id', 'directory', dirstat, None)
1275
 
            state.add('a dir/a file', b'a-file-id', 'file', filestat, b'1'*20)
 
1283
            state.add('a dir/a file', b'a-file-id',
 
1284
                      'file', filestat, b'1' * 20)
1276
1285
            # added it, it should be in the output of iter_entries.
1277
1286
            self.assertEqual(expected_entries, list(state._iter_entries()))
1278
1287
            # saving and reloading should not affect this.
1293
1302
              b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')],
1294
1303
            )
1295
1304
        try:
1296
 
            state.add('subdir', b'subdir-id', 'tree-reference', None, b'subtree-123123')
 
1305
            state.add('subdir', b'subdir-id', 'tree-reference',
 
1306
                      None, b'subtree-123123')
1297
1307
            entry = state._get_entry(0, b'subdir-id', b'subdir')
1298
1308
            self.assertEqual(entry, expected_entry)
1299
1309
            state._validate()
1315
1325
        state = dirstate.DirState.initialize('dirstate')
1316
1326
        self.addCleanup(state.unlock)
1317
1327
        self.assertRaises(errors.BzrError,
1318
 
            state.add, '.', b'ass-id', 'directory', None, None)
 
1328
                          state.add, '.', b'ass-id', 'directory', None, None)
1319
1329
        self.assertRaises(errors.BzrError,
1320
 
            state.add, '..', b'ass-id', 'directory', None, None)
 
1330
                          state.add, '..', b'ass-id', 'directory', None, None)
1321
1331
 
1322
1332
    def test_set_state_with_rename_b_a_bug_395556(self):
1323
1333
        # bug 395556 uncovered a bug where the dirstate ends up with a false
1341
1351
                state.set_state_from_inventory(inv)
1342
1352
                expected_result1 = [(b'', b'', root_id, b'd'),
1343
1353
                                    (b'', b'a', b'b-id', b'f'),
1344
 
                                   ]
 
1354
                                    ]
1345
1355
                values = []
1346
1356
                for entry in state._iter_entries():
1347
1357
                    values.append(entry[0] + entry[1][0][:1])
1384
1394
        state.lock_write()
1385
1395
        self.addCleanup(state.unlock)
1386
1396
        state._read_dirblocks_if_needed()
1387
 
        state.adjust_time(+20) # Allow things to be cached
 
1397
        state.adjust_time(+20)  # Allow things to be cached
1388
1398
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1389
1399
                         state._dirblock_state)
1390
1400
        content = self._read_state_content(state)
1414
1424
        state = self.create_dirstate_with_root_and_subdir()
1415
1425
        try:
1416
1426
            self.assertEqual([b'#bazaar dirstate flat format 3\n',
1417
 
                b'crc32: 41262208\n',
1418
 
                b'num_entries: 2\n',
1419
 
                b'0\x00\n\x00'
1420
 
                b'0\x00\n\x00'
1421
 
                b'\x00\x00a-root-value\x00'
1422
 
                b'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00'
1423
 
                b'\x00subdir\x00subdir-id\x00'
1424
 
                b'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00'
1425
 
                ], state.get_lines())
 
1427
                              b'crc32: 41262208\n',
 
1428
                              b'num_entries: 2\n',
 
1429
                              b'0\x00\n\x00'
 
1430
                              b'0\x00\n\x00'
 
1431
                              b'\x00\x00a-root-value\x00'
 
1432
                              b'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00'
 
1433
                              b'\x00subdir\x00subdir-id\x00'
 
1434
                              b'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00'
 
1435
                              ], state.get_lines())
1426
1436
        finally:
1427
1437
            state.unlock()
1428
1438
 
1439
1449
    def test_entry_to_line_with_parent(self):
1440
1450
        packed_stat = b'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
1441
1451
        root_entry = (b'', b'', b'a-root-value'), [
1442
 
            (b'd', b'', 0, False, packed_stat), # current tree details
1443
 
             # first: a pointer to the current location
 
1452
            (b'd', b'', 0, False, packed_stat),  # current tree details
 
1453
            # first: a pointer to the current location
1444
1454
            (b'a', b'dirname/basename', 0, False, b''),
1445
1455
            ]
1446
1456
        state = dirstate.DirState.initialize('dirstate')
1457
1467
        # / in the tree, at / in one parent and /dirname/basename in the other.
1458
1468
        packed_stat = b'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
1459
1469
        root_entry = (b'', b'', b'a-root-value'), [
1460
 
            (b'd', b'', 0, False, packed_stat), # current tree details
1461
 
            (b'd', b'', 0, False, b'rev_id'), # first parent details
1462
 
             # second: a pointer to the current location
 
1470
            (b'd', b'', 0, False, packed_stat),  # current tree details
 
1471
            (b'd', b'', 0, False, b'rev_id'),  # first parent details
 
1472
            # second: a pointer to the current location
1463
1473
            (b'a', b'dirname/basename', 0, False, b''),
1464
1474
            ]
1465
1475
        state = dirstate.DirState.initialize('dirstate')
1479
1489
        packed_stat = b'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
1480
1490
        dirblocks = []
1481
1491
        root_entries = [((b'', b'', b'a-root-value'), [
1482
 
            (b'd', b'', 0, False, packed_stat), # current tree details
 
1492
            (b'd', b'', 0, False, packed_stat),  # current tree details
1483
1493
            ])]
1484
1494
        dirblocks.append(('', root_entries))
1485
1495
        # add two files in the root
1486
1496
        subdir_entry = (b'', b'subdir', b'subdir-id'), [
1487
 
            (b'd', b'', 0, False, packed_stat), # current tree details
 
1497
            (b'd', b'', 0, False, packed_stat),  # current tree details
1488
1498
            ]
1489
1499
        afile_entry = (b'', b'afile', b'afile-id'), [
1490
 
            (b'f', b'sha1value', 34, False, packed_stat), # current tree details
 
1500
            (b'f', b'sha1value', 34, False, packed_stat),  # current tree details
1491
1501
            ]
1492
1502
        dirblocks.append(('', [subdir_entry, afile_entry]))
1493
1503
        # and one in subdir
1494
1504
        file_entry2 = (b'subdir', b'2file', b'2file-id'), [
1495
 
            (b'f', b'sha1value', 23, False, packed_stat), # current tree details
 
1505
            (b'f', b'sha1value', 23, False, packed_stat),  # current tree details
1496
1506
            ]
1497
1507
        dirblocks.append(('subdir', [file_entry2]))
1498
1508
        state = dirstate.DirState.initialize('dirstate')
1508
1518
class TestGetBlockRowIndex(TestCaseWithDirState):
1509
1519
 
1510
1520
    def assertBlockRowIndexEqual(self, block_index, row_index, dir_present,
1511
 
        file_present, state, dirname, basename, tree_index):
 
1521
                                 file_present, state, dirname, basename, tree_index):
1512
1522
        self.assertEqual((block_index, row_index, dir_present, file_present),
1513
 
            state._get_block_entry_index(dirname, basename, tree_index))
 
1523
                         state._get_block_entry_index(dirname, basename, tree_index))
1514
1524
        if dir_present:
1515
1525
            block = state._dirblocks[block_index]
1516
1526
            self.assertEqual(dirname, block[0])
1522
1532
    def test_simple_structure(self):
1523
1533
        state = self.create_dirstate_with_root_and_subdir()
1524
1534
        self.addCleanup(state.unlock)
1525
 
        self.assertBlockRowIndexEqual(1, 0, True, True, state, b'', b'subdir', 0)
1526
 
        self.assertBlockRowIndexEqual(1, 0, True, False, state, b'', b'bdir', 0)
1527
 
        self.assertBlockRowIndexEqual(1, 1, True, False, state, b'', b'zdir', 0)
1528
 
        self.assertBlockRowIndexEqual(2, 0, False, False, state, b'a', b'foo', 0)
 
1535
        self.assertBlockRowIndexEqual(
 
1536
            1, 0, True, True, state, b'', b'subdir', 0)
 
1537
        self.assertBlockRowIndexEqual(
 
1538
            1, 0, True, False, state, b'', b'bdir', 0)
 
1539
        self.assertBlockRowIndexEqual(
 
1540
            1, 1, True, False, state, b'', b'zdir', 0)
 
1541
        self.assertBlockRowIndexEqual(
 
1542
            2, 0, False, False, state, b'a', b'foo', 0)
1529
1543
        self.assertBlockRowIndexEqual(2, 0, False, False, state,
1530
1544
                                      b'subdir', b'foo', 0)
1531
1545
 
1555
1569
        self.assertBlockRowIndexEqual(1, 4, True, False, state,
1556
1570
                                      b'', b'h\xc3\xa5', 0)
1557
1571
        self.assertBlockRowIndexEqual(2, 0, False, False, state, b'_', b'a', 0)
1558
 
        self.assertBlockRowIndexEqual(3, 0, False, False, state, b'aa', b'a', 0)
1559
 
        self.assertBlockRowIndexEqual(4, 0, False, False, state, b'bb', b'a', 0)
 
1572
        self.assertBlockRowIndexEqual(
 
1573
            3, 0, False, False, state, b'aa', b'a', 0)
 
1574
        self.assertBlockRowIndexEqual(
 
1575
            4, 0, False, False, state, b'bb', b'a', 0)
1560
1576
        # This would be inserted between a/ and b/
1561
 
        self.assertBlockRowIndexEqual(3, 0, False, False, state, b'a/e', b'a', 0)
 
1577
        self.assertBlockRowIndexEqual(
 
1578
            3, 0, False, False, state, b'a/e', b'a', 0)
1562
1579
        # Put at the end
1563
1580
        self.assertBlockRowIndexEqual(4, 0, False, False, state, b'e', b'a', 0)
1564
1581
 
1578
1595
        state = self.create_dirstate_with_root_and_subdir()
1579
1596
        self.addCleanup(state.unlock)
1580
1597
        self.assertEntryEqual(b'', b'', b'a-root-value', state, b'', 0)
1581
 
        self.assertEntryEqual(b'', b'subdir', b'subdir-id', state, b'subdir', 0)
 
1598
        self.assertEntryEqual(
 
1599
            b'', b'subdir', b'subdir-id', state, b'subdir', 0)
1582
1600
        self.assertEntryEqual(None, None, None, state, b'missing', 0)
1583
1601
        self.assertEntryEqual(None, None, None, state, b'missing/foo', 0)
1584
1602
        self.assertEntryEqual(None, None, None, state, b'subdir/foo', 0)
1705
1723
        dirblocks.append((b'', [root_entry]))
1706
1724
        dirblocks.append((b'', [a_entry, b_entry, c_entry, d_entry]))
1707
1725
        dirblocks.append((b'a', [e_entry, f_entry]))
1708
 
        dirblocks.append((b'b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
 
1726
        dirblocks.append(
 
1727
            (b'b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
1709
1728
        state = dirstate.DirState.initialize('dirstate')
1710
1729
        state._validate()
1711
1730
        try:
1719
1738
        state, dirblocks = self.create_dirstate_with_two_trees()
1720
1739
        self.addCleanup(state.unlock)
1721
1740
        expected_result = []
1722
 
        expected_result.append(dirblocks[3][1][2]) # h2
1723
 
        expected_result.append(dirblocks[3][1][3]) # i
1724
 
        expected_result.append(dirblocks[3][1][4]) # j
 
1741
        expected_result.append(dirblocks[3][1][2])  # h2
 
1742
        expected_result.append(dirblocks[3][1][3])  # i
 
1743
        expected_result.append(dirblocks[3][1][4])  # j
1725
1744
        self.assertEqual(expected_result,
1726
 
            list(state._iter_child_entries(1, b'b')))
 
1745
                         list(state._iter_child_entries(1, b'b')))
1727
1746
 
1728
1747
    def test_iter_child_root(self):
1729
1748
        state, dirblocks = self.create_dirstate_with_two_trees()
1730
1749
        self.addCleanup(state.unlock)
1731
1750
        expected_result = []
1732
 
        expected_result.append(dirblocks[1][1][0]) # a
1733
 
        expected_result.append(dirblocks[1][1][1]) # b
1734
 
        expected_result.append(dirblocks[1][1][3]) # d
1735
 
        expected_result.append(dirblocks[2][1][0]) # e
1736
 
        expected_result.append(dirblocks[2][1][1]) # f
1737
 
        expected_result.append(dirblocks[3][1][2]) # h2
1738
 
        expected_result.append(dirblocks[3][1][3]) # i
1739
 
        expected_result.append(dirblocks[3][1][4]) # j
 
1751
        expected_result.append(dirblocks[1][1][0])  # a
 
1752
        expected_result.append(dirblocks[1][1][1])  # b
 
1753
        expected_result.append(dirblocks[1][1][3])  # d
 
1754
        expected_result.append(dirblocks[2][1][0])  # e
 
1755
        expected_result.append(dirblocks[2][1][1])  # f
 
1756
        expected_result.append(dirblocks[3][1][2])  # h2
 
1757
        expected_result.append(dirblocks[3][1][3])  # i
 
1758
        expected_result.append(dirblocks[3][1][4])  # j
1740
1759
        self.assertEqual(expected_result,
1741
 
            list(state._iter_child_entries(1, b'')))
 
1760
                         list(state._iter_child_entries(1, b'')))
1742
1761
 
1743
1762
 
1744
1763
class TestDirstateSortOrder(tests.TestCaseWithTransport):
1753
1772
        """
1754
1773
        dirs = ['a', 'a/a', 'a/a/a', 'a/a/a/a',
1755
1774
                'a-a', 'a/a-a', 'a/a/a-a', 'a/a/a/a-a',
1756
 
               ]
 
1775
                ]
1757
1776
        null_sha = b''
1758
1777
        state = dirstate.DirState.initialize('dirstate')
1759
1778
        self.addCleanup(state.unlock)
1760
1779
 
1761
1780
        fake_stat = os.stat('dirstate')
1762
1781
        for d in dirs:
1763
 
            d_id = d.encode('utf-8').replace(b'/', b'_')+b'-id'
 
1782
            d_id = d.encode('utf-8').replace(b'/', b'_') + b'-id'
1764
1783
            file_path = d + '/f'
1765
 
            file_id = file_path.encode('utf-8').replace(b'/', b'_')+b'-id'
 
1784
            file_id = file_path.encode('utf-8').replace(b'/', b'_') + b'-id'
1766
1785
            state.add(d, d_id, 'directory', fake_stat, null_sha)
1767
1786
            state.add(file_path, file_id, 'file', fake_stat, null_sha)
1768
1787
 
1769
1788
        expected = [b'', b'', b'a',
1770
 
                b'a/a', b'a/a/a', b'a/a/a/a',
1771
 
                b'a/a/a/a-a', b'a/a/a-a', b'a/a-a', b'a-a',
1772
 
               ]
1773
 
        split = lambda p:p.split(b'/')
 
1789
                    b'a/a', b'a/a/a', b'a/a/a/a',
 
1790
                    b'a/a/a/a-a', b'a/a/a-a', b'a/a-a', b'a-a',
 
1791
                    ]
 
1792
 
 
1793
        def split(p): return p.split(b'/')
1774
1794
        self.assertEqual(sorted(expected, key=split), expected)
1775
1795
        dirblock_names = [d[0] for d in state._dirblocks]
1776
1796
        self.assertEqual(expected, dirblock_names)
1784
1804
 
1785
1805
        fake_stat = os.stat('dirstate')
1786
1806
        for d in dirs:
1787
 
            d_id = d.encode('utf-8').replace(b'/', b'_')+b'-id'
 
1807
            d_id = d.encode('utf-8').replace(b'/', b'_') + b'-id'
1788
1808
            file_path = d + '/f'
1789
 
            file_id = file_path.encode('utf-8').replace(b'/', b'_')+b'-id'
 
1809
            file_id = file_path.encode('utf-8').replace(b'/', b'_') + b'-id'
1790
1810
            state.add(d, d_id, 'directory', fake_stat, null_sha)
1791
1811
            state.add(file_path, file_id, 'file', fake_stat, null_sha)
1792
1812
 
1808
1828
 
1809
1829
    def __init__(self, path, sha1_provider, worth_saving_limit=0):
1810
1830
        super(InstrumentedDirState, self).__init__(path, sha1_provider,
1811
 
            worth_saving_limit=worth_saving_limit)
 
1831
                                                   worth_saving_limit=worth_saving_limit)
1812
1832
        self._time_offset = 0
1813
1833
        self._log = []
1814
1834
        # member is dynamically set in DirState.__init__ to turn on trace
1861
1881
    @staticmethod
1862
1882
    def from_stat(st):
1863
1883
        return _FakeStat(st.st_size, st.st_mtime, st.st_ctime, st.st_dev,
1864
 
            st.st_ino, st.st_mode)
 
1884
                         st.st_ino, st.st_mode)
1865
1885
 
1866
1886
 
1867
1887
class TestPackStat(tests.TestCaseWithTransport):
2092
2112
    def test_bisect_dirblocks(self):
2093
2113
        tree, state, expected = self.create_duplicated_dirstate()
2094
2114
        self.assertBisectDirBlocks(expected,
2095
 
            [[b'', b'a', b'a2', b'b', b'b2', b'b-c', b'b-c2', b'f', b'f2']],
2096
 
            state, [b''])
2097
 
        self.assertBisectDirBlocks(expected,
2098
 
            [[b'b/c', b'b/c2', b'b/d', b'b/d2']], state, [b'b'])
2099
 
        self.assertBisectDirBlocks(expected,
2100
 
            [[b'b/d/e', b'b/d/e2']], state, [b'b/d'])
2101
 
        self.assertBisectDirBlocks(expected,
2102
 
            [[b'', b'a', b'a2', b'b', b'b2', b'b-c', b'b-c2', b'f', b'f2'],
2103
 
             [b'b/c', b'b/c2', b'b/d', b'b/d2'],
2104
 
             [b'b/d/e', b'b/d/e2'],
2105
 
            ], state, [b'', b'b', b'b/d'])
 
2115
                                   [[b'', b'a', b'a2', b'b', b'b2',
 
2116
                                       b'b-c', b'b-c2', b'f', b'f2']],
 
2117
                                   state, [b''])
 
2118
        self.assertBisectDirBlocks(expected,
 
2119
                                   [[b'b/c', b'b/c2', b'b/d', b'b/d2']], state, [b'b'])
 
2120
        self.assertBisectDirBlocks(expected,
 
2121
                                   [[b'b/d/e', b'b/d/e2']], state, [b'b/d'])
 
2122
        self.assertBisectDirBlocks(expected,
 
2123
                                   [[b'', b'a', b'a2', b'b', b'b2', b'b-c', b'b-c2', b'f', b'f2'],
 
2124
                                    [b'b/c', b'b/c2', b'b/d', b'b/d2'],
 
2125
                                       [b'b/d/e', b'b/d/e2'],
 
2126
                                    ], state, [b'', b'b', b'b/d'])
2106
2127
 
2107
2128
    def test_bisect_dirblocks_missing(self):
2108
2129
        tree, state, expected = self.create_basic_dirstate()
2109
2130
        self.assertBisectDirBlocks(expected, [[b'b/d/e'], None],
2110
 
            state, [b'b/d', b'b/e'])
 
2131
                                   state, [b'b/d', b'b/e'])
2111
2132
        # Files don't show up in this search
2112
2133
        self.assertBisectDirBlocks(expected, [None], state, [b'a'])
2113
2134
        self.assertBisectDirBlocks(expected, [None], state, [b'b/c'])
2131
2152
 
2132
2153
    def test_bisect_recursive_multiple(self):
2133
2154
        tree, state, expected = self.create_basic_dirstate()
2134
 
        self.assertBisectRecursive(expected, [b'a', b'b/c'], state, [b'a', b'b/c'])
 
2155
        self.assertBisectRecursive(
 
2156
            expected, [b'a', b'b/c'], state, [b'a', b'b/c'])
2135
2157
        self.assertBisectRecursive(expected, [b'b/d', b'b/d/e'],
2136
2158
                                   state, [b'b/d', b'b/d/e'])
2137
2159
 
2179
2201
             [(b'a', b'', 0, False, b''),
2180
2202
              (b'a', b'', 0, False, b'')]))
2181
2203
        e = self.assertRaises(AssertionError,
2182
 
            state._validate)
 
2204
                              state._validate)
2183
2205
        self.assertContainsRe(str(e), 'not sorted')
2184
2206
 
2185
2207
    def test_dirblock_name_mismatch(self):
2192
2214
             [(b'a', b'', 0, False, b''),
2193
2215
              (b'a', b'', 0, False, b'')]))
2194
2216
        e = self.assertRaises(AssertionError,
2195
 
            state._validate)
 
2217
                              state._validate)
2196
2218
        self.assertContainsRe(str(e),
2197
 
            "doesn't match directory name")
 
2219
                              "doesn't match directory name")
2198
2220
 
2199
2221
    def test_dirblock_missing_rename(self):
2200
2222
        tree, state, expected = self.create_renamed_dirstate()
2207
2229
             [(b'a', b'', 0, False, b''),
2208
2230
              (b'a', b'', 0, False, b'')]))
2209
2231
        e = self.assertRaises(AssertionError,
2210
 
            state._validate)
 
2232
                              state._validate)
2211
2233
        self.assertContainsRe(str(e),
2212
 
            'file a-id is absent in row')
 
2234
                              'file a-id is absent in row')
2213
2235
 
2214
2236
 
2215
2237
class TestDirstateTreeReference(TestCaseWithDirState):
2217
2239
    def test_reference_revision_is_none(self):
2218
2240
        tree = self.make_branch_and_tree('tree', format='development-subtree')
2219
2241
        subtree = self.make_branch_and_tree('tree/subtree',
2220
 
                            format='development-subtree')
 
2242
                                            format='development-subtree')
2221
2243
        subtree.set_root_id(b'subtree')
2222
2244
        tree.add_reference(subtree)
2223
2245
        tree.add('subtree')
2224
2246
        state = dirstate.DirState.from_tree(tree, 'dirstate')
2225
2247
        key = (b'', b'subtree', b'subtree')
2226
2248
        expected = (b'', [(key,
2227
 
            [(b't', b'', 0, False, b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])])
 
2249
                           [(b't', b'', 0, False, b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])])
2228
2250
 
2229
2251
        try:
2230
2252
            self.assertEqual(expected, state._find_block(key))
2299
2321
        file_in_merged_key = (b'', b'file-in-merged', b'b-file-id')
2300
2322
        dirblocks = [(b'', [(root_key, [present_dir, present_dir, present_dir])]),
2301
2323
                     (b'', [(file_in_merged_key,
2302
 
                            [absent, absent, present_file]),
2303
 
                           (file_in_root_key,
2304
 
                            [present_file, present_file, present_file]),
2305
 
                          ]),
2306
 
                    ]
 
2324
                             [absent, absent, present_file]),
 
2325
                            (file_in_root_key,
 
2326
                             [present_file, present_file, present_file]),
 
2327
                            ]),
 
2328
                     ]
2307
2329
 
2308
2330
        state = self.create_empty_dirstate()
2309
2331
        self.addCleanup(state.unlock)
2312
2334
 
2313
2335
        exp_dirblocks = [(b'', [(root_key, [present_dir, present_dir])]),
2314
2336
                         (b'', [(file_in_root_key,
2315
 
                                [present_file, present_file]),
2316
 
                              ]),
2317
 
                        ]
 
2337
                                 [present_file, present_file]),
 
2338
                                ]),
 
2339
                         ]
2318
2340
        state._discard_merge_parents()
2319
2341
        state._validate()
2320
2342
        self.assertEqual(exp_dirblocks, state._dirblocks)
2336
2358
        dirblocks = [
2337
2359
            (b'', [(root_key, [present_dir, present_dir, present_dir])]),
2338
2360
            (b'', [(key_in_1,
2339
 
                   [absent, present_file, (b'r', b'file-in-2', b'c-file-id')]),
2340
 
                  (key_in_2,
2341
 
                   [absent, (b'r', b'file-in-1', b'c-file-id'), present_file]),
2342
 
                  (file_in_root_key,
2343
 
                   [present_file, present_file, present_file]),
2344
 
                  (file_rename_s_key,
2345
 
                   [(b'r', b'file-t', b'b-file-id'), absent, present_file]),
2346
 
                  (file_rename_t_key,
2347
 
                   [present_file, absent, (b'r', b'file-s', b'b-file-id')]),
2348
 
                 ]),
 
2361
                    [absent, present_file, (b'r', b'file-in-2', b'c-file-id')]),
 
2362
                   (key_in_2,
 
2363
                    [absent, (b'r', b'file-in-1', b'c-file-id'), present_file]),
 
2364
                   (file_in_root_key,
 
2365
                    [present_file, present_file, present_file]),
 
2366
                   (file_rename_s_key,
 
2367
                    [(b'r', b'file-t', b'b-file-id'), absent, present_file]),
 
2368
                   (file_rename_t_key,
 
2369
                    [present_file, absent, (b'r', b'file-s', b'b-file-id')]),
 
2370
                   ]),
2349
2371
        ]
2350
2372
        exp_dirblocks = [
2351
2373
            (b'', [(root_key, [present_dir, present_dir])]),
2352
2374
            (b'', [(key_in_1, [absent, present_file]),
2353
 
                  (file_in_root_key, [present_file, present_file]),
2354
 
                  (file_rename_t_key, [present_file, absent]),
2355
 
                 ]),
 
2375
                   (file_in_root_key, [present_file, present_file]),
 
2376
                   (file_rename_t_key, [present_file, absent]),
 
2377
                   ]),
2356
2378
        ]
2357
2379
        state = self.create_empty_dirstate()
2358
2380
        self.addCleanup(state.unlock)
2378
2400
            (b'', [(root_key, [present_dir, present_dir, present_dir])]),
2379
2401
            (b'', [(subdir_key, [present_dir, present_dir, present_dir])]),
2380
2402
            (b'sub', [(child1_key, [absent, absent, present_file]),
2381
 
                     (child2_key, [absent, absent, present_file]),
2382
 
                     (child3_key, [absent, absent, present_file]),
2383
 
                    ]),
 
2403
                      (child2_key, [absent, absent, present_file]),
 
2404
                      (child3_key, [absent, absent, present_file]),
 
2405
                      ]),
2384
2406
        ]
2385
2407
        exp_dirblocks = [
2386
2408
            (b'', [(root_key, [present_dir, present_dir])]),
2518
2540
                # Don't have to actually do anything for this, because only
2519
2541
                # new_path creates InventoryEntries
2520
2542
                old_path = old_path[:-1]
2521
 
            if new_path is None: # Delete
 
2543
            if new_path is None:  # Delete
2522
2544
                inv_delta.append((old_path, None, file_id, None))
2523
2545
                continue
2524
2546
            ie = self.path_to_ie(new_path, file_id, rev_id, dir_ids)
2538
2560
        target_tree = self.create_tree_from_shape(b'target', target)
2539
2561
        state = self.create_empty_dirstate()
2540
2562
        state.set_state_from_scratch(active_tree.root_inventory,
2541
 
            [(b'basis', basis_tree)], [])
 
2563
                                     [(b'basis', basis_tree)], [])
2542
2564
        delta = target_tree.root_inventory._make_delta(
2543
2565
            basis_tree.root_inventory)
2544
2566
        state.update_basis_by_delta(delta, b'target')
2545
2567
        state._validate()
2546
2568
        dirstate_tree = workingtree_4.DirStateRevisionTree(state,
2547
 
            b'target', _Repo())
 
2569
                                                           b'target', _Repo())
2548
2570
        # The target now that delta has been applied should match the
2549
2571
        # RevisionTree
2550
2572
        self.assertEqual([], list(dirstate_tree.iter_changes(target_tree)))
2552
2574
        # it from scratch.
2553
2575
        state2 = self.create_empty_dirstate()
2554
2576
        state2.set_state_from_scratch(active_tree.root_inventory,
2555
 
            [(b'target', target_tree)], [])
 
2577
                                      [(b'target', target_tree)], [])
2556
2578
        self.assertEqual(state2._dirblocks, state._dirblocks)
2557
2579
        return state
2558
2580
 
2573
2595
        inv_delta = self.create_inv_delta(delta, b'target')
2574
2596
        state = self.create_empty_dirstate()
2575
2597
        state.set_state_from_scratch(active_tree.root_inventory,
2576
 
            [(b'basis', basis_tree)], [])
 
2598
                                     [(b'basis', basis_tree)], [])
2577
2599
        self.assertRaises(errors.InconsistentDelta,
2578
 
            state.update_basis_by_delta, inv_delta, b'target')
2579
 
        ## try:
 
2600
                          state.update_basis_by_delta, inv_delta, b'target')
 
2601
        # try:
2580
2602
        ##     state.update_basis_by_delta(inv_delta, b'target')
2581
 
        ## except errors.InconsistentDelta, e:
 
2603
        # except errors.InconsistentDelta, e:
2582
2604
        ##     import pdb; pdb.set_trace()
2583
 
        ## else:
 
2605
        # else:
2584
2606
        ##     import pdb; pdb.set_trace()
2585
2607
        self.assertTrue(state._changes_aborted)
2586
2608
 
2587
2609
    def test_remove_file_matching_active_state(self):
2588
2610
        state = self.assertUpdate(
2589
2611
            active=[],
2590
 
            basis =[('file', b'file-id')],
 
2612
            basis=[('file', b'file-id')],
2591
2613
            target=[],
2592
2614
            )
2593
2615
 
2594
2616
    def test_remove_file_present_in_active_state(self):
2595
2617
        state = self.assertUpdate(
2596
2618
            active=[('file', b'file-id')],
2597
 
            basis =[('file', b'file-id')],
 
2619
            basis=[('file', b'file-id')],
2598
2620
            target=[],
2599
2621
            )
2600
2622
 
2601
2623
    def test_remove_file_present_elsewhere_in_active_state(self):
2602
2624
        state = self.assertUpdate(
2603
2625
            active=[('other-file', b'file-id')],
2604
 
            basis =[('file', b'file-id')],
 
2626
            basis=[('file', b'file-id')],
2605
2627
            target=[],
2606
2628
            )
2607
2629
 
2608
2630
    def test_remove_file_active_state_has_diff_file(self):
2609
2631
        state = self.assertUpdate(
2610
2632
            active=[('file', b'file-id-2')],
2611
 
            basis =[('file', b'file-id')],
 
2633
            basis=[('file', b'file-id')],
2612
2634
            target=[],
2613
2635
            )
2614
2636
 
2616
2638
        state = self.assertUpdate(
2617
2639
            active=[('file', b'file-id-2'),
2618
2640
                    ('other-file', b'file-id')],
2619
 
            basis =[('file', b'file-id')],
 
2641
            basis=[('file', b'file-id')],
2620
2642
            target=[],
2621
2643
            )
2622
2644
 
2623
2645
    def test_add_file_matching_active_state(self):
2624
2646
        state = self.assertUpdate(
2625
2647
            active=[('file', b'file-id')],
2626
 
            basis =[],
 
2648
            basis=[],
2627
2649
            target=[('file', b'file-id')],
2628
2650
            )
2629
2651
 
2630
2652
    def test_add_file_in_empty_dir_not_matching_active_state(self):
2631
2653
        state = self.assertUpdate(
2632
 
                active=[],
2633
 
                basis=[('dir/', b'dir-id')],
2634
 
                target=[('dir/', b'dir-id', b'basis'), ('dir/file', b'file-id')],
2635
 
                )
 
2654
            active=[],
 
2655
            basis=[('dir/', b'dir-id')],
 
2656
            target=[('dir/', b'dir-id', b'basis'), ('dir/file', b'file-id')],
 
2657
            )
2636
2658
 
2637
2659
    def test_add_file_missing_in_active_state(self):
2638
2660
        state = self.assertUpdate(
2639
2661
            active=[],
2640
 
            basis =[],
 
2662
            basis=[],
2641
2663
            target=[('file', b'file-id')],
2642
2664
            )
2643
2665
 
2644
2666
    def test_add_file_elsewhere_in_active_state(self):
2645
2667
        state = self.assertUpdate(
2646
2668
            active=[('other-file', b'file-id')],
2647
 
            basis =[],
 
2669
            basis=[],
2648
2670
            target=[('file', b'file-id')],
2649
2671
            )
2650
2672
 
2652
2674
        state = self.assertUpdate(
2653
2675
            active=[('other-file', b'file-id'),
2654
2676
                    ('file', b'file-id-2')],
2655
 
            basis =[],
 
2677
            basis=[],
2656
2678
            target=[('file', b'file-id')],
2657
2679
            )
2658
2680
 
2659
2681
    def test_rename_file_matching_active_state(self):
2660
2682
        state = self.assertUpdate(
2661
2683
            active=[('other-file', b'file-id')],
2662
 
            basis =[('file', b'file-id')],
 
2684
            basis=[('file', b'file-id')],
2663
2685
            target=[('other-file', b'file-id')],
2664
2686
            )
2665
2687
 
2666
2688
    def test_rename_file_missing_in_active_state(self):
2667
2689
        state = self.assertUpdate(
2668
2690
            active=[],
2669
 
            basis =[('file', b'file-id')],
 
2691
            basis=[('file', b'file-id')],
2670
2692
            target=[('other-file', b'file-id')],
2671
2693
            )
2672
2694
 
2673
2695
    def test_rename_file_present_elsewhere_in_active_state(self):
2674
2696
        state = self.assertUpdate(
2675
2697
            active=[('third', b'file-id')],
2676
 
            basis =[('file', b'file-id')],
 
2698
            basis=[('file', b'file-id')],
2677
2699
            target=[('other-file', b'file-id')],
2678
2700
            )
2679
2701
 
2680
2702
    def test_rename_file_active_state_has_diff_source_file(self):
2681
2703
        state = self.assertUpdate(
2682
2704
            active=[('file', b'file-id-2')],
2683
 
            basis =[('file', b'file-id')],
 
2705
            basis=[('file', b'file-id')],
2684
2706
            target=[('other-file', b'file-id')],
2685
2707
            )
2686
2708
 
2687
2709
    def test_rename_file_active_state_has_diff_target_file(self):
2688
2710
        state = self.assertUpdate(
2689
2711
            active=[('other-file', b'file-id-2')],
2690
 
            basis =[('file', b'file-id')],
 
2712
            basis=[('file', b'file-id')],
2691
2713
            target=[('other-file', b'file-id')],
2692
2714
            )
2693
2715
 
2695
2717
        state = self.assertUpdate(
2696
2718
            active=[('file', b'file-id'),
2697
2719
                    ('other-file', b'file-id-2')],
2698
 
            basis= [('file', b'file-id'),
2699
 
                    ('other-file', b'file-id-2')],
 
2720
            basis=[('file', b'file-id'),
 
2721
                   ('other-file', b'file-id-2')],
2700
2722
            target=[('file', b'file-id-2'),
2701
2723
                    ('other-file', b'file-id')])
2702
2724
 
2704
2726
        state = self.assertUpdate(
2705
2727
            active=[('file', b'file-id'),
2706
2728
                    ('other-file', b'file-id-2')],
2707
 
            basis= [('file', b'file-id-2'),
2708
 
                    ('other-file', b'file-id')],
 
2729
            basis=[('file', b'file-id-2'),
 
2730
                   ('other-file', b'file-id')],
2709
2731
            target=[('file', b'file-id'),
2710
2732
                    ('other-file', b'file-id-2')])
2711
2733
 
2712
2734
    def test_rename_directory_with_contents(self):
2713
 
        state = self.assertUpdate( # active matches basis
 
2735
        state = self.assertUpdate(  # active matches basis
2714
2736
            active=[('dir1/', b'dir-id'),
2715
2737
                    ('dir1/file', b'file-id')],
2716
 
            basis= [('dir1/', b'dir-id'),
2717
 
                    ('dir1/file', b'file-id')],
 
2738
            basis=[('dir1/', b'dir-id'),
 
2739
                   ('dir1/file', b'file-id')],
2718
2740
            target=[('dir2/', b'dir-id'),
2719
2741
                    ('dir2/file', b'file-id')])
2720
 
        state = self.assertUpdate( # active matches target
 
2742
        state = self.assertUpdate(  # active matches target
2721
2743
            active=[('dir2/', b'dir-id'),
2722
2744
                    ('dir2/file', b'file-id')],
2723
 
            basis= [('dir1/', b'dir-id'),
2724
 
                    ('dir1/file', b'file-id')],
 
2745
            basis=[('dir1/', b'dir-id'),
 
2746
                   ('dir1/file', b'file-id')],
2725
2747
            target=[('dir2/', b'dir-id'),
2726
2748
                    ('dir2/file', b'file-id')])
2727
 
        state = self.assertUpdate( # active empty
 
2749
        state = self.assertUpdate(  # active empty
2728
2750
            active=[],
2729
 
            basis= [('dir1/', b'dir-id'),
2730
 
                    ('dir1/file', b'file-id')],
 
2751
            basis=[('dir1/', b'dir-id'),
 
2752
                   ('dir1/file', b'file-id')],
2731
2753
            target=[('dir2/', b'dir-id'),
2732
2754
                    ('dir2/file', b'file-id')])
2733
 
        state = self.assertUpdate( # active present at other location
 
2755
        state = self.assertUpdate(  # active present at other location
2734
2756
            active=[('dir3/', b'dir-id'),
2735
2757
                    ('dir3/file', b'file-id')],
2736
 
            basis= [('dir1/', b'dir-id'),
2737
 
                    ('dir1/file', b'file-id')],
 
2758
            basis=[('dir1/', b'dir-id'),
 
2759
                   ('dir1/file', b'file-id')],
2738
2760
            target=[('dir2/', b'dir-id'),
2739
2761
                    ('dir2/file', b'file-id')])
2740
 
        state = self.assertUpdate( # active has different ids
 
2762
        state = self.assertUpdate(  # active has different ids
2741
2763
            active=[('dir1/', b'dir1-id'),
2742
2764
                    ('dir1/file', b'file1-id'),
2743
2765
                    ('dir2/', b'dir2-id'),
2744
2766
                    ('dir2/file', b'file2-id')],
2745
 
            basis= [('dir1/', b'dir-id'),
2746
 
                    ('dir1/file', b'file-id')],
 
2767
            basis=[('dir1/', b'dir-id'),
 
2768
                   ('dir1/file', b'file-id')],
2747
2769
            target=[('dir2/', b'dir-id'),
2748
2770
                    ('dir2/file', b'file-id')])
2749
2771
 
2750
2772
    def test_invalid_file_not_present(self):
2751
2773
        state = self.assertBadDelta(
2752
2774
            active=[('file', b'file-id')],
2753
 
            basis= [('file', b'file-id')],
 
2775
            basis=[('file', b'file-id')],
2754
2776
            delta=[('other-file', 'file', b'file-id')])
2755
2777
 
2756
2778
    def test_invalid_new_id_same_path(self):
2757
2779
        # The bad entry comes after
2758
2780
        state = self.assertBadDelta(
2759
2781
            active=[('file', b'file-id')],
2760
 
            basis= [('file', b'file-id')],
 
2782
            basis=[('file', b'file-id')],
2761
2783
            delta=[(None, 'file', b'file-id-2')])
2762
2784
        # The bad entry comes first
2763
2785
        state = self.assertBadDelta(
2768
2790
    def test_invalid_existing_id(self):
2769
2791
        state = self.assertBadDelta(
2770
2792
            active=[('file', b'file-id')],
2771
 
            basis= [('file', b'file-id')],
 
2793
            basis=[('file', b'file-id')],
2772
2794
            delta=[(None, 'file', b'file-id')])
2773
2795
 
2774
2796
    def test_invalid_parent_missing(self):
2775
2797
        state = self.assertBadDelta(
2776
2798
            active=[],
2777
 
            basis= [],
 
2799
            basis=[],
2778
2800
            delta=[(None, 'path/path2', b'file-id')])
2779
2801
        # Note: we force the active tree to have the directory, by knowing how
2780
2802
        #       path_to_ie handles entries with missing parents
2781
2803
        state = self.assertBadDelta(
2782
2804
            active=[('path/', b'path-id')],
2783
 
            basis= [],
 
2805
            basis=[],
2784
2806
            delta=[(None, 'path/path2', b'file-id')])
2785
2807
        state = self.assertBadDelta(
2786
2808
            active=[('path/', b'path-id'),
2787
2809
                    ('path/path2', b'file-id')],
2788
 
            basis= [],
 
2810
            basis=[],
2789
2811
            delta=[(None, 'path/path2', b'file-id')])
2790
2812
 
2791
2813
    def test_renamed_dir_same_path(self):
2792
2814
        # We replace the parent directory, with another parent dir. But the C
2793
2815
        # file doesn't look like it has been moved.
2794
 
        state = self.assertUpdate(# Same as basis
 
2816
        state = self.assertUpdate(  # Same as basis
2795
2817
            active=[('dir/', b'A-id'),
2796
2818
                    ('dir/B', b'B-id')],
2797
 
            basis= [('dir/', b'A-id'),
2798
 
                    ('dir/B', b'B-id')],
 
2819
            basis=[('dir/', b'A-id'),
 
2820
                   ('dir/B', b'B-id')],
2799
2821
            target=[('dir/', b'C-id'),
2800
2822
                    ('dir/B', b'B-id')])
2801
 
        state = self.assertUpdate(# Same as target
 
2823
        state = self.assertUpdate(  # Same as target
2802
2824
            active=[('dir/', b'C-id'),
2803
2825
                    ('dir/B', b'B-id')],
2804
 
            basis= [('dir/', b'A-id'),
2805
 
                    ('dir/B', b'B-id')],
 
2826
            basis=[('dir/', b'A-id'),
 
2827
                   ('dir/B', b'B-id')],
2806
2828
            target=[('dir/', b'C-id'),
2807
2829
                    ('dir/B', b'B-id')])
2808
 
        state = self.assertUpdate(# empty active
 
2830
        state = self.assertUpdate(  # empty active
2809
2831
            active=[],
2810
 
            basis= [('dir/', b'A-id'),
2811
 
                    ('dir/B', b'B-id')],
 
2832
            basis=[('dir/', b'A-id'),
 
2833
                   ('dir/B', b'B-id')],
2812
2834
            target=[('dir/', b'C-id'),
2813
2835
                    ('dir/B', b'B-id')])
2814
 
        state = self.assertUpdate(# different active
 
2836
        state = self.assertUpdate(  # different active
2815
2837
            active=[('dir/', b'D-id'),
2816
2838
                    ('dir/B', b'B-id')],
2817
 
            basis= [('dir/', b'A-id'),
2818
 
                    ('dir/B', b'B-id')],
 
2839
            basis=[('dir/', b'A-id'),
 
2840
                   ('dir/B', b'B-id')],
2819
2841
            target=[('dir/', b'C-id'),
2820
2842
                    ('dir/B', b'B-id')])
2821
2843
 
2822
2844
    def test_parent_child_swap(self):
2823
 
        state = self.assertUpdate(# Same as basis
 
2845
        state = self.assertUpdate(  # Same as basis
2824
2846
            active=[('A/', b'A-id'),
2825
2847
                    ('A/B/', b'B-id'),
2826
2848
                    ('A/B/C', b'C-id')],
2827
 
            basis= [('A/', b'A-id'),
2828
 
                    ('A/B/', b'B-id'),
2829
 
                    ('A/B/C', b'C-id')],
 
2849
            basis=[('A/', b'A-id'),
 
2850
                   ('A/B/', b'B-id'),
 
2851
                   ('A/B/C', b'C-id')],
2830
2852
            target=[('A/', b'B-id'),
2831
2853
                    ('A/B/', b'A-id'),
2832
2854
                    ('A/B/C', b'C-id')])
2833
 
        state = self.assertUpdate(# Same as target
 
2855
        state = self.assertUpdate(  # Same as target
2834
2856
            active=[('A/', b'B-id'),
2835
2857
                    ('A/B/', b'A-id'),
2836
2858
                    ('A/B/C', b'C-id')],
2837
 
            basis= [('A/', b'A-id'),
2838
 
                    ('A/B/', b'B-id'),
2839
 
                    ('A/B/C', b'C-id')],
 
2859
            basis=[('A/', b'A-id'),
 
2860
                   ('A/B/', b'B-id'),
 
2861
                   ('A/B/C', b'C-id')],
2840
2862
            target=[('A/', b'B-id'),
2841
2863
                    ('A/B/', b'A-id'),
2842
2864
                    ('A/B/C', b'C-id')])
2843
 
        state = self.assertUpdate(# empty active
 
2865
        state = self.assertUpdate(  # empty active
2844
2866
            active=[],
2845
 
            basis= [('A/', b'A-id'),
2846
 
                    ('A/B/', b'B-id'),
2847
 
                    ('A/B/C', b'C-id')],
 
2867
            basis=[('A/', b'A-id'),
 
2868
                   ('A/B/', b'B-id'),
 
2869
                   ('A/B/C', b'C-id')],
2848
2870
            target=[('A/', b'B-id'),
2849
2871
                    ('A/B/', b'A-id'),
2850
2872
                    ('A/B/C', b'C-id')])
2851
 
        state = self.assertUpdate(# different active
 
2873
        state = self.assertUpdate(  # different active
2852
2874
            active=[('D/', b'A-id'),
2853
2875
                    ('D/E/', b'B-id'),
2854
2876
                    ('F', b'C-id')],
2855
 
            basis= [('A/', b'A-id'),
2856
 
                    ('A/B/', b'B-id'),
2857
 
                    ('A/B/C', b'C-id')],
 
2877
            basis=[('A/', b'A-id'),
 
2878
                   ('A/B/', b'B-id'),
 
2879
                   ('A/B/C', b'C-id')],
2858
2880
            target=[('A/', b'B-id'),
2859
2881
                    ('A/B/', b'A-id'),
2860
2882
                    ('A/B/C', b'C-id')])
2861
2883
 
2862
2884
    def test_change_root_id(self):
2863
 
        state = self.assertUpdate( # same as basis
 
2885
        state = self.assertUpdate(  # same as basis
2864
2886
            active=[('', b'root-id'),
2865
2887
                    ('file', b'file-id')],
2866
 
            basis= [('', b'root-id'),
2867
 
                    ('file', b'file-id')],
 
2888
            basis=[('', b'root-id'),
 
2889
                   ('file', b'file-id')],
2868
2890
            target=[('', b'target-root-id'),
2869
2891
                    ('file', b'file-id')])
2870
 
        state = self.assertUpdate( # same as target
 
2892
        state = self.assertUpdate(  # same as target
2871
2893
            active=[('', b'target-root-id'),
2872
2894
                    ('file', b'file-id')],
2873
 
            basis= [('', b'root-id'),
2874
 
                    ('file', b'file-id')],
 
2895
            basis=[('', b'root-id'),
 
2896
                   ('file', b'file-id')],
2875
2897
            target=[('', b'target-root-id'),
2876
2898
                    ('file', b'root-id')])
2877
 
        state = self.assertUpdate( # all different
 
2899
        state = self.assertUpdate(  # all different
2878
2900
            active=[('', b'active-root-id'),
2879
2901
                    ('file', b'file-id')],
2880
 
            basis= [('', b'root-id'),
2881
 
                    ('file', b'file-id')],
 
2902
            basis=[('', b'root-id'),
 
2903
                   ('file', b'file-id')],
2882
2904
            target=[('', b'target-root-id'),
2883
2905
                    ('file', b'root-id')])
2884
2906
 
2885
2907
    def test_change_file_absent_in_active(self):
2886
2908
        state = self.assertUpdate(
2887
2909
            active=[],
2888
 
            basis= [('file', b'file-id')],
 
2910
            basis=[('file', b'file-id')],
2889
2911
            target=[('file', b'file-id')])
2890
2912
 
2891
2913
    def test_invalid_changed_file(self):
2892
 
        state = self.assertBadDelta( # Not present in basis
 
2914
        state = self.assertBadDelta(  # Not present in basis
2893
2915
            active=[('file', b'file-id')],
2894
 
            basis= [],
 
2916
            basis=[],
2895
2917
            delta=[('file', 'file', b'file-id')])
2896
 
        state = self.assertBadDelta( # present at another location in basis
 
2918
        state = self.assertBadDelta(  # present at another location in basis
2897
2919
            active=[('file', b'file-id')],
2898
 
            basis= [('other-file', b'file-id')],
 
2920
            basis=[('other-file', b'file-id')],
2899
2921
            delta=[('file', 'file', b'file-id')])