/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: Jelmer Vernooij
  • Date: 2017-06-01 23:52:12 UTC
  • mfrom: (0.140.55 bzr-stats)
  • mto: This revision was merged to the branch mainline in revision 6646.
  • Revision ID: jelmer@jelmer.uk-20170601235212-twcndojyo32c5wkp
Bundle the stats plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
23
23
"""
24
24
 
25
25
from stat import S_ISDIR
26
 
import sys
27
26
 
28
 
import bzrlib
29
 
from bzrlib.errors import (NoSuchFile,
30
 
                           UnknownFormatError,
31
 
                           UnsupportedFormatError,
32
 
                           )
33
 
from bzrlib import (
34
 
    graph,
 
27
import breezy
 
28
from breezy.errors import (
 
29
    UnknownFormatError,
 
30
    UnsupportedFormatError,
 
31
    )
 
32
from breezy import (
 
33
    btree_index,
35
34
    tests,
 
35
    transport,
 
36
    vf_search,
36
37
    )
37
 
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
38
 
from bzrlib.index import GraphIndex
39
 
from bzrlib.repository import RepositoryFormat
40
 
from bzrlib.tests import (
 
38
from breezy.btree_index import BTreeBuilder, BTreeGraphIndex
 
39
from breezy.index import GraphIndex
 
40
from breezy.repository import RepositoryFormat
 
41
from breezy.tests import (
41
42
    TestCase,
42
43
    TestCaseWithTransport,
43
44
    )
44
 
from bzrlib.transport import (
45
 
    get_transport,
46
 
    )
47
 
from bzrlib import (
 
45
from breezy import (
48
46
    bzrdir,
 
47
    controldir,
49
48
    errors,
50
49
    inventory,
51
50
    osutils,
53
52
    revision as _mod_revision,
54
53
    upgrade,
55
54
    versionedfile,
 
55
    vf_repository,
56
56
    workingtree,
57
57
    )
58
 
from bzrlib.repofmt import (
 
58
from breezy.repofmt import (
59
59
    groupcompress_repo,
60
60
    knitrepo,
 
61
    knitpack_repo,
61
62
    pack_repo,
62
 
    weaverepo,
63
63
    )
64
64
 
65
65
 
66
66
class TestDefaultFormat(TestCase):
67
67
 
68
68
    def test_get_set_default_format(self):
69
 
        old_default = bzrdir.format_registry.get('default')
 
69
        old_default = controldir.format_registry.get('default')
70
70
        private_default = old_default().repository_format.__class__
71
 
        old_format = repository.RepositoryFormat.get_default_format()
 
71
        old_format = repository.format_registry.get_default()
72
72
        self.assertTrue(isinstance(old_format, private_default))
73
73
        def make_sample_bzrdir():
74
74
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
75
75
            my_bzrdir.repository_format = SampleRepositoryFormat()
76
76
            return my_bzrdir
77
 
        bzrdir.format_registry.remove('default')
78
 
        bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
79
 
        bzrdir.format_registry.set_default('sample')
 
77
        controldir.format_registry.remove('default')
 
78
        controldir.format_registry.register('sample', make_sample_bzrdir, '')
 
79
        controldir.format_registry.set_default('sample')
80
80
        # creating a repository should now create an instrumented dir.
81
81
        try:
82
82
            # the default branch format is used by the meta dir format
85
85
            result = dir.create_repository()
86
86
            self.assertEqual(result, 'A bzr repository dir')
87
87
        finally:
88
 
            bzrdir.format_registry.remove('default')
89
 
            bzrdir.format_registry.remove('sample')
90
 
            bzrdir.format_registry.register('default', old_default, '')
91
 
        self.assertIsInstance(repository.RepositoryFormat.get_default_format(),
 
88
            controldir.format_registry.remove('default')
 
89
            controldir.format_registry.remove('sample')
 
90
            controldir.format_registry.register('default', old_default, '')
 
91
        self.assertIsInstance(repository.format_registry.get_default(),
92
92
                              old_format.__class__)
93
93
 
94
94
 
95
 
class SampleRepositoryFormat(repository.RepositoryFormat):
 
95
class SampleRepositoryFormat(repository.RepositoryFormatMetaDir):
96
96
    """A sample format
97
97
 
98
98
    this format is initializable, unsupported to aid in testing the
99
99
    open and open(unsupported=True) routines.
100
100
    """
101
101
 
102
 
    def get_format_string(self):
 
102
    @classmethod
 
103
    def get_format_string(cls):
103
104
        """See RepositoryFormat.get_format_string()."""
104
105
        return "Sample .bzr repository format."
105
106
 
116
117
        return "opened repository."
117
118
 
118
119
 
 
120
class SampleExtraRepositoryFormat(repository.RepositoryFormat):
 
121
    """A sample format that can not be used in a metadir
 
122
 
 
123
    """
 
124
 
 
125
    def get_format_string(self):
 
126
        raise NotImplementedError
 
127
 
 
128
 
119
129
class TestRepositoryFormat(TestCaseWithTransport):
120
130
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
121
131
 
127
137
        def check_format(format, url):
128
138
            dir = format._matchingbzrdir.initialize(url)
129
139
            format.initialize(dir)
130
 
            t = get_transport(url)
131
 
            found_format = repository.RepositoryFormat.find_format(dir)
132
 
            self.failUnless(isinstance(found_format, format.__class__))
133
 
        check_format(weaverepo.RepositoryFormat7(), "bar")
 
140
            t = transport.get_transport_from_path(url)
 
141
            found_format = repository.RepositoryFormatMetaDir.find_format(dir)
 
142
            self.assertIsInstance(found_format, format.__class__)
 
143
        check_format(repository.format_registry.get_default(), "bar")
134
144
 
135
145
    def test_find_format_no_repository(self):
136
146
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
137
147
        self.assertRaises(errors.NoRepositoryPresent,
138
 
                          repository.RepositoryFormat.find_format,
 
148
                          repository.RepositoryFormatMetaDir.find_format,
139
149
                          dir)
140
150
 
 
151
    def test_from_string(self):
 
152
        self.assertIsInstance(
 
153
            SampleRepositoryFormat.from_string(
 
154
                "Sample .bzr repository format."),
 
155
            SampleRepositoryFormat)
 
156
        self.assertRaises(AssertionError,
 
157
            SampleRepositoryFormat.from_string,
 
158
                "Different .bzr repository format.")
 
159
 
141
160
    def test_find_format_unknown_format(self):
142
161
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
143
162
        SampleRepositoryFormat().initialize(dir)
144
163
        self.assertRaises(UnknownFormatError,
145
 
                          repository.RepositoryFormat.find_format,
 
164
                          repository.RepositoryFormatMetaDir.find_format,
146
165
                          dir)
147
166
 
 
167
    def test_find_format_with_features(self):
 
168
        tree = self.make_branch_and_tree('.', format='2a')
 
169
        tree.branch.repository.update_feature_flags({"name": "necessity"})
 
170
        found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
 
171
        self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
 
172
        self.assertEqual(found_format.features.get("name"), "necessity")
 
173
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
 
174
            True)
 
175
        self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
 
176
            "name")
 
177
        repository.RepositoryFormatMetaDir.register_feature("name")
 
178
        found_format.check_support_status(True)
 
179
 
 
180
 
 
181
class TestRepositoryFormatRegistry(TestCase):
 
182
 
 
183
    def setUp(self):
 
184
        super(TestRepositoryFormatRegistry, self).setUp()
 
185
        self.registry = repository.RepositoryFormatRegistry()
 
186
 
148
187
    def test_register_unregister_format(self):
149
188
        format = SampleRepositoryFormat()
150
 
        # make a control dir
151
 
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
 
        # make a repo
153
 
        format.initialize(dir)
154
 
        # register a format for it.
155
 
        repository.RepositoryFormat.register_format(format)
156
 
        # which repository.Open will refuse (not supported)
157
 
        self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
158
 
        # but open(unsupported) will work
159
 
        self.assertEqual(format.open(dir), "opened repository.")
160
 
        # unregister the format
161
 
        repository.RepositoryFormat.unregister_format(format)
162
 
 
163
 
 
164
 
class TestFormat6(TestCaseWithTransport):
165
 
 
166
 
    def test_attribute__fetch_order(self):
167
 
        """Weaves need topological data insertion."""
168
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
169
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
170
 
        self.assertEqual('topological', repo._format._fetch_order)
171
 
 
172
 
    def test_attribute__fetch_uses_deltas(self):
173
 
        """Weaves do not reuse deltas."""
174
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
175
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
176
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
177
 
 
178
 
    def test_attribute__fetch_reconcile(self):
179
 
        """Weave repositories need a reconcile after fetch."""
180
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
181
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
182
 
        self.assertEqual(True, repo._format._fetch_reconcile)
183
 
 
184
 
    def test_no_ancestry_weave(self):
185
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
186
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
187
 
        # We no longer need to create the ancestry.weave file
188
 
        # since it is *never* used.
189
 
        self.assertRaises(NoSuchFile,
190
 
                          control.transport.get,
191
 
                          'ancestry.weave')
192
 
 
193
 
    def test_supports_external_lookups(self):
194
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
195
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
196
 
        self.assertFalse(repo._format.supports_external_lookups)
197
 
 
198
 
 
199
 
class TestFormat7(TestCaseWithTransport):
200
 
 
201
 
    def test_attribute__fetch_order(self):
202
 
        """Weaves need topological data insertion."""
203
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
204
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
205
 
        self.assertEqual('topological', repo._format._fetch_order)
206
 
 
207
 
    def test_attribute__fetch_uses_deltas(self):
208
 
        """Weaves do not reuse deltas."""
209
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
210
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
211
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
212
 
 
213
 
    def test_attribute__fetch_reconcile(self):
214
 
        """Weave repositories need a reconcile after fetch."""
215
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
216
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
217
 
        self.assertEqual(True, repo._format._fetch_reconcile)
218
 
 
219
 
    def test_disk_layout(self):
220
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
221
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
222
 
        # in case of side effects of locking.
223
 
        repo.lock_write()
224
 
        repo.unlock()
225
 
        # we want:
226
 
        # format 'Bazaar-NG Repository format 7'
227
 
        # lock ''
228
 
        # inventory.weave == empty_weave
229
 
        # empty revision-store directory
230
 
        # empty weaves directory
231
 
        t = control.get_repository_transport(None)
232
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
233
 
                             t.get('format').read())
234
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
235
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
236
 
        self.assertEqualDiff('# bzr weave file v5\n'
237
 
                             'w\n'
238
 
                             'W\n',
239
 
                             t.get('inventory.weave').read())
240
 
        # Creating a file with id Foo:Bar results in a non-escaped file name on
241
 
        # disk.
242
 
        control.create_branch()
243
 
        tree = control.create_workingtree()
244
 
        tree.add(['foo'], ['Foo:Bar'], ['file'])
245
 
        tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
246
 
        try:
247
 
            tree.commit('first post', rev_id='first')
248
 
        except errors.IllegalPath:
249
 
            if sys.platform != 'win32':
250
 
                raise
251
 
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
252
 
                              ' in repo format 7')
253
 
            return
254
 
        self.assertEqualDiff(
255
 
            '# bzr weave file v5\n'
256
 
            'i\n'
257
 
            '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
258
 
            'n first\n'
259
 
            '\n'
260
 
            'w\n'
261
 
            '{ 0\n'
262
 
            '. content\n'
263
 
            '}\n'
264
 
            'W\n',
265
 
            t.get('weaves/74/Foo%3ABar.weave').read())
266
 
 
267
 
    def test_shared_disk_layout(self):
268
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
269
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
270
 
        # we want:
271
 
        # format 'Bazaar-NG Repository format 7'
272
 
        # inventory.weave == empty_weave
273
 
        # empty revision-store directory
274
 
        # empty weaves directory
275
 
        # a 'shared-storage' marker file.
276
 
        # lock is not present when unlocked
277
 
        t = control.get_repository_transport(None)
278
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
279
 
                             t.get('format').read())
280
 
        self.assertEqualDiff('', t.get('shared-storage').read())
281
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
282
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
283
 
        self.assertEqualDiff('# bzr weave file v5\n'
284
 
                             'w\n'
285
 
                             'W\n',
286
 
                             t.get('inventory.weave').read())
287
 
        self.assertFalse(t.has('branch-lock'))
288
 
 
289
 
    def test_creates_lockdir(self):
290
 
        """Make sure it appears to be controlled by a LockDir existence"""
291
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
292
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
293
 
        t = control.get_repository_transport(None)
294
 
        # TODO: Should check there is a 'lock' toplevel directory,
295
 
        # regardless of contents
296
 
        self.assertFalse(t.has('lock/held/info'))
297
 
        repo.lock_write()
298
 
        try:
299
 
            self.assertTrue(t.has('lock/held/info'))
300
 
        finally:
301
 
            # unlock so we don't get a warning about failing to do so
302
 
            repo.unlock()
303
 
 
304
 
    def test_uses_lockdir(self):
305
 
        """repo format 7 actually locks on lockdir"""
306
 
        base_url = self.get_url()
307
 
        control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
308
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
309
 
        t = control.get_repository_transport(None)
310
 
        repo.lock_write()
311
 
        repo.unlock()
312
 
        del repo
313
 
        # make sure the same lock is created by opening it
314
 
        repo = repository.Repository.open(base_url)
315
 
        repo.lock_write()
316
 
        self.assertTrue(t.has('lock/held/info'))
317
 
        repo.unlock()
318
 
        self.assertFalse(t.has('lock/held/info'))
319
 
 
320
 
    def test_shared_no_tree_disk_layout(self):
321
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
322
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
323
 
        repo.set_make_working_trees(False)
324
 
        # we want:
325
 
        # format 'Bazaar-NG Repository format 7'
326
 
        # lock ''
327
 
        # inventory.weave == empty_weave
328
 
        # empty revision-store directory
329
 
        # empty weaves directory
330
 
        # a 'shared-storage' marker file.
331
 
        t = control.get_repository_transport(None)
332
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
333
 
                             t.get('format').read())
334
 
        ## self.assertEqualDiff('', t.get('lock').read())
335
 
        self.assertEqualDiff('', t.get('shared-storage').read())
336
 
        self.assertEqualDiff('', t.get('no-working-trees').read())
337
 
        repo.set_make_working_trees(True)
338
 
        self.assertFalse(t.has('no-working-trees'))
339
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
340
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
341
 
        self.assertEqualDiff('# bzr weave file v5\n'
342
 
                             'w\n'
343
 
                             'W\n',
344
 
                             t.get('inventory.weave').read())
345
 
 
346
 
    def test_supports_external_lookups(self):
347
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
348
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
349
 
        self.assertFalse(repo._format.supports_external_lookups)
 
189
        self.registry.register(format)
 
190
        self.assertEqual(format, self.registry.get("Sample .bzr repository format."))
 
191
        self.registry.remove(format)
 
192
        self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
 
193
 
 
194
    def test_get_all(self):
 
195
        format = SampleRepositoryFormat()
 
196
        self.assertEqual([], self.registry._get_all())
 
197
        self.registry.register(format)
 
198
        self.assertEqual([format], self.registry._get_all())
 
199
 
 
200
    def test_register_extra(self):
 
201
        format = SampleExtraRepositoryFormat()
 
202
        self.assertEqual([], self.registry._get_all())
 
203
        self.registry.register_extra(format)
 
204
        self.assertEqual([format], self.registry._get_all())
 
205
 
 
206
    def test_register_extra_lazy(self):
 
207
        self.assertEqual([], self.registry._get_all())
 
208
        self.registry.register_extra_lazy("breezy.tests.test_repository",
 
209
            "SampleExtraRepositoryFormat")
 
210
        formats = self.registry._get_all()
 
211
        self.assertEqual(1, len(formats))
 
212
        self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
350
213
 
351
214
 
352
215
class TestFormatKnit1(TestCaseWithTransport):
354
217
    def test_attribute__fetch_order(self):
355
218
        """Knits need topological data insertion."""
356
219
        repo = self.make_repository('.',
357
 
                format=bzrdir.format_registry.get('knit')())
 
220
                format=controldir.format_registry.get('knit')())
358
221
        self.assertEqual('topological', repo._format._fetch_order)
359
222
 
360
223
    def test_attribute__fetch_uses_deltas(self):
361
224
        """Knits reuse deltas."""
362
225
        repo = self.make_repository('.',
363
 
                format=bzrdir.format_registry.get('knit')())
 
226
                format=controldir.format_registry.get('knit')())
364
227
        self.assertEqual(True, repo._format._fetch_uses_deltas)
365
228
 
366
229
    def test_disk_layout(self):
452
315
        is valid when the api is not being abused.
453
316
        """
454
317
        repo = self.make_repository('.',
455
 
                format=bzrdir.format_registry.get('knit')())
 
318
                format=controldir.format_registry.get('knit')())
456
319
        inv_xml = '<inventory format="5">\n</inventory>\n'
457
320
        inv = repo._deserialise_inventory('test-rev-id', inv_xml)
458
321
        self.assertEqual('test-rev-id', inv.root.revision)
460
323
    def test_deserialise_uses_global_revision_id(self):
461
324
        """If it is set, then we re-use the global revision id"""
462
325
        repo = self.make_repository('.',
463
 
                format=bzrdir.format_registry.get('knit')())
 
326
                format=controldir.format_registry.get('knit')())
464
327
        inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
465
328
                   '</inventory>\n')
466
329
        # Arguably, the deserialise_inventory should detect a mismatch, and
473
336
 
474
337
    def test_supports_external_lookups(self):
475
338
        repo = self.make_repository('.',
476
 
                format=bzrdir.format_registry.get('knit')())
 
339
                format=controldir.format_registry.get('knit')())
477
340
        self.assertFalse(repo._format.supports_external_lookups)
478
341
 
479
342
 
520
383
        # classes do not barf inappropriately when a surprising repository type
521
384
        # is handed to them.
522
385
        dummy_a = DummyRepository()
 
386
        dummy_a._format = RepositoryFormat()
 
387
        dummy_a._format.supports_full_versioned_files = True
523
388
        dummy_b = DummyRepository()
 
389
        dummy_b._format = RepositoryFormat()
 
390
        dummy_b._format.supports_full_versioned_files = True
524
391
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
525
392
 
526
393
    def assertGetsDefaultInterRepository(self, repo_a, repo_b):
530
397
        no actual sane default in the presence of incompatible data models.
531
398
        """
532
399
        inter_repo = repository.InterRepository.get(repo_a, repo_b)
533
 
        self.assertEqual(repository.InterSameDataRepository,
 
400
        self.assertEqual(vf_repository.InterSameDataRepository,
534
401
                         inter_repo.__class__)
535
402
        self.assertEqual(repo_a, inter_repo.source)
536
403
        self.assertEqual(repo_b, inter_repo.target)
550
417
        dummy_a._serializer = repo._serializer
551
418
        dummy_a._format.supports_tree_reference = repo._format.supports_tree_reference
552
419
        dummy_a._format.rich_root_data = repo._format.rich_root_data
 
420
        dummy_a._format.supports_full_versioned_files = repo._format.supports_full_versioned_files
553
421
        dummy_b._serializer = repo._serializer
554
422
        dummy_b._format.supports_tree_reference = repo._format.supports_tree_reference
555
423
        dummy_b._format.rich_root_data = repo._format.rich_root_data
 
424
        dummy_b._format.supports_full_versioned_files = repo._format.supports_full_versioned_files
556
425
        repository.InterRepository.register_optimiser(InterDummy)
557
426
        try:
558
427
            # we should get the default for something InterDummy returns False
571
440
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
572
441
 
573
442
 
574
 
class TestInterWeaveRepo(TestCaseWithTransport):
575
 
 
576
 
    def test_is_compatible_and_registered(self):
577
 
        # InterWeaveRepo is compatible when either side
578
 
        # is a format 5/6/7 branch
579
 
        from bzrlib.repofmt import knitrepo, weaverepo
580
 
        formats = [weaverepo.RepositoryFormat5(),
581
 
                   weaverepo.RepositoryFormat6(),
582
 
                   weaverepo.RepositoryFormat7()]
583
 
        incompatible_formats = [weaverepo.RepositoryFormat4(),
584
 
                                knitrepo.RepositoryFormatKnit1(),
585
 
                                ]
586
 
        repo_a = self.make_repository('a')
587
 
        repo_b = self.make_repository('b')
588
 
        is_compatible = repository.InterWeaveRepo.is_compatible
589
 
        for source in incompatible_formats:
590
 
            # force incompatible left then right
591
 
            repo_a._format = source
592
 
            repo_b._format = formats[0]
593
 
            self.assertFalse(is_compatible(repo_a, repo_b))
594
 
            self.assertFalse(is_compatible(repo_b, repo_a))
595
 
        for source in formats:
596
 
            repo_a._format = source
597
 
            for target in formats:
598
 
                repo_b._format = target
599
 
                self.assertTrue(is_compatible(repo_a, repo_b))
600
 
        self.assertEqual(repository.InterWeaveRepo,
601
 
                         repository.InterRepository.get(repo_a,
602
 
                                                        repo_b).__class__)
 
443
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
 
444
 
 
445
    @classmethod
 
446
    def get_format_string(cls):
 
447
        return "Test Format 1"
 
448
 
 
449
 
 
450
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
 
451
 
 
452
    @classmethod
 
453
    def get_format_string(cls):
 
454
        return "Test Format 2"
603
455
 
604
456
 
605
457
class TestRepositoryConverter(TestCaseWithTransport):
606
458
 
607
459
    def test_convert_empty(self):
608
 
        t = get_transport(self.get_url('.'))
 
460
        source_format = TestRepositoryFormat1()
 
461
        target_format = TestRepositoryFormat2()
 
462
        repository.format_registry.register(source_format)
 
463
        self.addCleanup(repository.format_registry.remove,
 
464
            source_format)
 
465
        repository.format_registry.register(target_format)
 
466
        self.addCleanup(repository.format_registry.remove,
 
467
            target_format)
 
468
        t = self.get_transport()
609
469
        t.mkdir('repository')
610
470
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
611
 
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
612
 
        target_format = knitrepo.RepositoryFormatKnit1()
 
471
        repo = TestRepositoryFormat1().initialize(repo_dir)
613
472
        converter = repository.CopyConverter(target_format)
614
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
473
        pb = breezy.ui.ui_factory.nested_progress_bar()
615
474
        try:
616
475
            converter.convert(repo, pb)
617
476
        finally:
620
479
        self.assertTrue(isinstance(target_format, repo._format.__class__))
621
480
 
622
481
 
623
 
class TestMisc(TestCase):
624
 
 
625
 
    def test_unescape_xml(self):
626
 
        """We get some kind of error when malformed entities are passed"""
627
 
        self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;')
628
 
 
629
 
 
630
482
class TestRepositoryFormatKnit3(TestCaseWithTransport):
631
483
 
632
484
    def test_attribute__fetch_order(self):
653
505
        revision_tree.lock_read()
654
506
        try:
655
507
            self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
656
 
                revision_tree.inventory.root.file_id)
 
508
                revision_tree.get_root_id())
657
509
        finally:
658
510
            revision_tree.unlock()
659
511
        format = bzrdir.BzrDirMetaFormat1()
663
515
        revision_tree = tree.branch.repository.revision_tree('dull')
664
516
        revision_tree.lock_read()
665
517
        try:
666
 
            revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
 
518
            revision_tree.get_file_lines(revision_tree.get_root_id())
667
519
        finally:
668
520
            revision_tree.unlock()
669
521
        tree.commit("Another dull commit", rev_id='dull2')
670
522
        revision_tree = tree.branch.repository.revision_tree('dull2')
671
523
        revision_tree.lock_read()
672
524
        self.addCleanup(revision_tree.unlock)
673
 
        self.assertEqual('dull', revision_tree.inventory.root.revision)
 
525
        self.assertEqual('dull',
 
526
                revision_tree.get_file_revision(revision_tree.get_root_id()))
674
527
 
675
528
    def test_supports_external_lookups(self):
676
529
        format = bzrdir.BzrDirMetaFormat1()
681
534
 
682
535
class Test2a(tests.TestCaseWithMemoryTransport):
683
536
 
 
537
    def test_chk_bytes_uses_custom_btree_parser(self):
 
538
        mt = self.make_branch_and_memory_tree('test', format='2a')
 
539
        mt.lock_write()
 
540
        self.addCleanup(mt.unlock)
 
541
        mt.add([''], ['root-id'])
 
542
        mt.commit('first')
 
543
        index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
 
544
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
545
        # It should also work if we re-open the repo
 
546
        repo = mt.branch.repository.bzrdir.open_repository()
 
547
        repo.lock_read()
 
548
        self.addCleanup(repo.unlock)
 
549
        index = repo.chk_bytes._index._graph_index._indices[0]
 
550
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
551
 
684
552
    def test_fetch_combines_groups(self):
685
553
        builder = self.make_branch_builder('source', format='2a')
686
554
        builder.start_series()
812
680
        target = self.make_repository('target', format='rich-root-pack')
813
681
        stream = source._get_source(target._format)
814
682
        # We don't want the child GroupCHKStreamSource
815
 
        self.assertIs(type(stream), repository.StreamSource)
 
683
        self.assertIs(type(stream), vf_repository.StreamSource)
816
684
 
817
685
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
818
686
        source_builder = self.make_branch_builder('source',
845
713
 
846
714
        # On a regular pass, getting the inventories and chk pages for rev-2
847
715
        # would only get the newly created chk pages
848
 
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
849
 
                                    set(['rev-2']))
 
716
        search = vf_search.SearchResult({'rev-2'}, {'rev-1'}, 1,
 
717
                                    {'rev-2'})
850
718
        simple_chk_records = []
851
719
        for vf_name, substream in source.get_stream(search):
852
720
            if vf_name == 'chk_bytes':
894
762
        source = self.make_repository('source', format='pack-0.92')
895
763
        target = self.make_repository('target', format='pack-0.92')
896
764
        stream_source = source._get_source(target._format)
897
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
765
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
898
766
 
899
767
    def test_source_to_exact_pack_rich_root_pack(self):
900
768
        source = self.make_repository('source', format='rich-root-pack')
901
769
        target = self.make_repository('target', format='rich-root-pack')
902
770
        stream_source = source._get_source(target._format)
903
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
771
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
904
772
 
905
773
    def test_source_to_exact_pack_19(self):
906
774
        source = self.make_repository('source', format='1.9')
907
775
        target = self.make_repository('target', format='1.9')
908
776
        stream_source = source._get_source(target._format)
909
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
777
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
910
778
 
911
779
    def test_source_to_exact_pack_19_rich_root(self):
912
780
        source = self.make_repository('source', format='1.9-rich-root')
913
781
        target = self.make_repository('target', format='1.9-rich-root')
914
782
        stream_source = source._get_source(target._format)
915
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
783
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
916
784
 
917
785
    def test_source_to_remote_exact_pack_19(self):
918
786
        trans = self.make_smart_server('target')
921
789
        target = self.make_repository('target', format='1.9')
922
790
        target = repository.Repository.open(trans.base)
923
791
        stream_source = source._get_source(target._format)
924
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
792
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
925
793
 
926
794
    def test_stream_source_to_non_exact(self):
927
795
        source = self.make_repository('source', format='pack-0.92')
928
796
        target = self.make_repository('target', format='1.9')
929
797
        stream = source._get_source(target._format)
930
 
        self.assertIs(type(stream), repository.StreamSource)
 
798
        self.assertIs(type(stream), vf_repository.StreamSource)
931
799
 
932
800
    def test_stream_source_to_non_exact_rich_root(self):
933
801
        source = self.make_repository('source', format='1.9')
934
802
        target = self.make_repository('target', format='1.9-rich-root')
935
803
        stream = source._get_source(target._format)
936
 
        self.assertIs(type(stream), repository.StreamSource)
 
804
        self.assertIs(type(stream), vf_repository.StreamSource)
937
805
 
938
806
    def test_source_to_remote_non_exact_pack_19(self):
939
807
        trans = self.make_smart_server('target')
942
810
        target = self.make_repository('target', format='1.6')
943
811
        target = repository.Repository.open(trans.base)
944
812
        stream_source = source._get_source(target._format)
945
 
        self.assertIs(type(stream_source), repository.StreamSource)
 
813
        self.assertIs(type(stream_source), vf_repository.StreamSource)
946
814
 
947
815
    def test_stream_source_to_knit(self):
948
816
        source = self.make_repository('source', format='pack-0.92')
949
817
        target = self.make_repository('target', format='dirstate')
950
818
        stream = source._get_source(target._format)
951
 
        self.assertIs(type(stream), repository.StreamSource)
 
819
        self.assertIs(type(stream), vf_repository.StreamSource)
952
820
 
953
821
 
954
822
class TestDevelopment6FindParentIdsOfRevisions(TestCaseWithTransport):
956
824
 
957
825
    def setUp(self):
958
826
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
959
 
        self.builder = self.make_branch_builder('source',
960
 
            format='development6-rich-root')
 
827
        self.builder = self.make_branch_builder('source')
961
828
        self.builder.start_series()
962
829
        self.builder.build_snapshot('initial', None,
963
830
            [('add', ('', 'tree-root', 'directory', None))])
1033
900
            revision = _mod_revision.Revision('rev1a',
1034
901
                committer='jrandom@example.com', timestamp=0,
1035
902
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
1036
 
            repo.add_revision('rev1a',revision, inv)
 
903
            repo.add_revision('rev1a', revision, inv)
1037
904
 
1038
905
            # make rev1b, which has no Revision, but has an Inventory, and
1039
906
            # file1
1074
941
        revision = _mod_revision.Revision(revision_id,
1075
942
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
1076
943
            timezone=0, message='foo', parent_ids=parent_ids)
1077
 
        repo.add_revision(revision_id,revision, inv)
 
944
        repo.add_revision(revision_id, revision, inv)
1078
945
 
1079
946
    def add_file(self, repo, inv, filename, revision, parents):
1080
947
        file_id = filename + '-id'
1100
967
            return
1101
968
        empty_repo.lock_read()
1102
969
        self.addCleanup(empty_repo.unlock)
1103
 
        text = empty_repo.texts.get_record_stream(
1104
 
            [('file2-id', 'rev3')], 'topological', True).next()
 
970
        text = next(empty_repo.texts.get_record_stream(
 
971
            [('file2-id', 'rev3')], 'topological', True))
1105
972
        self.assertEqual('line\n', text.get_bytes_as('fulltext'))
1106
973
 
1107
974
 
1108
975
class TestRepositoryPackCollection(TestCaseWithTransport):
1109
976
 
1110
977
    def get_format(self):
1111
 
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
 
978
        return controldir.format_registry.make_bzrdir('pack-0.92')
1112
979
 
1113
980
    def get_packs(self):
1114
981
        format = self.get_format()
1153
1020
        obsolete_pack_trans.put_bytes('a-pack.iix', 'content\n')
1154
1021
        obsolete_pack_trans.put_bytes('another-pack.pack', 'foo\n')
1155
1022
        obsolete_pack_trans.put_bytes('not-a-pack.rix', 'foo\n')
1156
 
        res = packs._clear_obsolete_packs(preserve=set(['a-pack']))
 
1023
        res = packs._clear_obsolete_packs(preserve={'a-pack'})
1157
1024
        self.assertEqual(['a-pack', 'another-pack'], sorted(res))
1158
1025
        self.assertEqual(['a-pack.iix', 'a-pack.pack', 'a-pack.rix'],
1159
1026
                         sorted(obsolete_pack_trans.list_dir('.')))
1207
1074
                         sorted(packs._pack_transport.list_dir('.')))
1208
1075
        # names[0] should not be present in the index anymore
1209
1076
        self.assertEqual(names[1:],
1210
 
            sorted(set([osutils.splitext(n)[0] for n in
1211
 
                        packs._index_transport.list_dir('.')])))
 
1077
            sorted({osutils.splitext(n)[0] for n in
 
1078
                        packs._index_transport.list_dir('.')}))
 
1079
 
 
1080
    def test__obsolete_packs_missing_directory(self):
 
1081
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1082
        r.control_transport.rmdir('obsolete_packs')
 
1083
        names = packs.names()
 
1084
        pack = packs.get_pack_by_name(names[0])
 
1085
        # Schedule this one for removal
 
1086
        packs._remove_pack_from_memory(pack)
 
1087
        # Now trigger the obsoletion, and ensure that all the remaining files
 
1088
        # are still renamed
 
1089
        packs._obsolete_packs([pack])
 
1090
        self.assertEqual([n + '.pack' for n in names[1:]],
 
1091
                         sorted(packs._pack_transport.list_dir('.')))
 
1092
        # names[0] should not be present in the index anymore
 
1093
        self.assertEqual(names[1:],
 
1094
            sorted({osutils.splitext(n)[0] for n in
 
1095
                        packs._index_transport.list_dir('.')}))
1212
1096
 
1213
1097
    def test_pack_distribution_zero(self):
1214
1098
        packs = self.get_packs()
1390
1274
        # and remove another pack (via _remove_pack_from_memory)
1391
1275
        orig_names = packs.names()
1392
1276
        orig_at_load = packs._packs_at_load
1393
 
        to_remove_name = iter(orig_names).next()
 
1277
        to_remove_name = next(iter(orig_names))
1394
1278
        r.start_write_group()
1395
1279
        self.addCleanup(r.abort_write_group)
1396
1280
        r.texts.insert_record_stream([versionedfile.FulltextContentFactory(
1404
1288
        packs._remove_pack_from_memory(removed_pack)
1405
1289
        names = packs.names()
1406
1290
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1407
 
        new_names = set([x[0][0] for x in new_nodes])
 
1291
        new_names = {x[0][0] for x in new_nodes}
1408
1292
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1409
1293
        self.assertEqual(set(names) - set(orig_names), new_names)
1410
 
        self.assertEqual(set([new_pack.name]), new_names)
 
1294
        self.assertEqual({new_pack.name}, new_names)
1411
1295
        self.assertEqual([to_remove_name],
1412
1296
                         sorted([x[0][0] for x in deleted_nodes]))
1413
1297
        packs.reload_pack_names()
1415
1299
        self.assertEqual(orig_at_load, packs._packs_at_load)
1416
1300
        self.assertEqual(names, reloaded_names)
1417
1301
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1418
 
        new_names = set([x[0][0] for x in new_nodes])
 
1302
        new_names = {x[0][0] for x in new_nodes}
1419
1303
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1420
1304
        self.assertEqual(set(names) - set(orig_names), new_names)
1421
 
        self.assertEqual(set([new_pack.name]), new_names)
 
1305
        self.assertEqual({new_pack.name}, new_names)
1422
1306
        self.assertEqual([to_remove_name],
1423
1307
                         sorted([x[0][0] for x in deleted_nodes]))
1424
1308
 
1464
1348
        self.assertEqual([n + '.pack' for n in names[1:]], sorted(cur_packs))
1465
1349
        # obsolete_packs will also have stuff like .rix and .iix present.
1466
1350
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1467
 
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1351
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
1468
1352
        self.assertEqual([pack.name], sorted(obsolete_names))
1469
1353
 
1470
1354
    def test__save_pack_names_already_obsoleted(self):
1482
1366
        # Note that while we set clear_obsolete_packs=True, it should not
1483
1367
        # delete a pack file that we have also scheduled for obsoletion.
1484
1368
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1485
 
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1369
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
1486
1370
        self.assertEqual([pack.name], sorted(obsolete_names))
1487
1371
 
 
1372
    def test_pack_no_obsolete_packs_directory(self):
 
1373
        """Bug #314314, don't fail if obsolete_packs directory does
 
1374
        not exist."""
 
1375
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1376
        r.control_transport.rmdir('obsolete_packs')
 
1377
        packs._clear_obsolete_packs()
1488
1378
 
1489
1379
 
1490
1380
class TestPack(TestCaseWithTransport):
1591
1481
        # Because of how they were built, they correspond to
1592
1482
        # ['D', 'C', 'B', 'A']
1593
1483
        packs = b.repository._pack_collection.packs
1594
 
        packer = pack_repo.Packer(b.repository._pack_collection,
 
1484
        packer = knitpack_repo.KnitPacker(b.repository._pack_collection,
1595
1485
                                  packs, 'testing',
1596
1486
                                  revision_ids=['B', 'C'])
1597
1487
        # Now, when we are copying the B & C revisions, their pack files should
1611
1501
        return repo._pack_collection
1612
1502
 
1613
1503
    def test_open_pack_will_optimise(self):
1614
 
        packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
 
1504
        packer = knitpack_repo.OptimisingKnitPacker(self.get_pack_collection(),
1615
1505
                                            [], '.test')
1616
1506
        new_pack = packer.open_pack()
1617
1507
        self.addCleanup(new_pack.abort) # ensure cleanup
1622
1512
        self.assertTrue(new_pack.signature_index._optimize_for_size)
1623
1513
 
1624
1514
 
 
1515
class TestGCCHKPacker(TestCaseWithTransport):
 
1516
 
 
1517
    def make_abc_branch(self):
 
1518
        builder = self.make_branch_builder('source')
 
1519
        builder.start_series()
 
1520
        builder.build_snapshot('A', None, [
 
1521
            ('add', ('', 'root-id', 'directory', None)),
 
1522
            ('add', ('file', 'file-id', 'file', 'content\n')),
 
1523
            ])
 
1524
        builder.build_snapshot('B', ['A'], [
 
1525
            ('add', ('dir', 'dir-id', 'directory', None))])
 
1526
        builder.build_snapshot('C', ['B'], [
 
1527
            ('modify', ('file-id', 'new content\n'))])
 
1528
        builder.finish_series()
 
1529
        return builder.get_branch()
 
1530
 
 
1531
    def make_branch_with_disjoint_inventory_and_revision(self):
 
1532
        """a repo with separate packs for a revisions Revision and Inventory.
 
1533
 
 
1534
        There will be one pack file that holds the Revision content, and one
 
1535
        for the Inventory content.
 
1536
 
 
1537
        :return: (repository,
 
1538
                  pack_name_with_rev_A_Revision,
 
1539
                  pack_name_with_rev_A_Inventory,
 
1540
                  pack_name_with_rev_C_content)
 
1541
        """
 
1542
        b_source = self.make_abc_branch()
 
1543
        b_base = b_source.bzrdir.sprout('base', revision_id='A').open_branch()
 
1544
        b_stacked = b_base.bzrdir.sprout('stacked', stacked=True).open_branch()
 
1545
        b_stacked.lock_write()
 
1546
        self.addCleanup(b_stacked.unlock)
 
1547
        b_stacked.fetch(b_source, 'B')
 
1548
        # Now re-open the stacked repo directly (no fallbacks) so that we can
 
1549
        # fill in the A rev.
 
1550
        repo_not_stacked = b_stacked.bzrdir.open_repository()
 
1551
        repo_not_stacked.lock_write()
 
1552
        self.addCleanup(repo_not_stacked.unlock)
 
1553
        # Now we should have a pack file with A's inventory, but not its
 
1554
        # Revision
 
1555
        self.assertEqual([('A',), ('B',)],
 
1556
                         sorted(repo_not_stacked.inventories.keys()))
 
1557
        self.assertEqual([('B',)],
 
1558
                         sorted(repo_not_stacked.revisions.keys()))
 
1559
        stacked_pack_names = repo_not_stacked._pack_collection.names()
 
1560
        # We have a couple names here, figure out which has A's inventory
 
1561
        for name in stacked_pack_names:
 
1562
            pack = repo_not_stacked._pack_collection.get_pack_by_name(name)
 
1563
            keys = [n[1] for n in pack.inventory_index.iter_all_entries()]
 
1564
            if ('A',) in keys:
 
1565
                inv_a_pack_name = name
 
1566
                break
 
1567
        else:
 
1568
            self.fail('Could not find pack containing A\'s inventory')
 
1569
        repo_not_stacked.fetch(b_source.repository, 'A')
 
1570
        self.assertEqual([('A',), ('B',)],
 
1571
                         sorted(repo_not_stacked.revisions.keys()))
 
1572
        new_pack_names = set(repo_not_stacked._pack_collection.names())
 
1573
        rev_a_pack_names = new_pack_names.difference(stacked_pack_names)
 
1574
        self.assertEqual(1, len(rev_a_pack_names))
 
1575
        rev_a_pack_name = list(rev_a_pack_names)[0]
 
1576
        # Now fetch 'C', so we have a couple pack files to join
 
1577
        repo_not_stacked.fetch(b_source.repository, 'C')
 
1578
        rev_c_pack_names = set(repo_not_stacked._pack_collection.names())
 
1579
        rev_c_pack_names = rev_c_pack_names.difference(new_pack_names)
 
1580
        self.assertEqual(1, len(rev_c_pack_names))
 
1581
        rev_c_pack_name = list(rev_c_pack_names)[0]
 
1582
        return (repo_not_stacked, rev_a_pack_name, inv_a_pack_name,
 
1583
                rev_c_pack_name)
 
1584
 
 
1585
    def test_pack_with_distant_inventories(self):
 
1586
        # See https://bugs.launchpad.net/bzr/+bug/437003
 
1587
        # When repacking, it is possible to have an inventory in a different
 
1588
        # pack file than the associated revision. An autopack can then come
 
1589
        # along, and miss that inventory, and complain.
 
1590
        (repo, rev_a_pack_name, inv_a_pack_name, rev_c_pack_name
 
1591
         ) = self.make_branch_with_disjoint_inventory_and_revision()
 
1592
        a_pack = repo._pack_collection.get_pack_by_name(rev_a_pack_name)
 
1593
        c_pack = repo._pack_collection.get_pack_by_name(rev_c_pack_name)
 
1594
        packer = groupcompress_repo.GCCHKPacker(repo._pack_collection,
 
1595
                    [a_pack, c_pack], '.test-pack')
 
1596
        # This would raise ValueError in bug #437003, but should not raise an
 
1597
        # error once fixed.
 
1598
        packer.pack()
 
1599
 
 
1600
    def test_pack_with_missing_inventory(self):
 
1601
        # Similar to test_pack_with_missing_inventory, but this time, we force
 
1602
        # the A inventory to actually be gone from the repository.
 
1603
        (repo, rev_a_pack_name, inv_a_pack_name, rev_c_pack_name
 
1604
         ) = self.make_branch_with_disjoint_inventory_and_revision()
 
1605
        inv_a_pack = repo._pack_collection.get_pack_by_name(inv_a_pack_name)
 
1606
        repo._pack_collection._remove_pack_from_memory(inv_a_pack)
 
1607
        packer = groupcompress_repo.GCCHKPacker(repo._pack_collection,
 
1608
            repo._pack_collection.all_packs(), '.test-pack')
 
1609
        e = self.assertRaises(ValueError, packer.pack)
 
1610
        packer.new_pack.abort()
 
1611
        self.assertContainsRe(str(e),
 
1612
            r"We are missing inventories for revisions: .*'A'")
 
1613
 
 
1614
 
1625
1615
class TestCrossFormatPacks(TestCaseWithTransport):
1626
1616
 
1627
1617
    def log_pack(self, hint=None):
1642
1632
        self.addCleanup(target.unlock)
1643
1633
        source = source_tree.branch.repository._get_source(target._format)
1644
1634
        self.orig_pack = target.pack
1645
 
        target.pack = self.log_pack
 
1635
        self.overrideAttr(target, "pack", self.log_pack)
1646
1636
        search = target.search_missing_revision_ids(
1647
 
            source_tree.branch.repository, tip)
 
1637
            source_tree.branch.repository, revision_ids=[tip])
1648
1638
        stream = source.get_stream(search)
1649
1639
        from_format = source_tree.branch.repository._format
1650
1640
        sink = target._get_sink()
1666
1656
        self.addCleanup(target.unlock)
1667
1657
        source = source_tree.branch.repository
1668
1658
        self.orig_pack = target.pack
1669
 
        target.pack = self.log_pack
 
1659
        self.overrideAttr(target, "pack", self.log_pack)
1670
1660
        target.fetch(source)
1671
1661
        if expect_pack_called:
1672
1662
            self.assertLength(1, self.calls)
1700
1690
    def test_IDS_format_same_no(self):
1701
1691
        # When the formats are the same, pack is not called.
1702
1692
        self.run_fetch('2a', '2a', False)
 
1693
 
 
1694
 
 
1695
class Test_LazyListJoin(tests.TestCase):
 
1696
 
 
1697
    def test__repr__(self):
 
1698
        lazy = repository._LazyListJoin(['a'], ['b'])
 
1699
        self.assertEqual("breezy.repository._LazyListJoin((['a'], ['b']))",
 
1700
                         repr(lazy))
 
1701
 
 
1702
 
 
1703
class TestFeatures(tests.TestCaseWithTransport):
 
1704
 
 
1705
    def test_open_with_present_feature(self):
 
1706
        self.addCleanup(
 
1707
            repository.RepositoryFormatMetaDir.unregister_feature,
 
1708
            "makes-cheese-sandwich")
 
1709
        repository.RepositoryFormatMetaDir.register_feature(
 
1710
            "makes-cheese-sandwich")
 
1711
        repo = self.make_repository('.')
 
1712
        repo.lock_write()
 
1713
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1714
        repo._format.check_support_status(False)
 
1715
        repo.unlock()
 
1716
 
 
1717
    def test_open_with_missing_required_feature(self):
 
1718
        repo = self.make_repository('.')
 
1719
        repo.lock_write()
 
1720
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1721
        self.assertRaises(errors.MissingFeature,
 
1722
            repo._format.check_support_status, False)