/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_repository.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-03-25 11:54:30 UTC
  • mfrom: (6855.4.10 more-bees)
  • Revision ID: breezy.the.bot@gmail.com-20180325115430-75xnlbrmzjoomd83
Add more bees. In particular:

* for file ids
* for revision ids
* for file contents in build_tree_contents()

Merged from https://code.launchpad.net/~jelmer/brz/more-bees/+merge/337919

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
        tree = control.create_workingtree()
254
254
        tree.add(['foo'], ['Nasty-IdC:'], ['file'])
255
255
        tree.put_file_bytes_non_atomic('foo', '')
256
 
        tree.commit('1st post', rev_id='foo')
 
256
        tree.commit('1st post', rev_id=b'foo')
257
257
        self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a',
258
258
            '\nfoo fulltext 0 81  :')
259
259
 
518
518
            revision_tree.get_file_lines(u'', revision_tree.get_root_id())
519
519
        finally:
520
520
            revision_tree.unlock()
521
 
        tree.commit("Another dull commit", rev_id='dull2')
 
521
        tree.commit("Another dull commit", rev_id=b'dull2')
522
522
        revision_tree = tree.branch.repository.revision_tree('dull2')
523
523
        revision_tree.lock_read()
524
524
        self.addCleanup(revision_tree.unlock)
538
538
        mt = self.make_branch_and_memory_tree('test', format='2a')
539
539
        mt.lock_write()
540
540
        self.addCleanup(mt.unlock)
541
 
        mt.add([''], ['root-id'])
 
541
        mt.add([''], [b'root-id'])
542
542
        mt.commit('first')
543
543
        index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
544
544
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
553
553
        builder = self.make_branch_builder('source', format='2a')
554
554
        builder.start_series()
555
555
        builder.build_snapshot(None, [
556
 
            ('add', ('', 'root-id', 'directory', '')),
557
 
            ('add', ('file', 'file-id', 'file', 'content\n'))],
558
 
            revision_id='1')
559
 
        builder.build_snapshot(['1'], [
560
 
            ('modify', ('file-id', 'content-2\n'))],
561
 
            revision_id='2')
562
 
        builder.finish_series()
563
 
        source = builder.get_branch()
564
 
        target = self.make_repository('target', format='2a')
565
 
        target.fetch(source.repository)
566
 
        target.lock_read()
567
 
        self.addCleanup(target.unlock)
568
 
        details = target.texts._index.get_build_details(
569
 
            [('file-id', '1',), ('file-id', '2',)])
570
 
        file_1_details = details[('file-id', '1')]
571
 
        file_2_details = details[('file-id', '2')]
572
 
        # The index, and what to read off disk, should be the same for both
573
 
        # versions of the file.
574
 
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
575
 
 
576
 
    def test_fetch_combines_groups(self):
577
 
        builder = self.make_branch_builder('source', format='2a')
578
 
        builder.start_series()
579
 
        builder.build_snapshot(None, [
580
 
            ('add', ('', 'root-id', 'directory', '')),
581
 
            ('add', ('file', 'file-id', 'file', 'content\n'))],
582
 
            revision_id='1')
583
 
        builder.build_snapshot(['1'], [
584
 
            ('modify', ('file-id', 'content-2\n'))],
585
 
            revision_id='2')
586
 
        builder.finish_series()
587
 
        source = builder.get_branch()
588
 
        target = self.make_repository('target', format='2a')
589
 
        target.fetch(source.repository)
590
 
        target.lock_read()
591
 
        self.addCleanup(target.unlock)
592
 
        details = target.texts._index.get_build_details(
593
 
            [('file-id', '1',), ('file-id', '2',)])
594
 
        file_1_details = details[('file-id', '1')]
595
 
        file_2_details = details[('file-id', '2')]
596
 
        # The index, and what to read off disk, should be the same for both
597
 
        # versions of the file.
598
 
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
599
 
 
600
 
    def test_fetch_combines_groups(self):
601
 
        builder = self.make_branch_builder('source', format='2a')
602
 
        builder.start_series()
603
 
        builder.build_snapshot(None, [
604
 
            ('add', ('', 'root-id', 'directory', '')),
605
 
            ('add', ('file', 'file-id', 'file', 'content\n'))],
606
 
            revision_id='1')
607
 
        builder.build_snapshot(['1'], [
608
 
            ('modify', ('file-id', 'content-2\n'))],
609
 
            revision_id='2')
610
 
        builder.finish_series()
611
 
        source = builder.get_branch()
612
 
        target = self.make_repository('target', format='2a')
613
 
        target.fetch(source.repository)
614
 
        target.lock_read()
615
 
        self.addCleanup(target.unlock)
616
 
        details = target.texts._index.get_build_details(
617
 
            [('file-id', '1',), ('file-id', '2',)])
618
 
        file_1_details = details[('file-id', '1')]
619
 
        file_2_details = details[('file-id', '2')]
 
556
            ('add', ('', b'root-id', 'directory', '')),
 
557
            ('add', ('file', b'file-id', 'file', 'content\n'))],
 
558
            revision_id=b'1')
 
559
        builder.build_snapshot(['1'], [
 
560
            ('modify', (b'file-id', 'content-2\n'))],
 
561
            revision_id=b'2')
 
562
        builder.finish_series()
 
563
        source = builder.get_branch()
 
564
        target = self.make_repository('target', format='2a')
 
565
        target.fetch(source.repository)
 
566
        target.lock_read()
 
567
        self.addCleanup(target.unlock)
 
568
        details = target.texts._index.get_build_details(
 
569
            [(b'file-id', '1',), (b'file-id', '2',)])
 
570
        file_1_details = details[(b'file-id', '1')]
 
571
        file_2_details = details[(b'file-id', '2')]
 
572
        # The index, and what to read off disk, should be the same for both
 
573
        # versions of the file.
 
574
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
575
 
 
576
    def test_fetch_combines_groups(self):
 
577
        builder = self.make_branch_builder('source', format='2a')
 
578
        builder.start_series()
 
579
        builder.build_snapshot(None, [
 
580
            ('add', ('', b'root-id', 'directory', '')),
 
581
            ('add', ('file', b'file-id', 'file', 'content\n'))],
 
582
            revision_id=b'1')
 
583
        builder.build_snapshot([b'1'], [
 
584
            ('modify', (b'file-id', 'content-2\n'))],
 
585
            revision_id=b'2')
 
586
        builder.finish_series()
 
587
        source = builder.get_branch()
 
588
        target = self.make_repository('target', format='2a')
 
589
        target.fetch(source.repository)
 
590
        target.lock_read()
 
591
        self.addCleanup(target.unlock)
 
592
        details = target.texts._index.get_build_details(
 
593
            [(b'file-id', '1',), (b'file-id', '2',)])
 
594
        file_1_details = details[(b'file-id', '1')]
 
595
        file_2_details = details[(b'file-id', '2')]
 
596
        # The index, and what to read off disk, should be the same for both
 
597
        # versions of the file.
 
598
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
599
 
 
600
    def test_fetch_combines_groups(self):
 
601
        builder = self.make_branch_builder('source', format='2a')
 
602
        builder.start_series()
 
603
        builder.build_snapshot(None, [
 
604
            ('add', ('', b'root-id', 'directory', '')),
 
605
            ('add', ('file', b'file-id', 'file', 'content\n'))],
 
606
            revision_id=b'1')
 
607
        builder.build_snapshot([b'1'], [
 
608
            ('modify', (b'file-id', 'content-2\n'))],
 
609
            revision_id=b'2')
 
610
        builder.finish_series()
 
611
        source = builder.get_branch()
 
612
        target = self.make_repository('target', format='2a')
 
613
        target.fetch(source.repository)
 
614
        target.lock_read()
 
615
        self.addCleanup(target.unlock)
 
616
        details = target.texts._index.get_build_details(
 
617
            [(b'file-id', '1',), (b'file-id', '2',)])
 
618
        file_1_details = details[(b'file-id', '1')]
 
619
        file_2_details = details[(b'file-id', '2')]
620
620
        # The index, and what to read off disk, should be the same for both
621
621
        # versions of the file.
622
622
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
628
628
    def test_inventories_use_chk_map_with_parent_base_dict(self):
629
629
        tree = self.make_branch_and_memory_tree('repo', format="2a")
630
630
        tree.lock_write()
631
 
        tree.add([''], ['TREE_ROOT'])
 
631
        tree.add([''], [b'TREE_ROOT'])
632
632
        revid = tree.commit("foo")
633
633
        tree.unlock()
634
634
        tree.lock_read()
649
649
        tree = self.make_branch_and_memory_tree('tree', format='2a')
650
650
        tree.lock_write()
651
651
        self.addCleanup(tree.unlock)
652
 
        tree.add([''], ['TREE_ROOT'])
 
652
        tree.add([''], [b'TREE_ROOT'])
653
653
        for pos in range(20):
654
654
            tree.commit(str(pos))
655
655
 
657
657
        tree = self.make_branch_and_memory_tree('tree', format='2a')
658
658
        tree.lock_write()
659
659
        self.addCleanup(tree.unlock)
660
 
        tree.add([''], ['TREE_ROOT'])
 
660
        tree.add([''], [b'TREE_ROOT'])
661
661
        # 1 commit to leave untouched
662
662
        tree.commit('1')
663
663
        to_keep = tree.branch.repository._pack_collection.names()
693
693
                            format='2a')
694
694
        # We have to build a fairly large tree, so that we are sure the chk
695
695
        # pages will have split into multiple pages.
696
 
        entries = [('add', ('', 'a-root-id', 'directory', None))]
 
696
        entries = [('add', ('', b'a-root-id', 'directory', None))]
697
697
        for i in 'abcdefghijklmnopqrstuvwxyz123456789':
698
698
            for j in 'abcdefghijklmnopqrstuvwxyz123456789':
699
699
                fname = i + j
700
 
                fid = fname + '-id'
 
700
                fid = fname.encode('utf-8') + b'-id'
701
701
                content = 'content for %s\n' % (fname,)
702
702
                entries.append(('add', (fname, fid, 'file', content)))
703
703
        source_builder.start_series()
704
 
        source_builder.build_snapshot(None, entries, revision_id='rev-1')
 
704
        source_builder.build_snapshot(None, entries, revision_id=b'rev-1')
705
705
        # Now change a few of them, so we get a few new pages for the second
706
706
        # revision
707
 
        source_builder.build_snapshot(['rev-1'], [
708
 
            ('modify', ('aa-id', 'new content for aa-id\n')),
709
 
            ('modify', ('cc-id', 'new content for cc-id\n')),
710
 
            ('modify', ('zz-id', 'new content for zz-id\n')),
711
 
            ], revision_id='rev-2')
 
707
        source_builder.build_snapshot([b'rev-1'], [
 
708
            ('modify', (b'aa-id', 'new content for aa-id\n')),
 
709
            ('modify', (b'cc-id', 'new content for cc-id\n')),
 
710
            ('modify', (b'zz-id', 'new content for zz-id\n')),
 
711
            ], revision_id=b'rev-2')
712
712
        source_builder.finish_series()
713
713
        source_branch = source_builder.get_branch()
714
714
        source_branch.lock_read()
719
719
 
720
720
        # On a regular pass, getting the inventories and chk pages for rev-2
721
721
        # would only get the newly created chk pages
722
 
        search = vf_search.SearchResult({'rev-2'}, {'rev-1'}, 1,
723
 
                                    {'rev-2'})
 
722
        search = vf_search.SearchResult({b'rev-2'}, {b'rev-1'}, 1,
 
723
                                    {b'rev-2'})
724
724
        simple_chk_records = []
725
725
        for vf_name, substream in source.get_stream(search):
726
726
            if vf_name == 'chk_bytes':