/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/per_workingtree/test_parents.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    def test_set_one_ghost_parent_rejects(self):
88
88
        t = self.make_branch_and_tree('.')
89
89
        self.assertRaises(errors.GhostRevisionUnusableHere,
90
 
            t.set_parent_trees, [(b'missing-revision-id', None)])
 
90
                          t.set_parent_trees, [(b'missing-revision-id', None)])
91
91
 
92
92
    def test_set_one_ghost_parent_force(self):
93
93
        t = self.make_branch_and_tree('.')
94
94
        if t._format.supports_leftmost_parent_id_as_ghost:
95
95
            t.set_parent_trees([(b'missing-revision-id', None)],
96
 
                allow_leftmost_as_ghost=True)
 
96
                               allow_leftmost_as_ghost=True)
97
97
            self.assertConsistentParents([b'missing-revision-id'], t)
98
98
        else:
99
99
            self.assertRaises(errors.GhostRevisionUnusableHere,
100
 
                t.set_parent_trees, [(b'missing-revision-id', None)])
 
100
                              t.set_parent_trees, [(b'missing-revision-id', None)])
101
101
            self.assertConsistentParents([], t)
102
102
 
103
103
    def test_set_two_parents_one_ghost(self):
108
108
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
109
109
        if t._format.supports_righthand_parent_id_as_ghost:
110
110
            t.set_parent_trees([(revision_in_repo, rev_tree),
111
 
                (b'another-missing', None)])
112
 
            self.assertConsistentParents([revision_in_repo, b'another-missing'], t)
 
111
                                (b'another-missing', None)])
 
112
            self.assertConsistentParents(
 
113
                [revision_in_repo, b'another-missing'], t)
113
114
        else:
114
115
            self.assertRaises(errors.GhostRevisionUnusableHere,
115
 
                t.set_parent_trees, [(revision_in_repo, rev_tree),
116
 
                (b'another-missing', None)])
 
116
                              t.set_parent_trees, [(revision_in_repo, rev_tree),
 
117
                                                   (b'another-missing', None)])
117
118
 
118
119
    def test_set_three_parents(self):
119
120
        t = self.make_branch_and_tree('.')
127
128
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
128
129
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
129
130
        t.set_parent_trees([(first_revision, rev_tree1),
130
 
            (second_revision, rev_tree2),
131
 
            (third_revision, rev_tree3)])
 
131
                            (second_revision, rev_tree2),
 
132
                            (third_revision, rev_tree3)])
132
133
        self.assertConsistentParents(
133
134
            [first_revision, second_revision, third_revision], t)
134
135
 
144
145
    def test_set_one_ghost_parent_ids_rejects(self):
145
146
        t = self.make_branch_and_tree('.')
146
147
        self.assertRaises(errors.GhostRevisionUnusableHere,
147
 
            t.set_parent_ids, [b'missing-revision-id'])
 
148
                          t.set_parent_ids, [b'missing-revision-id'])
148
149
 
149
150
    def test_set_one_ghost_parent_ids_force(self):
150
151
        t = self.make_branch_and_tree('.')
151
152
        if t._format.supports_leftmost_parent_id_as_ghost:
152
153
            t.set_parent_ids([b'missing-revision-id'],
153
 
                allow_leftmost_as_ghost=True)
 
154
                             allow_leftmost_as_ghost=True)
154
155
            self.assertConsistentParents([b'missing-revision-id'], t)
155
156
        else:
156
157
            self.assertRaises(
165
166
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
166
167
        if t._format.supports_righthand_parent_id_as_ghost:
167
168
            t.set_parent_ids([revision_in_repo, b'another-missing'])
168
 
            self.assertConsistentParents([revision_in_repo, b'another-missing'], t)
 
169
            self.assertConsistentParents(
 
170
                [revision_in_repo, b'another-missing'], t)
169
171
        else:
170
172
            self.assertRaises(errors.GhostRevisionUnusableHere,
171
 
                t.set_parent_ids, [revision_in_repo, b'another-missing'])
 
173
                              t.set_parent_ids, [revision_in_repo, b'another-missing'])
172
174
 
173
175
    def test_set_three_parents_ids(self):
174
176
        t = self.make_branch_and_tree('.')
292
294
        """Test adding the first parent id - as a ghost"""
293
295
        tree = self.make_branch_and_tree('.')
294
296
        self.assertRaises(errors.GhostRevisionUnusableHere,
295
 
            tree.add_parent_tree_id, b'first-revision')
 
297
                          tree.add_parent_tree_id, b'first-revision')
296
298
 
297
299
    def test_add_first_parent_id_ghost_force(self):
298
300
        """Test adding the first parent id - as a ghost"""
299
301
        tree = self.make_branch_and_tree('.')
300
302
        try:
301
 
            tree.add_parent_tree_id(b'first-revision', allow_leftmost_as_ghost=True)
 
303
            tree.add_parent_tree_id(
 
304
                b'first-revision', allow_leftmost_as_ghost=True)
302
305
        except errors.GhostRevisionUnusableHere:
303
306
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
304
307
        else:
309
312
        """Test adding the second parent when the first is a ghost."""
310
313
        tree = self.make_branch_and_tree('.')
311
314
        try:
312
 
            tree.add_parent_tree_id(b'first-revision', allow_leftmost_as_ghost=True)
 
315
            tree.add_parent_tree_id(
 
316
                b'first-revision', allow_leftmost_as_ghost=True)
313
317
        except errors.GhostRevisionUnusableHere:
314
318
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
315
319
        else:
334
338
            self.assertConsistentParents([first_revision, b'second'], tree)
335
339
        else:
336
340
            self.assertRaises(errors.GhostRevisionUnusableHere,
337
 
                    tree.add_parent_tree_id, b'second')
 
341
                              tree.add_parent_tree_id, b'second')
338
342
 
339
343
    def test_add_first_parent_tree(self):
340
344
        """Test adding the first parent id"""
342
346
        first_revision = tree.commit('first post')
343
347
        uncommit(tree.branch, tree=tree)
344
348
        tree.add_parent_tree((first_revision,
345
 
            tree.branch.repository.revision_tree(first_revision)))
 
349
                              tree.branch.repository.revision_tree(first_revision)))
346
350
        self.assertConsistentParents([first_revision], tree)
347
351
 
348
352
    def test_add_first_parent_tree_ghost_rejects(self):
349
353
        """Test adding the first parent id - as a ghost"""
350
354
        tree = self.make_branch_and_tree('.')
351
355
        self.assertRaises(errors.GhostRevisionUnusableHere,
352
 
            tree.add_parent_tree, (b'first-revision', None))
 
356
                          tree.add_parent_tree, (b'first-revision', None))
353
357
 
354
358
    def test_add_first_parent_tree_ghost_force(self):
355
359
        """Test adding the first parent id - as a ghost"""
356
360
        tree = self.make_branch_and_tree('.')
357
361
        try:
358
362
            tree.add_parent_tree((b'first-revision', None),
359
 
                allow_leftmost_as_ghost=True)
 
363
                                 allow_leftmost_as_ghost=True)
360
364
        except errors.GhostRevisionUnusableHere:
361
365
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
362
366
        else:
370
374
        uncommit(tree.branch, tree=tree)
371
375
        second_revision = tree.commit('second post')
372
376
        tree.add_parent_tree((first_revision,
373
 
            tree.branch.repository.revision_tree(first_revision)))
 
377
                              tree.branch.repository.revision_tree(first_revision)))
374
378
        self.assertConsistentParents([second_revision, first_revision], tree)
375
379
 
376
380
    def test_add_second_parent_tree_ghost(self):
382
386
            self.assertConsistentParents([first_revision, b'second'], tree)
383
387
        else:
384
388
            self.assertRaises(errors.GhostRevisionUnusableHere,
385
 
                    tree.add_parent_tree, (b'second', None))
 
389
                              tree.add_parent_tree, (b'second', None))
386
390
 
387
391
 
388
392
class UpdateToOneParentViaDeltaTests(TestCaseWithWorkingTree):
395
399
    """
396
400
 
397
401
    def assertDeltaApplicationResultsInExpectedBasis(self, tree, revid, delta,
398
 
        expected_inventory):
 
402
                                                     expected_inventory):
399
403
        with tree.lock_write():
400
404
            tree.update_basis_by_delta(revid, delta)
401
405
        # check the last revision was adjusted to rev_id
419
423
        for file_id in deletes:
420
424
            delta.append((old.id2path(file_id), None, file_id, None))
421
425
        for file_id in adds:
422
 
            delta.append((None, new.id2path(file_id), file_id, new.get_entry(file_id)))
 
426
            delta.append((None, new.id2path(file_id),
 
427
                          file_id, new.get_entry(file_id)))
423
428
        for file_id in common:
424
429
            if old.get_entry(file_id) != new.get_entry(file_id):
425
430
                delta.append((old.id2path(file_id), new.id2path(file_id),
426
 
                    file_id, new.get_entry(file_id)))
 
431
                              file_id, new.get_entry(file_id)))
427
432
        return delta
428
433
 
429
434
    def fake_up_revision(self, tree, revid, shape):
452
457
            if shape.root.revision is None:
453
458
                shape.root.revision = revid
454
459
            builder = tree.branch.get_commit_builder(
455
 
                    parents=[],
456
 
                    timestamp=0,
457
 
                    timezone=None,
458
 
                    committer="Foo Bar <foo@example.com>",
459
 
                    revision_id=revid)
 
460
                parents=[],
 
461
                timestamp=0,
 
462
                timezone=None,
 
463
                committer="Foo Bar <foo@example.com>",
 
464
                revision_id=revid)
460
465
            shape_tree = ShapeTree(shape)
461
466
            base_tree = tree.branch.repository.revision_tree(
462
 
                    _mod_revision.NULL_REVISION)
 
467
                _mod_revision.NULL_REVISION)
463
468
            changes = shape_tree.iter_changes(
464
469
                base_tree)
465
470
            list(builder.record_iter_changes(shape_tree,
466
 
                base_tree.get_revision_id(), changes))
 
471
                                             base_tree.get_revision_id(), changes))
467
472
            builder.finish_inventory()
468
473
            builder.commit("Message")
469
474
 
493
498
            self.add_dir(new_shape, new_revid, b'root-id', None, '')
494
499
 
495
500
    def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
496
 
        new_shape, new_revid, extra_parent=None, set_current_inventory=True):
 
501
                                         new_shape, new_revid, extra_parent=None, set_current_inventory=True):
497
502
        # set the inventory revision ids.
498
503
        basis_shape.revision_id = basis_revid
499
504
        new_shape.revision_id = new_revid
512
517
            # give tree an inventory of new_shape
513
518
            tree._write_inventory(new_shape)
514
519
        self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
515
 
            delta, new_shape)
 
520
                                                          delta, new_shape)
516
521
        # The tree should be internally consistent; while this is a moderately
517
522
        # large hammer, this is a particularly sensitive area of code, so the
518
523
        # extra assurance is well worth it.
528
533
        basis_shape = Inventory(root_id=None)  # empty tree
529
534
        new_shape = Inventory()  # tree with a root
530
535
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
531
 
            b'new_parent')
 
536
                                              b'new_parent')
532
537
 
533
538
    def test_no_parents_full_tree(self):
534
539
        """Test doing a regular initial commit with files and dirs."""
535
 
        basis_shape = Inventory(root_id=None) # empty tree
 
540
        basis_shape = Inventory(root_id=None)  # empty tree
536
541
        revid = b'new-parent'
537
542
        new_shape = Inventory(root_id=None)
538
543
        self.add_dir(new_shape, revid, b'root-id', None, '')
539
 
        self.add_link(new_shape, revid, b'link-id', b'root-id', 'link', 'target')
 
544
        self.add_link(new_shape, revid, b'link-id',
 
545
                      b'root-id', 'link', 'target')
540
546
        self.add_file(new_shape, revid, b'file-id', b'root-id', 'file', b'1' * 32,
541
 
            12)
 
547
                      12)
542
548
        self.add_dir(new_shape, revid, b'dir-id', b'root-id', 'dir')
543
549
        self.add_file(new_shape, revid, b'subfile-id', b'dir-id', 'subfile',
544
 
            b'2' * 32, 24)
 
550
                      b'2' * 32, 24)
545
551
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
546
 
            revid)
 
552
                                              revid)
547
553
 
548
554
    def test_file_content_change(self):
549
555
        old_revid = b'old-parent'
550
556
        basis_shape = Inventory(root_id=None)
551
557
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
552
558
        self.add_file(basis_shape, old_revid, b'file-id', b'root-id', 'file',
553
 
            b'1' * 32, 12)
 
559
                      b'1' * 32, 12)
554
560
        new_revid = b'new-parent'
555
561
        new_shape = Inventory(root_id=None)
556
562
        self.add_new_root(new_shape, old_revid, new_revid)
557
563
        self.add_file(new_shape, new_revid, b'file-id', b'root-id', 'file',
558
 
            b'2' * 32, 24)
 
564
                      b'2' * 32, 24)
559
565
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
560
 
            new_shape, new_revid)
 
566
                                              new_shape, new_revid)
561
567
 
562
568
    def test_link_content_change(self):
563
569
        old_revid = b'old-parent'
564
570
        basis_shape = Inventory(root_id=None)
565
571
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
566
572
        self.add_link(basis_shape, old_revid, b'link-id', b'root-id', 'link',
567
 
            'old-target')
 
573
                      'old-target')
568
574
        new_revid = b'new-parent'
569
575
        new_shape = Inventory(root_id=None)
570
576
        self.add_new_root(new_shape, old_revid, new_revid)
571
577
        self.add_link(new_shape, new_revid, b'link-id', b'root-id', 'link',
572
 
            'new-target')
 
578
                      'new-target')
573
579
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
574
 
            new_shape, new_revid)
 
580
                                              new_shape, new_revid)
575
581
 
576
582
    def test_kind_changes(self):
577
583
        def do_file(inv, revid):
578
584
            self.add_file(inv, revid, b'path-id', b'root-id', 'path', b'1' * 32,
579
 
                12)
 
585
                          12)
580
586
 
581
587
        def do_link(inv, revid):
582
588
            self.add_link(inv, revid, b'path-id', b'root-id', 'path', 'target')
597
603
                self.add_new_root(new_shape, old_revid, new_revid)
598
604
                new_factory(new_shape, new_revid)
599
605
                self.assertTransitionFromBasisToShape(basis_shape, old_revid,
600
 
                    new_shape, new_revid)
 
606
                                                      new_shape, new_revid)
601
607
 
602
608
    def test_content_from_second_parent_is_dropped(self):
603
609
        left_revid = b'left-parent'
604
610
        basis_shape = Inventory(root_id=None)
605
611
        self.add_dir(basis_shape, left_revid, b'root-id', None, '')
606
612
        self.add_link(basis_shape, left_revid, b'link-id', b'root-id', 'link',
607
 
            'left-target')
 
613
                      'left-target')
608
614
        # the right shape has content - file, link, subdir with a child,
609
615
        # that should all be discarded by the call.
610
616
        right_revid = b'right-parent'
611
617
        right_shape = Inventory(root_id=None)
612
618
        self.add_dir(right_shape, left_revid, b'root-id', None, '')
613
619
        self.add_link(right_shape, right_revid, b'link-id', b'root-id', 'link',
614
 
            'some-target')
 
620
                      'some-target')
615
621
        self.add_dir(right_shape, right_revid, b'subdir-id', b'root-id', 'dir')
616
622
        self.add_file(right_shape, right_revid, b'file-id', b'subdir-id', 'file',
617
 
            b'2' * 32, 24)
 
623
                      b'2' * 32, 24)
618
624
        new_revid = b'new-parent'
619
625
        new_shape = Inventory(root_id=None)
620
626
        self.add_new_root(new_shape, left_revid, new_revid)
621
627
        self.add_link(new_shape, new_revid, b'link-id', b'root-id', 'link',
622
 
            'new-target')
 
628
                      'new-target')
623
629
        self.assertTransitionFromBasisToShape(basis_shape, left_revid,
624
 
            new_shape, new_revid, right_revid)
 
630
                                              new_shape, new_revid, right_revid)
625
631
 
626
632
    def test_parent_id_changed(self):
627
633
        # test that when the only change to an entry is its parent id changing
629
635
        old_revid = b'old-parent'
630
636
        basis_shape = Inventory(root_id=None)
631
637
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
632
 
        self.add_dir(basis_shape, old_revid, b'orig-parent-id', b'root-id', 'dir')
633
 
        self.add_dir(basis_shape, old_revid, b'dir-id', b'orig-parent-id', 'dir')
 
638
        self.add_dir(basis_shape, old_revid,
 
639
                     b'orig-parent-id', b'root-id', 'dir')
 
640
        self.add_dir(basis_shape, old_revid, b'dir-id',
 
641
                     b'orig-parent-id', 'dir')
634
642
        new_revid = b'new-parent'
635
643
        new_shape = Inventory(root_id=None)
636
644
        self.add_new_root(new_shape, old_revid, new_revid)
637
645
        self.add_dir(new_shape, new_revid, b'new-parent-id', b'root-id', 'dir')
638
646
        self.add_dir(new_shape, new_revid, b'dir-id', b'new-parent-id', 'dir')
639
647
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
640
 
            new_shape, new_revid)
 
648
                                              new_shape, new_revid)
641
649
 
642
650
    def test_name_changed(self):
643
651
        # test that when the only change to an entry is its name changing that
645
653
        old_revid = b'old-parent'
646
654
        basis_shape = Inventory(root_id=None)
647
655
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
648
 
        self.add_dir(basis_shape, old_revid, b'parent-id', b'root-id', 'origdir')
 
656
        self.add_dir(basis_shape, old_revid,
 
657
                     b'parent-id', b'root-id', 'origdir')
649
658
        self.add_dir(basis_shape, old_revid, b'dir-id', b'parent-id', 'olddir')
650
659
        new_revid = b'new-parent'
651
660
        new_shape = Inventory(root_id=None)
653
662
        self.add_dir(new_shape, new_revid, b'parent-id', b'root-id', 'newdir')
654
663
        self.add_dir(new_shape, new_revid, b'dir-id', b'parent-id', 'newdir')
655
664
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
656
 
            new_shape, new_revid)
 
665
                                              new_shape, new_revid)
657
666
 
658
667
    def test_parent_child_swap(self):
659
668
        # test a A->A/B and A/B->A path swap.
662
671
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
663
672
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
664
673
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
665
 
        self.add_link(basis_shape, old_revid, b'link-id-C', b'dir-id-B', 'C', 'C')
 
674
        self.add_link(basis_shape, old_revid,
 
675
                      b'link-id-C', b'dir-id-B', 'C', 'C')
666
676
        new_revid = b'new-parent'
667
677
        new_shape = Inventory(root_id=None)
668
678
        self.add_new_root(new_shape, old_revid, new_revid)
669
679
        self.add_dir(new_shape, new_revid, b'dir-id-B', b'root-id', 'A')
670
680
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'dir-id-B', 'B')
671
 
        self.add_link(new_shape, new_revid, b'link-id-C', b'dir-id-A', 'C', 'C')
 
681
        self.add_link(new_shape, new_revid, b'link-id-C',
 
682
                      b'dir-id-A', 'C', 'C')
672
683
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
673
 
            new_shape, new_revid)
 
684
                                              new_shape, new_revid)
674
685
 
675
686
    def test_parent_deleted_child_renamed(self):
676
687
        # test a A->None and A/B->A.
679
690
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
680
691
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
681
692
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
682
 
        self.add_link(basis_shape, old_revid, b'link-id-C', b'dir-id-B', 'C', 'C')
 
693
        self.add_link(basis_shape, old_revid,
 
694
                      b'link-id-C', b'dir-id-B', 'C', 'C')
683
695
        new_revid = b'new-parent'
684
696
        new_shape = Inventory(root_id=None)
685
697
        self.add_new_root(new_shape, old_revid, new_revid)
686
698
        self.add_dir(new_shape, new_revid, b'dir-id-B', b'root-id', 'A')
687
 
        self.add_link(new_shape, old_revid, b'link-id-C', b'dir-id-B', 'C', 'C')
 
699
        self.add_link(new_shape, old_revid, b'link-id-C',
 
700
                      b'dir-id-B', 'C', 'C')
688
701
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
689
 
            new_shape, new_revid)
 
702
                                              new_shape, new_revid)
690
703
 
691
704
    def test_dir_to_root(self):
692
705
        # test a A->''.
694
707
        basis_shape = Inventory(root_id=None)
695
708
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
696
709
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
697
 
        self.add_link(basis_shape, old_revid, b'link-id-B', b'dir-id-A', 'B', 'B')
 
710
        self.add_link(basis_shape, old_revid,
 
711
                      b'link-id-B', b'dir-id-A', 'B', 'B')
698
712
        new_revid = b'new-parent'
699
713
        new_shape = Inventory(root_id=None)
700
714
        self.add_dir(new_shape, new_revid, b'dir-id-A', None, '')
701
 
        self.add_link(new_shape, old_revid, b'link-id-B', b'dir-id-A', 'B', 'B')
 
715
        self.add_link(new_shape, old_revid, b'link-id-B',
 
716
                      b'dir-id-A', 'B', 'B')
702
717
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
703
 
            new_shape, new_revid)
 
718
                                              new_shape, new_revid)
704
719
 
705
720
    def test_path_swap(self):
706
721
        # test a A->B and B->A path swap.
709
724
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
710
725
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
711
726
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'root-id', 'B')
712
 
        self.add_link(basis_shape, old_revid, b'link-id-C', b'root-id', 'C', 'C')
713
 
        self.add_link(basis_shape, old_revid, b'link-id-D', b'root-id', 'D', 'D')
 
727
        self.add_link(basis_shape, old_revid,
 
728
                      b'link-id-C', b'root-id', 'C', 'C')
 
729
        self.add_link(basis_shape, old_revid,
 
730
                      b'link-id-D', b'root-id', 'D', 'D')
714
731
        self.add_file(basis_shape, old_revid, b'file-id-E', b'root-id', 'E',
715
 
            b'1' * 32, 12)
 
732
                      b'1' * 32, 12)
716
733
        self.add_file(basis_shape, old_revid, b'file-id-F', b'root-id', 'F',
717
 
            b'2' * 32, 24)
 
734
                      b'2' * 32, 24)
718
735
        new_revid = b'new-parent'
719
736
        new_shape = Inventory(root_id=None)
720
737
        self.add_new_root(new_shape, old_revid, new_revid)
723
740
        self.add_link(new_shape, new_revid, b'link-id-C', b'root-id', 'D', 'C')
724
741
        self.add_link(new_shape, new_revid, b'link-id-D', b'root-id', 'C', 'D')
725
742
        self.add_file(new_shape, new_revid, b'file-id-E', b'root-id', 'F',
726
 
            b'1' * 32, 12)
 
743
                      b'1' * 32, 12)
727
744
        self.add_file(new_shape, new_revid, b'file-id-F', b'root-id', 'E',
728
 
            b'2' * 32, 24)
 
745
                      b'2' * 32, 24)
729
746
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
730
 
            new_shape, new_revid)
 
747
                                              new_shape, new_revid)
731
748
 
732
749
    def test_adds(self):
733
750
        # test adding paths and dirs, including adding to a newly added dir.
741
758
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'A')
742
759
        self.add_link(new_shape, new_revid, b'link-id-B', b'root-id', 'B', 'C')
743
760
        self.add_file(new_shape, new_revid, b'file-id-C', b'root-id', 'C',
744
 
            b'1' * 32, 12)
 
761
                      b'1' * 32, 12)
745
762
        self.add_file(new_shape, new_revid, b'file-id-D', b'dir-id-A', 'D',
746
 
            b'2' * 32, 24)
 
763
                      b'2' * 32, 24)
747
764
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
748
 
            new_shape, new_revid)
 
765
                                              new_shape, new_revid)
749
766
 
750
767
    def test_removes(self):
751
768
        # test removing paths, including paths that are within other also
754
771
        basis_shape = Inventory(root_id=None)
755
772
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
756
773
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
757
 
        self.add_link(basis_shape, old_revid, b'link-id-B', b'root-id', 'B', 'C')
 
774
        self.add_link(basis_shape, old_revid,
 
775
                      b'link-id-B', b'root-id', 'B', 'C')
758
776
        self.add_file(basis_shape, old_revid, b'file-id-C', b'root-id', 'C',
759
 
            b'1' * 32, 12)
 
777
                      b'1' * 32, 12)
760
778
        self.add_file(basis_shape, old_revid, b'file-id-D', b'dir-id-A', 'D',
761
 
            b'2' * 32, 24)
 
779
                      b'2' * 32, 24)
762
780
        new_revid = b'new-parent'
763
781
        new_shape = Inventory(root_id=None)
764
782
        self.add_new_root(new_shape, old_revid, new_revid)
765
783
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
766
 
            new_shape, new_revid)
 
784
                                              new_shape, new_revid)
767
785
 
768
786
    def test_move_to_added_dir(self):
769
787
        old_revid = b'old-parent'
770
788
        basis_shape = Inventory(root_id=None)
771
789
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
772
 
        self.add_link(basis_shape, old_revid, b'link-id-B', b'root-id', 'B', 'C')
 
790
        self.add_link(basis_shape, old_revid,
 
791
                      b'link-id-B', b'root-id', 'B', 'C')
773
792
        new_revid = b'new-parent'
774
793
        new_shape = Inventory(root_id=None)
775
794
        self.add_new_root(new_shape, old_revid, new_revid)
776
795
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'A')
777
 
        self.add_link(new_shape, new_revid, b'link-id-B', b'dir-id-A', 'B', 'C')
 
796
        self.add_link(new_shape, new_revid, b'link-id-B',
 
797
                      b'dir-id-A', 'B', 'C')
778
798
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
779
 
            new_shape, new_revid)
 
799
                                              new_shape, new_revid)
780
800
 
781
801
    def test_move_from_removed_dir(self):
782
802
        old_revid = b'old-parent'
783
803
        basis_shape = Inventory(root_id=None)
784
804
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
785
805
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
786
 
        self.add_link(basis_shape, old_revid, b'link-id-B', b'dir-id-A', 'B', 'C')
 
806
        self.add_link(basis_shape, old_revid,
 
807
                      b'link-id-B', b'dir-id-A', 'B', 'C')
787
808
        new_revid = b'new-parent'
788
809
        new_shape = Inventory(root_id=None)
789
810
        self.add_new_root(new_shape, old_revid, new_revid)
790
811
        self.add_link(new_shape, new_revid, b'link-id-B', b'root-id', 'B', 'C')
791
812
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
792
 
            new_shape, new_revid)
 
813
                                              new_shape, new_revid)
793
814
 
794
815
    def test_move_moves_children_recursively(self):
795
816
        old_revid = b'old-parent'
797
818
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
798
819
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
799
820
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
800
 
        self.add_link(basis_shape, old_revid, b'link-id-C', b'dir-id-B', 'C', 'D')
 
821
        self.add_link(basis_shape, old_revid,
 
822
                      b'link-id-C', b'dir-id-B', 'C', 'D')
801
823
        new_revid = b'new-parent'
802
824
        new_shape = Inventory(root_id=None)
803
825
        self.add_new_root(new_shape, old_revid, new_revid)
805
827
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'B')
806
828
        # unmoved children.
807
829
        self.add_dir(new_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
808
 
        self.add_link(new_shape, old_revid, b'link-id-C', b'dir-id-B', 'C', 'D')
 
830
        self.add_link(new_shape, old_revid, b'link-id-C',
 
831
                      b'dir-id-B', 'C', 'D')
809
832
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
810
 
            new_shape, new_revid)
 
833
                                              new_shape, new_revid)
811
834
 
812
835
    def test_add_files_to_empty_directory(self):
813
836
        old_revid = b'old-parent'
819
842
        self.add_new_root(new_shape, old_revid, new_revid)
820
843
        self.add_dir(new_shape, old_revid, b'dir-id-A', b'root-id', 'A')
821
844
        self.add_file(new_shape, new_revid, b'file-id-B', b'dir-id-A', 'B',
822
 
            b'1' * 32, 24)
 
845
                      b'1' * 32, 24)
823
846
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
824
 
                new_shape, new_revid, set_current_inventory=False)
 
847
                                              new_shape, new_revid, set_current_inventory=False)