/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 bzrlib/tests/test_repository.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
 
25
25
from stat import S_ISDIR
26
26
 
27
 
import breezy
28
 
from breezy.errors import (
 
27
import bzrlib
 
28
from bzrlib.errors import (
29
29
    UnknownFormatError,
30
30
    UnsupportedFormatError,
31
31
    )
32
 
from breezy import (
 
32
from bzrlib import (
 
33
    btree_index,
 
34
    symbol_versioning,
33
35
    tests,
34
36
    transport,
35
 
    )
36
 
from breezy.bzr import (
37
 
    bzrdir,
38
 
    btree_index,
39
 
    inventory,
40
 
    repository as bzrrepository,
41
 
    versionedfile,
42
 
    vf_repository,
43
37
    vf_search,
44
38
    )
45
 
from breezy.bzr.btree_index import BTreeBuilder, BTreeGraphIndex
46
 
from breezy.bzr.index import GraphIndex
47
 
from breezy.repository import RepositoryFormat
48
 
from breezy.tests import (
 
39
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
 
40
from bzrlib.index import GraphIndex
 
41
from bzrlib.repository import RepositoryFormat
 
42
from bzrlib.tests import (
49
43
    TestCase,
50
44
    TestCaseWithTransport,
51
45
    )
52
 
from breezy import (
 
46
from bzrlib import (
 
47
    bzrdir,
53
48
    controldir,
54
49
    errors,
 
50
    inventory,
55
51
    osutils,
56
52
    repository,
57
53
    revision as _mod_revision,
58
54
    upgrade,
 
55
    versionedfile,
 
56
    vf_repository,
59
57
    workingtree,
60
58
    )
61
 
from breezy.bzr import (
 
59
from bzrlib.repofmt import (
62
60
    groupcompress_repo,
63
61
    knitrepo,
64
62
    knitpack_repo,
95
93
                              old_format.__class__)
96
94
 
97
95
 
98
 
class SampleRepositoryFormat(bzrrepository.RepositoryFormatMetaDir):
 
96
class SampleRepositoryFormat(repository.RepositoryFormatMetaDir):
99
97
    """A sample format
100
98
 
101
99
    this format is initializable, unsupported to aid in testing the
105
103
    @classmethod
106
104
    def get_format_string(cls):
107
105
        """See RepositoryFormat.get_format_string()."""
108
 
        return b"Sample .bzr repository format."
 
106
        return "Sample .bzr repository format."
109
107
 
110
 
    def initialize(self, a_controldir, shared=False):
 
108
    def initialize(self, a_bzrdir, shared=False):
111
109
        """Initialize a repository in a BzrDir"""
112
 
        t = a_controldir.get_repository_transport(self)
 
110
        t = a_bzrdir.get_repository_transport(self)
113
111
        t.put_bytes('format', self.get_format_string())
114
112
        return 'A bzr repository dir'
115
113
 
116
114
    def is_supported(self):
117
115
        return False
118
116
 
119
 
    def open(self, a_controldir, _found=False):
 
117
    def open(self, a_bzrdir, _found=False):
120
118
        return "opened repository."
121
119
 
122
120
 
138
136
        # this is not quite the same as
139
137
        self.build_tree(["foo/", "bar/"])
140
138
        def check_format(format, url):
141
 
            dir = format._matchingcontroldir.initialize(url)
 
139
            dir = format._matchingbzrdir.initialize(url)
142
140
            format.initialize(dir)
143
141
            t = transport.get_transport_from_path(url)
144
 
            found_format = bzrrepository.RepositoryFormatMetaDir.find_format(dir)
 
142
            found_format = repository.RepositoryFormatMetaDir.find_format(dir)
145
143
            self.assertIsInstance(found_format, format.__class__)
146
144
        check_format(repository.format_registry.get_default(), "bar")
147
145
 
148
146
    def test_find_format_no_repository(self):
149
147
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
150
148
        self.assertRaises(errors.NoRepositoryPresent,
151
 
                          bzrrepository.RepositoryFormatMetaDir.find_format,
 
149
                          repository.RepositoryFormatMetaDir.find_format,
152
150
                          dir)
153
151
 
154
152
    def test_from_string(self):
155
153
        self.assertIsInstance(
156
154
            SampleRepositoryFormat.from_string(
157
 
                b"Sample .bzr repository format."),
 
155
                "Sample .bzr repository format."),
158
156
            SampleRepositoryFormat)
159
157
        self.assertRaises(AssertionError,
160
158
            SampleRepositoryFormat.from_string,
161
 
                b"Different .bzr repository format.")
 
159
                "Different .bzr repository format.")
162
160
 
163
161
    def test_find_format_unknown_format(self):
164
162
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
165
163
        SampleRepositoryFormat().initialize(dir)
166
164
        self.assertRaises(UnknownFormatError,
167
 
                          bzrrepository.RepositoryFormatMetaDir.find_format,
 
165
                          repository.RepositoryFormatMetaDir.find_format,
168
166
                          dir)
169
167
 
170
168
    def test_find_format_with_features(self):
171
169
        tree = self.make_branch_and_tree('.', format='2a')
172
 
        tree.branch.repository.update_feature_flags({b"name": b"necessity"})
173
 
        found_format = bzrrepository.RepositoryFormatMetaDir.find_format(tree.controldir)
174
 
        self.assertIsInstance(found_format, bzrrepository.RepositoryFormatMetaDir)
175
 
        self.assertEqual(found_format.features.get(b"name"), b"necessity")
176
 
        self.assertRaises(bzrdir.MissingFeature, found_format.check_support_status,
 
170
        tree.branch.repository.update_feature_flags({"name": "necessity"})
 
171
        found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
 
172
        self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
 
173
        self.assertEquals(found_format.features.get("name"), "necessity")
 
174
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
177
175
            True)
178
 
        self.addCleanup(bzrrepository.RepositoryFormatMetaDir.unregister_feature,
179
 
            b"name")
180
 
        bzrrepository.RepositoryFormatMetaDir.register_feature(b"name")
 
176
        self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
 
177
            "name")
 
178
        repository.RepositoryFormatMetaDir.register_feature("name")
181
179
        found_format.check_support_status(True)
182
180
 
183
181
 
190
188
    def test_register_unregister_format(self):
191
189
        format = SampleRepositoryFormat()
192
190
        self.registry.register(format)
193
 
        self.assertEqual(format, self.registry.get(b"Sample .bzr repository format."))
 
191
        self.assertEquals(format, self.registry.get("Sample .bzr repository format."))
194
192
        self.registry.remove(format)
195
 
        self.assertRaises(KeyError, self.registry.get, b"Sample .bzr repository format.")
 
193
        self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
196
194
 
197
195
    def test_get_all(self):
198
196
        format = SampleRepositoryFormat()
199
 
        self.assertEqual([], self.registry._get_all())
 
197
        self.assertEquals([], self.registry._get_all())
200
198
        self.registry.register(format)
201
 
        self.assertEqual([format], self.registry._get_all())
 
199
        self.assertEquals([format], self.registry._get_all())
202
200
 
203
201
    def test_register_extra(self):
204
202
        format = SampleExtraRepositoryFormat()
205
 
        self.assertEqual([], self.registry._get_all())
 
203
        self.assertEquals([], self.registry._get_all())
206
204
        self.registry.register_extra(format)
207
 
        self.assertEqual([format], self.registry._get_all())
 
205
        self.assertEquals([format], self.registry._get_all())
208
206
 
209
207
    def test_register_extra_lazy(self):
210
 
        self.assertEqual([], self.registry._get_all())
211
 
        self.registry.register_extra_lazy("breezy.tests.test_repository",
 
208
        self.assertEquals([], self.registry._get_all())
 
209
        self.registry.register_extra_lazy("bzrlib.tests.test_repository",
212
210
            "SampleExtraRepositoryFormat")
213
211
        formats = self.registry._get_all()
214
 
        self.assertEqual(1, len(formats))
 
212
        self.assertEquals(1, len(formats))
215
213
        self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
216
214
 
217
215
 
252
250
        branch = control.create_branch()
253
251
        tree = control.create_workingtree()
254
252
        tree.add(['foo'], ['Nasty-IdC:'], ['file'])
255
 
        tree.put_file_bytes_non_atomic('foo', '')
256
 
        tree.commit('1st post', rev_id=b'foo')
 
253
        tree.put_file_bytes_non_atomic('Nasty-IdC:', '')
 
254
        tree.commit('1st post', rev_id='foo')
257
255
        self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a',
258
256
            '\nfoo fulltext 0 81  :')
259
257
 
447
445
 
448
446
    @classmethod
449
447
    def get_format_string(cls):
450
 
        return b"Test Format 1"
 
448
        return "Test Format 1"
451
449
 
452
450
 
453
451
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
454
452
 
455
453
    @classmethod
456
454
    def get_format_string(cls):
457
 
        return b"Test Format 2"
 
455
        return "Test Format 2"
458
456
 
459
457
 
460
458
class TestRepositoryConverter(TestCaseWithTransport):
473
471
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
474
472
        repo = TestRepositoryFormat1().initialize(repo_dir)
475
473
        converter = repository.CopyConverter(target_format)
476
 
        with breezy.ui.ui_factory.nested_progress_bar() as pb:
 
474
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
475
        try:
477
476
            converter.convert(repo, pb)
 
477
        finally:
 
478
            pb.finished()
478
479
        repo = repo_dir.open_repository()
479
480
        self.assertTrue(isinstance(target_format, repo._format.__class__))
480
481
 
505
506
        revision_tree.lock_read()
506
507
        try:
507
508
            self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
508
 
                u'', revision_tree.get_root_id())
 
509
                revision_tree.get_root_id())
509
510
        finally:
510
511
            revision_tree.unlock()
511
512
        format = bzrdir.BzrDirMetaFormat1()
515
516
        revision_tree = tree.branch.repository.revision_tree('dull')
516
517
        revision_tree.lock_read()
517
518
        try:
518
 
            revision_tree.get_file_lines(u'', revision_tree.get_root_id())
 
519
            revision_tree.get_file_lines(revision_tree.get_root_id())
519
520
        finally:
520
521
            revision_tree.unlock()
521
 
        tree.commit("Another dull commit", rev_id=b'dull2')
 
522
        tree.commit("Another dull commit", rev_id='dull2')
522
523
        revision_tree = tree.branch.repository.revision_tree('dull2')
523
524
        revision_tree.lock_read()
524
525
        self.addCleanup(revision_tree.unlock)
525
526
        self.assertEqual('dull',
526
 
                revision_tree.get_file_revision(u'', revision_tree.get_root_id()))
 
527
                revision_tree.get_file_revision(revision_tree.get_root_id()))
527
528
 
528
529
    def test_supports_external_lookups(self):
529
530
        format = bzrdir.BzrDirMetaFormat1()
538
539
        mt = self.make_branch_and_memory_tree('test', format='2a')
539
540
        mt.lock_write()
540
541
        self.addCleanup(mt.unlock)
541
 
        mt.add([''], [b'root-id'])
 
542
        mt.add([''], ['root-id'])
542
543
        mt.commit('first')
543
544
        index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
544
545
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
545
546
        # It should also work if we re-open the repo
546
 
        repo = mt.branch.repository.controldir.open_repository()
 
547
        repo = mt.branch.repository.bzrdir.open_repository()
547
548
        repo.lock_read()
548
549
        self.addCleanup(repo.unlock)
549
550
        index = repo.chk_bytes._index._graph_index._indices[0]
552
553
    def test_fetch_combines_groups(self):
553
554
        builder = self.make_branch_builder('source', format='2a')
554
555
        builder.start_series()
555
 
        builder.build_snapshot(None, [
556
 
            ('add', ('', b'root-id', 'directory', '')),
557
 
            ('add', ('file', b'file-id', 'file', b'content\n'))],
558
 
            revision_id='1')
559
 
        builder.build_snapshot([b'1'], [
560
 
            ('modify', ('file', b'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', b'1',), (b'file-id', b'2',)])
570
 
        file_1_details = details[(b'file-id', b'1')]
571
 
        file_2_details = details[(b'file-id', b'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', ('file', b'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', b'1',), (b'file-id', b'2',)])
594
 
        file_1_details = details[(b'file-id', b'1')]
595
 
        file_2_details = details[(b'file-id', b'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', ('file', b'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', b'1',), (b'file-id', b'2',)])
618
 
        file_1_details = details[(b'file-id', b'1')]
619
 
        file_2_details = details[(b'file-id', b'2')]
 
556
        builder.build_snapshot('1', None, [
 
557
            ('add', ('', 'root-id', 'directory', '')),
 
558
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
559
        builder.build_snapshot('2', ['1'], [
 
560
            ('modify', ('file-id', 'content-2\n'))])
 
561
        builder.finish_series()
 
562
        source = builder.get_branch()
 
563
        target = self.make_repository('target', format='2a')
 
564
        target.fetch(source.repository)
 
565
        target.lock_read()
 
566
        self.addCleanup(target.unlock)
 
567
        details = target.texts._index.get_build_details(
 
568
            [('file-id', '1',), ('file-id', '2',)])
 
569
        file_1_details = details[('file-id', '1')]
 
570
        file_2_details = details[('file-id', '2')]
 
571
        # The index, and what to read off disk, should be the same for both
 
572
        # versions of the file.
 
573
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
574
 
 
575
    def test_fetch_combines_groups(self):
 
576
        builder = self.make_branch_builder('source', format='2a')
 
577
        builder.start_series()
 
578
        builder.build_snapshot('1', None, [
 
579
            ('add', ('', 'root-id', 'directory', '')),
 
580
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
581
        builder.build_snapshot('2', ['1'], [
 
582
            ('modify', ('file-id', 'content-2\n'))])
 
583
        builder.finish_series()
 
584
        source = builder.get_branch()
 
585
        target = self.make_repository('target', format='2a')
 
586
        target.fetch(source.repository)
 
587
        target.lock_read()
 
588
        self.addCleanup(target.unlock)
 
589
        details = target.texts._index.get_build_details(
 
590
            [('file-id', '1',), ('file-id', '2',)])
 
591
        file_1_details = details[('file-id', '1')]
 
592
        file_2_details = details[('file-id', '2')]
 
593
        # The index, and what to read off disk, should be the same for both
 
594
        # versions of the file.
 
595
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
596
 
 
597
    def test_fetch_combines_groups(self):
 
598
        builder = self.make_branch_builder('source', format='2a')
 
599
        builder.start_series()
 
600
        builder.build_snapshot('1', None, [
 
601
            ('add', ('', 'root-id', 'directory', '')),
 
602
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
603
        builder.build_snapshot('2', ['1'], [
 
604
            ('modify', ('file-id', 'content-2\n'))])
 
605
        builder.finish_series()
 
606
        source = builder.get_branch()
 
607
        target = self.make_repository('target', format='2a')
 
608
        target.fetch(source.repository)
 
609
        target.lock_read()
 
610
        self.addCleanup(target.unlock)
 
611
        details = target.texts._index.get_build_details(
 
612
            [('file-id', '1',), ('file-id', '2',)])
 
613
        file_1_details = details[('file-id', '1')]
 
614
        file_2_details = details[('file-id', '2')]
620
615
        # The index, and what to read off disk, should be the same for both
621
616
        # versions of the file.
622
617
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
628
623
    def test_inventories_use_chk_map_with_parent_base_dict(self):
629
624
        tree = self.make_branch_and_memory_tree('repo', format="2a")
630
625
        tree.lock_write()
631
 
        tree.add([''], [b'TREE_ROOT'])
 
626
        tree.add([''], ['TREE_ROOT'])
632
627
        revid = tree.commit("foo")
633
628
        tree.unlock()
634
629
        tree.lock_read()
649
644
        tree = self.make_branch_and_memory_tree('tree', format='2a')
650
645
        tree.lock_write()
651
646
        self.addCleanup(tree.unlock)
652
 
        tree.add([''], [b'TREE_ROOT'])
 
647
        tree.add([''], ['TREE_ROOT'])
653
648
        for pos in range(20):
654
649
            tree.commit(str(pos))
655
650
 
657
652
        tree = self.make_branch_and_memory_tree('tree', format='2a')
658
653
        tree.lock_write()
659
654
        self.addCleanup(tree.unlock)
660
 
        tree.add([''], [b'TREE_ROOT'])
 
655
        tree.add([''], ['TREE_ROOT'])
661
656
        # 1 commit to leave untouched
662
657
        tree.commit('1')
663
658
        to_keep = tree.branch.repository._pack_collection.names()
693
688
                            format='2a')
694
689
        # We have to build a fairly large tree, so that we are sure the chk
695
690
        # pages will have split into multiple pages.
696
 
        entries = [('add', ('', b'a-root-id', 'directory', None))]
 
691
        entries = [('add', ('', 'a-root-id', 'directory', None))]
697
692
        for i in 'abcdefghijklmnopqrstuvwxyz123456789':
698
693
            for j in 'abcdefghijklmnopqrstuvwxyz123456789':
699
694
                fname = i + j
700
 
                fid = fname.encode('utf-8') + b'-id'
 
695
                fid = fname + '-id'
701
696
                content = 'content for %s\n' % (fname,)
702
697
                entries.append(('add', (fname, fid, 'file', content)))
703
698
        source_builder.start_series()
704
 
        source_builder.build_snapshot(None, entries, revision_id=b'rev-1')
 
699
        source_builder.build_snapshot('rev-1', None, entries)
705
700
        # Now change a few of them, so we get a few new pages for the second
706
701
        # revision
707
 
        source_builder.build_snapshot([b'rev-1'], [
708
 
            ('modify', ('aa', b'new content for aa-id\n')),
709
 
            ('modify', ('cc', b'new content for cc-id\n')),
710
 
            ('modify', ('zz', b'new content for zz-id\n')),
711
 
            ], revision_id=b'rev-2')
 
702
        source_builder.build_snapshot('rev-2', ['rev-1'], [
 
703
            ('modify', ('aa-id', 'new content for aa-id\n')),
 
704
            ('modify', ('cc-id', 'new content for cc-id\n')),
 
705
            ('modify', ('zz-id', 'new content for zz-id\n')),
 
706
            ])
712
707
        source_builder.finish_series()
713
708
        source_branch = source_builder.get_branch()
714
709
        source_branch.lock_read()
719
714
 
720
715
        # On a regular pass, getting the inventories and chk pages for rev-2
721
716
        # would only get the newly created chk pages
722
 
        search = vf_search.SearchResult({b'rev-2'}, {b'rev-1'}, 1,
723
 
                                    {b'rev-2'})
 
717
        search = vf_search.SearchResult(set(['rev-2']), set(['rev-1']), 1,
 
718
                                    set(['rev-2']))
724
719
        simple_chk_records = []
725
720
        for vf_name, substream in source.get_stream(search):
726
721
            if vf_name == 'chk_bytes':
832
827
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
833
828
        self.builder = self.make_branch_builder('source')
834
829
        self.builder.start_series()
835
 
        self.builder.build_snapshot(None,
836
 
            [('add', ('', 'tree-root', 'directory', None))],
837
 
            revision_id='initial')
 
830
        self.builder.build_snapshot('initial', None,
 
831
            [('add', ('', 'tree-root', 'directory', None))])
838
832
        self.repo = self.builder.get_branch().repository
839
833
        self.addCleanup(self.builder.finish_series)
840
834
 
843
837
            sorted(self.repo._find_parent_ids_of_revisions(rev_set)))
844
838
 
845
839
    def test_simple(self):
846
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
847
 
        self.builder.build_snapshot(['revid1'], [], revision_id='revid2')
 
840
        self.builder.build_snapshot('revid1', None, [])
 
841
        self.builder.build_snapshot('revid2', ['revid1'], [])
848
842
        rev_set = ['revid2']
849
843
        self.assertParentIds(['revid1'], rev_set)
850
844
 
851
845
    def test_not_first_parent(self):
852
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
853
 
        self.builder.build_snapshot(['revid1'], [], revision_id='revid2')
854
 
        self.builder.build_snapshot(['revid2'], [], revision_id='revid3')
 
846
        self.builder.build_snapshot('revid1', None, [])
 
847
        self.builder.build_snapshot('revid2', ['revid1'], [])
 
848
        self.builder.build_snapshot('revid3', ['revid2'], [])
855
849
        rev_set = ['revid3', 'revid2']
856
850
        self.assertParentIds(['revid1'], rev_set)
857
851
 
860
854
        self.assertParentIds([], rev_set)
861
855
 
862
856
    def test_not_null_set(self):
863
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
 
857
        self.builder.build_snapshot('revid1', None, [])
864
858
        rev_set = [_mod_revision.NULL_REVISION]
865
859
        self.assertParentIds([], rev_set)
866
860
 
867
861
    def test_ghost(self):
868
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
 
862
        self.builder.build_snapshot('revid1', None, [])
869
863
        rev_set = ['ghost', 'revid1']
870
864
        self.assertParentIds(['initial'], rev_set)
871
865
 
872
866
    def test_ghost_parent(self):
873
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
874
 
        self.builder.build_snapshot(['revid1', 'ghost'], [], revision_id='revid2')
 
867
        self.builder.build_snapshot('revid1', None, [])
 
868
        self.builder.build_snapshot('revid2', ['revid1', 'ghost'], [])
875
869
        rev_set = ['revid2', 'revid1']
876
870
        self.assertParentIds(['ghost', 'initial'], rev_set)
877
871
 
878
872
    def test_righthand_parent(self):
879
 
        self.builder.build_snapshot(None, [], revision_id='revid1')
880
 
        self.builder.build_snapshot(['revid1'], [], revision_id='revid2a')
881
 
        self.builder.build_snapshot(['revid1'], [], revision_id='revid2b')
882
 
        self.builder.build_snapshot(['revid2a', 'revid2b'], [],
883
 
                                    revision_id='revid3')
 
873
        self.builder.build_snapshot('revid1', None, [])
 
874
        self.builder.build_snapshot('revid2a', ['revid1'], [])
 
875
        self.builder.build_snapshot('revid2b', ['revid1'], [])
 
876
        self.builder.build_snapshot('revid3', ['revid2a', 'revid2b'], [])
884
877
        rev_set = ['revid3', 'revid2a']
885
878
        self.assertParentIds(['revid1', 'revid2b'], rev_set)
886
879
 
975
968
            return
976
969
        empty_repo.lock_read()
977
970
        self.addCleanup(empty_repo.unlock)
978
 
        text = next(empty_repo.texts.get_record_stream(
979
 
            [('file2-id', 'rev3')], 'topological', True))
 
971
        text = empty_repo.texts.get_record_stream(
 
972
            [('file2-id', 'rev3')], 'topological', True).next()
980
973
        self.assertEqual('line\n', text.get_bytes_as('fulltext'))
981
974
 
982
975
 
983
976
class TestRepositoryPackCollection(TestCaseWithTransport):
984
977
 
985
978
    def get_format(self):
986
 
        return controldir.format_registry.make_controldir('pack-0.92')
 
979
        return controldir.format_registry.make_bzrdir('pack-0.92')
987
980
 
988
981
    def get_packs(self):
989
982
        format = self.get_format()
1028
1021
        obsolete_pack_trans.put_bytes('a-pack.iix', 'content\n')
1029
1022
        obsolete_pack_trans.put_bytes('another-pack.pack', 'foo\n')
1030
1023
        obsolete_pack_trans.put_bytes('not-a-pack.rix', 'foo\n')
1031
 
        res = packs._clear_obsolete_packs(preserve={'a-pack'})
 
1024
        res = packs._clear_obsolete_packs(preserve=set(['a-pack']))
1032
1025
        self.assertEqual(['a-pack', 'another-pack'], sorted(res))
1033
1026
        self.assertEqual(['a-pack.iix', 'a-pack.pack', 'a-pack.rix'],
1034
1027
                         sorted(obsolete_pack_trans.list_dir('.')))
1082
1075
                         sorted(packs._pack_transport.list_dir('.')))
1083
1076
        # names[0] should not be present in the index anymore
1084
1077
        self.assertEqual(names[1:],
1085
 
            sorted({osutils.splitext(n)[0] for n in
1086
 
                        packs._index_transport.list_dir('.')}))
 
1078
            sorted(set([osutils.splitext(n)[0] for n in
 
1079
                        packs._index_transport.list_dir('.')])))
1087
1080
 
1088
1081
    def test__obsolete_packs_missing_directory(self):
1089
1082
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1099
1092
                         sorted(packs._pack_transport.list_dir('.')))
1100
1093
        # names[0] should not be present in the index anymore
1101
1094
        self.assertEqual(names[1:],
1102
 
            sorted({osutils.splitext(n)[0] for n in
1103
 
                        packs._index_transport.list_dir('.')}))
 
1095
            sorted(set([osutils.splitext(n)[0] for n in
 
1096
                        packs._index_transport.list_dir('.')])))
1104
1097
 
1105
1098
    def test_pack_distribution_zero(self):
1106
1099
        packs = self.get_packs()
1282
1275
        # and remove another pack (via _remove_pack_from_memory)
1283
1276
        orig_names = packs.names()
1284
1277
        orig_at_load = packs._packs_at_load
1285
 
        to_remove_name = next(iter(orig_names))
 
1278
        to_remove_name = iter(orig_names).next()
1286
1279
        r.start_write_group()
1287
1280
        self.addCleanup(r.abort_write_group)
1288
1281
        r.texts.insert_record_stream([versionedfile.FulltextContentFactory(
1296
1289
        packs._remove_pack_from_memory(removed_pack)
1297
1290
        names = packs.names()
1298
1291
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1299
 
        new_names = {x[0][0] for x in new_nodes}
 
1292
        new_names = set([x[0][0] for x in new_nodes])
1300
1293
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1301
1294
        self.assertEqual(set(names) - set(orig_names), new_names)
1302
 
        self.assertEqual({new_pack.name}, new_names)
 
1295
        self.assertEqual(set([new_pack.name]), new_names)
1303
1296
        self.assertEqual([to_remove_name],
1304
1297
                         sorted([x[0][0] for x in deleted_nodes]))
1305
1298
        packs.reload_pack_names()
1307
1300
        self.assertEqual(orig_at_load, packs._packs_at_load)
1308
1301
        self.assertEqual(names, reloaded_names)
1309
1302
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1310
 
        new_names = {x[0][0] for x in new_nodes}
 
1303
        new_names = set([x[0][0] for x in new_nodes])
1311
1304
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1312
1305
        self.assertEqual(set(names) - set(orig_names), new_names)
1313
 
        self.assertEqual({new_pack.name}, new_names)
 
1306
        self.assertEqual(set([new_pack.name]), new_names)
1314
1307
        self.assertEqual([to_remove_name],
1315
1308
                         sorted([x[0][0] for x in deleted_nodes]))
1316
1309
 
1356
1349
        self.assertEqual([n + '.pack' for n in names[1:]], sorted(cur_packs))
1357
1350
        # obsolete_packs will also have stuff like .rix and .iix present.
1358
1351
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1359
 
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
 
1352
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1360
1353
        self.assertEqual([pack.name], sorted(obsolete_names))
1361
1354
 
1362
1355
    def test__save_pack_names_already_obsoleted(self):
1374
1367
        # Note that while we set clear_obsolete_packs=True, it should not
1375
1368
        # delete a pack file that we have also scheduled for obsoletion.
1376
1369
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1377
 
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
 
1370
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1378
1371
        self.assertEqual([pack.name], sorted(obsolete_names))
1379
1372
 
1380
1373
    def test_pack_no_obsolete_packs_directory(self):
1472
1465
    def test_pack_optimizes_pack_order(self):
1473
1466
        builder = self.make_branch_builder('.', format="1.9")
1474
1467
        builder.start_series()
1475
 
        builder.build_snapshot(None, [
 
1468
        builder.build_snapshot('A', None, [
1476
1469
            ('add', ('', 'root-id', 'directory', None)),
1477
 
            ('add', ('f', 'f-id', 'file', 'content\n'))],
1478
 
            revision_id='A')
1479
 
        builder.build_snapshot(['A'],
1480
 
            [('modify', ('f', 'new-content\n'))],
1481
 
            revision_id='B')
1482
 
        builder.build_snapshot(['B'],
1483
 
            [('modify', ('f', 'third-content\n'))],
1484
 
            revision_id='C')
1485
 
        builder.build_snapshot(['C'],
1486
 
            [('modify', ('f', 'fourth-content\n'))],
1487
 
            revision_id='D')
 
1470
            ('add', ('f', 'f-id', 'file', 'content\n'))])
 
1471
        builder.build_snapshot('B', ['A'],
 
1472
            [('modify', ('f-id', 'new-content\n'))])
 
1473
        builder.build_snapshot('C', ['B'],
 
1474
            [('modify', ('f-id', 'third-content\n'))])
 
1475
        builder.build_snapshot('D', ['C'],
 
1476
            [('modify', ('f-id', 'fourth-content\n'))])
1488
1477
        b = builder.get_branch()
1489
1478
        b.lock_read()
1490
1479
        builder.finish_series()
1529
1518
    def make_abc_branch(self):
1530
1519
        builder = self.make_branch_builder('source')
1531
1520
        builder.start_series()
1532
 
        builder.build_snapshot(None, [
 
1521
        builder.build_snapshot('A', None, [
1533
1522
            ('add', ('', 'root-id', 'directory', None)),
1534
1523
            ('add', ('file', 'file-id', 'file', 'content\n')),
1535
 
            ], revision_id='A')
1536
 
        builder.build_snapshot(['A'], [
1537
 
            ('add', ('dir', 'dir-id', 'directory', None))],
1538
 
            revision_id='B')
1539
 
        builder.build_snapshot(['B'], [
1540
 
            ('modify', ('file', 'new content\n'))],
1541
 
            revision_id='C')
 
1524
            ])
 
1525
        builder.build_snapshot('B', ['A'], [
 
1526
            ('add', ('dir', 'dir-id', 'directory', None))])
 
1527
        builder.build_snapshot('C', ['B'], [
 
1528
            ('modify', ('file-id', 'new content\n'))])
1542
1529
        builder.finish_series()
1543
1530
        return builder.get_branch()
1544
1531
 
1554
1541
                  pack_name_with_rev_C_content)
1555
1542
        """
1556
1543
        b_source = self.make_abc_branch()
1557
 
        b_base = b_source.controldir.sprout('base', revision_id='A').open_branch()
1558
 
        b_stacked = b_base.controldir.sprout('stacked', stacked=True).open_branch()
 
1544
        b_base = b_source.bzrdir.sprout('base', revision_id='A').open_branch()
 
1545
        b_stacked = b_base.bzrdir.sprout('stacked', stacked=True).open_branch()
1559
1546
        b_stacked.lock_write()
1560
1547
        self.addCleanup(b_stacked.unlock)
1561
1548
        b_stacked.fetch(b_source, 'B')
1562
1549
        # Now re-open the stacked repo directly (no fallbacks) so that we can
1563
1550
        # fill in the A rev.
1564
 
        repo_not_stacked = b_stacked.controldir.open_repository()
 
1551
        repo_not_stacked = b_stacked.bzrdir.open_repository()
1565
1552
        repo_not_stacked.lock_write()
1566
1553
        self.addCleanup(repo_not_stacked.unlock)
1567
1554
        # Now we should have a pack file with A's inventory, but not its
1710
1697
 
1711
1698
    def test__repr__(self):
1712
1699
        lazy = repository._LazyListJoin(['a'], ['b'])
1713
 
        self.assertEqual("breezy.repository._LazyListJoin((['a'], ['b']))",
 
1700
        self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",
1714
1701
                         repr(lazy))
1715
1702
 
1716
1703
 
1718
1705
 
1719
1706
    def test_open_with_present_feature(self):
1720
1707
        self.addCleanup(
1721
 
            bzrrepository.RepositoryFormatMetaDir.unregister_feature,
1722
 
            b"makes-cheese-sandwich")
1723
 
        bzrrepository.RepositoryFormatMetaDir.register_feature(
1724
 
            b"makes-cheese-sandwich")
 
1708
            repository.RepositoryFormatMetaDir.unregister_feature,
 
1709
            "makes-cheese-sandwich")
 
1710
        repository.RepositoryFormatMetaDir.register_feature(
 
1711
            "makes-cheese-sandwich")
1725
1712
        repo = self.make_repository('.')
1726
1713
        repo.lock_write()
1727
 
        repo._format.features[b"makes-cheese-sandwich"] = b"required"
 
1714
        repo._format.features["makes-cheese-sandwich"] = "required"
1728
1715
        repo._format.check_support_status(False)
1729
1716
        repo.unlock()
1730
1717
 
1731
1718
    def test_open_with_missing_required_feature(self):
1732
1719
        repo = self.make_repository('.')
1733
1720
        repo.lock_write()
1734
 
        repo._format.features[b"makes-cheese-sandwich"] = b"required"
1735
 
        self.assertRaises(bzrdir.MissingFeature,
 
1721
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1722
        self.assertRaises(errors.MissingFeature,
1736
1723
            repo._format.check_support_status, False)