/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-08-27 13:57:26 UTC
  • mto: This revision was merged to the branch mainline in revision 6773.
  • Revision ID: jelmer@jelmer.uk-20170827135726-o6k0a4j205zdh8k0
Fix some tests.

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 (
35
33
    tests,
36
 
    )
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 (
 
34
    transport,
 
35
    )
 
36
from breezy.bzr import (
 
37
    bzrdir,
 
38
    btree_index,
 
39
    inventory,
 
40
    repository as bzrrepository,
 
41
    versionedfile,
 
42
    vf_repository,
 
43
    vf_search,
 
44
    )
 
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 (
41
49
    TestCase,
42
50
    TestCaseWithTransport,
43
51
    )
44
 
from bzrlib.transport import (
45
 
    get_transport,
46
 
    )
47
 
from bzrlib import (
48
 
    bzrdir,
 
52
from breezy import (
 
53
    controldir,
49
54
    errors,
50
 
    inventory,
51
55
    osutils,
52
56
    repository,
53
57
    revision as _mod_revision,
54
58
    upgrade,
55
 
    versionedfile,
56
59
    workingtree,
57
60
    )
58
 
from bzrlib.repofmt import (
 
61
from breezy.bzr import (
59
62
    groupcompress_repo,
60
63
    knitrepo,
 
64
    knitpack_repo,
61
65
    pack_repo,
62
 
    weaverepo,
63
66
    )
64
67
 
65
68
 
66
69
class TestDefaultFormat(TestCase):
67
70
 
68
71
    def test_get_set_default_format(self):
69
 
        old_default = bzrdir.format_registry.get('default')
 
72
        old_default = controldir.format_registry.get('default')
70
73
        private_default = old_default().repository_format.__class__
71
 
        old_format = repository.RepositoryFormat.get_default_format()
 
74
        old_format = repository.format_registry.get_default()
72
75
        self.assertTrue(isinstance(old_format, private_default))
73
76
        def make_sample_bzrdir():
74
77
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
75
78
            my_bzrdir.repository_format = SampleRepositoryFormat()
76
79
            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')
 
80
        controldir.format_registry.remove('default')
 
81
        controldir.format_registry.register('sample', make_sample_bzrdir, '')
 
82
        controldir.format_registry.set_default('sample')
80
83
        # creating a repository should now create an instrumented dir.
81
84
        try:
82
85
            # the default branch format is used by the meta dir format
85
88
            result = dir.create_repository()
86
89
            self.assertEqual(result, 'A bzr repository dir')
87
90
        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(),
 
91
            controldir.format_registry.remove('default')
 
92
            controldir.format_registry.remove('sample')
 
93
            controldir.format_registry.register('default', old_default, '')
 
94
        self.assertIsInstance(repository.format_registry.get_default(),
92
95
                              old_format.__class__)
93
96
 
94
97
 
95
 
class SampleRepositoryFormat(repository.RepositoryFormat):
 
98
class SampleRepositoryFormat(bzrrepository.RepositoryFormatMetaDir):
96
99
    """A sample format
97
100
 
98
101
    this format is initializable, unsupported to aid in testing the
99
102
    open and open(unsupported=True) routines.
100
103
    """
101
104
 
102
 
    def get_format_string(self):
 
105
    @classmethod
 
106
    def get_format_string(cls):
103
107
        """See RepositoryFormat.get_format_string()."""
104
108
        return "Sample .bzr repository format."
105
109
 
106
 
    def initialize(self, a_bzrdir, shared=False):
 
110
    def initialize(self, a_controldir, shared=False):
107
111
        """Initialize a repository in a BzrDir"""
108
 
        t = a_bzrdir.get_repository_transport(self)
 
112
        t = a_controldir.get_repository_transport(self)
109
113
        t.put_bytes('format', self.get_format_string())
110
114
        return 'A bzr repository dir'
111
115
 
112
116
    def is_supported(self):
113
117
        return False
114
118
 
115
 
    def open(self, a_bzrdir, _found=False):
 
119
    def open(self, a_controldir, _found=False):
116
120
        return "opened repository."
117
121
 
118
122
 
 
123
class SampleExtraRepositoryFormat(repository.RepositoryFormat):
 
124
    """A sample format that can not be used in a metadir
 
125
 
 
126
    """
 
127
 
 
128
    def get_format_string(self):
 
129
        raise NotImplementedError
 
130
 
 
131
 
119
132
class TestRepositoryFormat(TestCaseWithTransport):
120
133
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
121
134
 
125
138
        # this is not quite the same as
126
139
        self.build_tree(["foo/", "bar/"])
127
140
        def check_format(format, url):
128
 
            dir = format._matchingbzrdir.initialize(url)
 
141
            dir = format._matchingcontroldir.initialize(url)
129
142
            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")
 
143
            t = transport.get_transport_from_path(url)
 
144
            found_format = bzrrepository.RepositoryFormatMetaDir.find_format(dir)
 
145
            self.assertIsInstance(found_format, format.__class__)
 
146
        check_format(repository.format_registry.get_default(), "bar")
134
147
 
135
148
    def test_find_format_no_repository(self):
136
149
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
137
150
        self.assertRaises(errors.NoRepositoryPresent,
138
 
                          repository.RepositoryFormat.find_format,
 
151
                          bzrrepository.RepositoryFormatMetaDir.find_format,
139
152
                          dir)
140
153
 
 
154
    def test_from_string(self):
 
155
        self.assertIsInstance(
 
156
            SampleRepositoryFormat.from_string(
 
157
                "Sample .bzr repository format."),
 
158
            SampleRepositoryFormat)
 
159
        self.assertRaises(AssertionError,
 
160
            SampleRepositoryFormat.from_string,
 
161
                "Different .bzr repository format.")
 
162
 
141
163
    def test_find_format_unknown_format(self):
142
164
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
143
165
        SampleRepositoryFormat().initialize(dir)
144
166
        self.assertRaises(UnknownFormatError,
145
 
                          repository.RepositoryFormat.find_format,
 
167
                          bzrrepository.RepositoryFormatMetaDir.find_format,
146
168
                          dir)
147
169
 
 
170
    def test_find_format_with_features(self):
 
171
        tree = self.make_branch_and_tree('.', format='2a')
 
172
        tree.branch.repository.update_feature_flags({"name": "necessity"})
 
173
        found_format = bzrrepository.RepositoryFormatMetaDir.find_format(tree.controldir)
 
174
        self.assertIsInstance(found_format, bzrrepository.RepositoryFormatMetaDir)
 
175
        self.assertEqual(found_format.features.get("name"), "necessity")
 
176
        self.assertRaises(bzrdir.MissingFeature, found_format.check_support_status,
 
177
            True)
 
178
        self.addCleanup(bzrrepository.RepositoryFormatMetaDir.unregister_feature,
 
179
            "name")
 
180
        bzrrepository.RepositoryFormatMetaDir.register_feature("name")
 
181
        found_format.check_support_status(True)
 
182
 
 
183
 
 
184
class TestRepositoryFormatRegistry(TestCase):
 
185
 
 
186
    def setUp(self):
 
187
        super(TestRepositoryFormatRegistry, self).setUp()
 
188
        self.registry = repository.RepositoryFormatRegistry()
 
189
 
148
190
    def test_register_unregister_format(self):
149
191
        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)
 
192
        self.registry.register(format)
 
193
        self.assertEqual(format, self.registry.get("Sample .bzr repository format."))
 
194
        self.registry.remove(format)
 
195
        self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
 
196
 
 
197
    def test_get_all(self):
 
198
        format = SampleRepositoryFormat()
 
199
        self.assertEqual([], self.registry._get_all())
 
200
        self.registry.register(format)
 
201
        self.assertEqual([format], self.registry._get_all())
 
202
 
 
203
    def test_register_extra(self):
 
204
        format = SampleExtraRepositoryFormat()
 
205
        self.assertEqual([], self.registry._get_all())
 
206
        self.registry.register_extra(format)
 
207
        self.assertEqual([format], self.registry._get_all())
 
208
 
 
209
    def test_register_extra_lazy(self):
 
210
        self.assertEqual([], self.registry._get_all())
 
211
        self.registry.register_extra_lazy("breezy.tests.test_repository",
 
212
            "SampleExtraRepositoryFormat")
 
213
        formats = self.registry._get_all()
 
214
        self.assertEqual(1, len(formats))
 
215
        self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
350
216
 
351
217
 
352
218
class TestFormatKnit1(TestCaseWithTransport):
354
220
    def test_attribute__fetch_order(self):
355
221
        """Knits need topological data insertion."""
356
222
        repo = self.make_repository('.',
357
 
                format=bzrdir.format_registry.get('knit')())
 
223
                format=controldir.format_registry.get('knit')())
358
224
        self.assertEqual('topological', repo._format._fetch_order)
359
225
 
360
226
    def test_attribute__fetch_uses_deltas(self):
361
227
        """Knits reuse deltas."""
362
228
        repo = self.make_repository('.',
363
 
                format=bzrdir.format_registry.get('knit')())
 
229
                format=controldir.format_registry.get('knit')())
364
230
        self.assertEqual(True, repo._format._fetch_uses_deltas)
365
231
 
366
232
    def test_disk_layout(self):
452
318
        is valid when the api is not being abused.
453
319
        """
454
320
        repo = self.make_repository('.',
455
 
                format=bzrdir.format_registry.get('knit')())
 
321
                format=controldir.format_registry.get('knit')())
456
322
        inv_xml = '<inventory format="5">\n</inventory>\n'
457
323
        inv = repo._deserialise_inventory('test-rev-id', inv_xml)
458
324
        self.assertEqual('test-rev-id', inv.root.revision)
460
326
    def test_deserialise_uses_global_revision_id(self):
461
327
        """If it is set, then we re-use the global revision id"""
462
328
        repo = self.make_repository('.',
463
 
                format=bzrdir.format_registry.get('knit')())
 
329
                format=controldir.format_registry.get('knit')())
464
330
        inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
465
331
                   '</inventory>\n')
466
332
        # Arguably, the deserialise_inventory should detect a mismatch, and
473
339
 
474
340
    def test_supports_external_lookups(self):
475
341
        repo = self.make_repository('.',
476
 
                format=bzrdir.format_registry.get('knit')())
 
342
                format=controldir.format_registry.get('knit')())
477
343
        self.assertFalse(repo._format.supports_external_lookups)
478
344
 
479
345
 
520
386
        # classes do not barf inappropriately when a surprising repository type
521
387
        # is handed to them.
522
388
        dummy_a = DummyRepository()
 
389
        dummy_a._format = RepositoryFormat()
 
390
        dummy_a._format.supports_full_versioned_files = True
523
391
        dummy_b = DummyRepository()
 
392
        dummy_b._format = RepositoryFormat()
 
393
        dummy_b._format.supports_full_versioned_files = True
524
394
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
525
395
 
526
396
    def assertGetsDefaultInterRepository(self, repo_a, repo_b):
530
400
        no actual sane default in the presence of incompatible data models.
531
401
        """
532
402
        inter_repo = repository.InterRepository.get(repo_a, repo_b)
533
 
        self.assertEqual(repository.InterSameDataRepository,
 
403
        self.assertEqual(vf_repository.InterSameDataRepository,
534
404
                         inter_repo.__class__)
535
405
        self.assertEqual(repo_a, inter_repo.source)
536
406
        self.assertEqual(repo_b, inter_repo.target)
550
420
        dummy_a._serializer = repo._serializer
551
421
        dummy_a._format.supports_tree_reference = repo._format.supports_tree_reference
552
422
        dummy_a._format.rich_root_data = repo._format.rich_root_data
 
423
        dummy_a._format.supports_full_versioned_files = repo._format.supports_full_versioned_files
553
424
        dummy_b._serializer = repo._serializer
554
425
        dummy_b._format.supports_tree_reference = repo._format.supports_tree_reference
555
426
        dummy_b._format.rich_root_data = repo._format.rich_root_data
 
427
        dummy_b._format.supports_full_versioned_files = repo._format.supports_full_versioned_files
556
428
        repository.InterRepository.register_optimiser(InterDummy)
557
429
        try:
558
430
            # we should get the default for something InterDummy returns False
571
443
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
572
444
 
573
445
 
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__)
 
446
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
 
447
 
 
448
    @classmethod
 
449
    def get_format_string(cls):
 
450
        return "Test Format 1"
 
451
 
 
452
 
 
453
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
 
454
 
 
455
    @classmethod
 
456
    def get_format_string(cls):
 
457
        return "Test Format 2"
603
458
 
604
459
 
605
460
class TestRepositoryConverter(TestCaseWithTransport):
606
461
 
607
462
    def test_convert_empty(self):
608
 
        t = get_transport(self.get_url('.'))
 
463
        source_format = TestRepositoryFormat1()
 
464
        target_format = TestRepositoryFormat2()
 
465
        repository.format_registry.register(source_format)
 
466
        self.addCleanup(repository.format_registry.remove,
 
467
            source_format)
 
468
        repository.format_registry.register(target_format)
 
469
        self.addCleanup(repository.format_registry.remove,
 
470
            target_format)
 
471
        t = self.get_transport()
609
472
        t.mkdir('repository')
610
473
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
611
 
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
612
 
        target_format = knitrepo.RepositoryFormatKnit1()
 
474
        repo = TestRepositoryFormat1().initialize(repo_dir)
613
475
        converter = repository.CopyConverter(target_format)
614
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
476
        pb = breezy.ui.ui_factory.nested_progress_bar()
615
477
        try:
616
478
            converter.convert(repo, pb)
617
479
        finally:
620
482
        self.assertTrue(isinstance(target_format, repo._format.__class__))
621
483
 
622
484
 
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
485
class TestRepositoryFormatKnit3(TestCaseWithTransport):
631
486
 
632
487
    def test_attribute__fetch_order(self):
653
508
        revision_tree.lock_read()
654
509
        try:
655
510
            self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
656
 
                revision_tree.inventory.root.file_id)
 
511
                revision_tree.get_root_id())
657
512
        finally:
658
513
            revision_tree.unlock()
659
514
        format = bzrdir.BzrDirMetaFormat1()
663
518
        revision_tree = tree.branch.repository.revision_tree('dull')
664
519
        revision_tree.lock_read()
665
520
        try:
666
 
            revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
 
521
            revision_tree.get_file_lines(revision_tree.get_root_id())
667
522
        finally:
668
523
            revision_tree.unlock()
669
524
        tree.commit("Another dull commit", rev_id='dull2')
670
525
        revision_tree = tree.branch.repository.revision_tree('dull2')
671
526
        revision_tree.lock_read()
672
527
        self.addCleanup(revision_tree.unlock)
673
 
        self.assertEqual('dull', revision_tree.inventory.root.revision)
 
528
        self.assertEqual('dull',
 
529
                revision_tree.get_file_revision(revision_tree.get_root_id()))
674
530
 
675
531
    def test_supports_external_lookups(self):
676
532
        format = bzrdir.BzrDirMetaFormat1()
681
537
 
682
538
class Test2a(tests.TestCaseWithMemoryTransport):
683
539
 
 
540
    def test_chk_bytes_uses_custom_btree_parser(self):
 
541
        mt = self.make_branch_and_memory_tree('test', format='2a')
 
542
        mt.lock_write()
 
543
        self.addCleanup(mt.unlock)
 
544
        mt.add([''], ['root-id'])
 
545
        mt.commit('first')
 
546
        index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
 
547
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
548
        # It should also work if we re-open the repo
 
549
        repo = mt.branch.repository.controldir.open_repository()
 
550
        repo.lock_read()
 
551
        self.addCleanup(repo.unlock)
 
552
        index = repo.chk_bytes._index._graph_index._indices[0]
 
553
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
554
 
684
555
    def test_fetch_combines_groups(self):
685
556
        builder = self.make_branch_builder('source', format='2a')
686
557
        builder.start_series()
812
683
        target = self.make_repository('target', format='rich-root-pack')
813
684
        stream = source._get_source(target._format)
814
685
        # We don't want the child GroupCHKStreamSource
815
 
        self.assertIs(type(stream), repository.StreamSource)
 
686
        self.assertIs(type(stream), vf_repository.StreamSource)
816
687
 
817
688
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
818
689
        source_builder = self.make_branch_builder('source',
845
716
 
846
717
        # On a regular pass, getting the inventories and chk pages for rev-2
847
718
        # would only get the newly created chk pages
848
 
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
849
 
                                    set(['rev-2']))
 
719
        search = vf_search.SearchResult({'rev-2'}, {'rev-1'}, 1,
 
720
                                    {'rev-2'})
850
721
        simple_chk_records = []
851
722
        for vf_name, substream in source.get_stream(search):
852
723
            if vf_name == 'chk_bytes':
894
765
        source = self.make_repository('source', format='pack-0.92')
895
766
        target = self.make_repository('target', format='pack-0.92')
896
767
        stream_source = source._get_source(target._format)
897
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
768
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
898
769
 
899
770
    def test_source_to_exact_pack_rich_root_pack(self):
900
771
        source = self.make_repository('source', format='rich-root-pack')
901
772
        target = self.make_repository('target', format='rich-root-pack')
902
773
        stream_source = source._get_source(target._format)
903
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
774
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
904
775
 
905
776
    def test_source_to_exact_pack_19(self):
906
777
        source = self.make_repository('source', format='1.9')
907
778
        target = self.make_repository('target', format='1.9')
908
779
        stream_source = source._get_source(target._format)
909
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
780
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
910
781
 
911
782
    def test_source_to_exact_pack_19_rich_root(self):
912
783
        source = self.make_repository('source', format='1.9-rich-root')
913
784
        target = self.make_repository('target', format='1.9-rich-root')
914
785
        stream_source = source._get_source(target._format)
915
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
786
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
916
787
 
917
788
    def test_source_to_remote_exact_pack_19(self):
918
789
        trans = self.make_smart_server('target')
921
792
        target = self.make_repository('target', format='1.9')
922
793
        target = repository.Repository.open(trans.base)
923
794
        stream_source = source._get_source(target._format)
924
 
        self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
 
795
        self.assertIsInstance(stream_source, knitpack_repo.KnitPackStreamSource)
925
796
 
926
797
    def test_stream_source_to_non_exact(self):
927
798
        source = self.make_repository('source', format='pack-0.92')
928
799
        target = self.make_repository('target', format='1.9')
929
800
        stream = source._get_source(target._format)
930
 
        self.assertIs(type(stream), repository.StreamSource)
 
801
        self.assertIs(type(stream), vf_repository.StreamSource)
931
802
 
932
803
    def test_stream_source_to_non_exact_rich_root(self):
933
804
        source = self.make_repository('source', format='1.9')
934
805
        target = self.make_repository('target', format='1.9-rich-root')
935
806
        stream = source._get_source(target._format)
936
 
        self.assertIs(type(stream), repository.StreamSource)
 
807
        self.assertIs(type(stream), vf_repository.StreamSource)
937
808
 
938
809
    def test_source_to_remote_non_exact_pack_19(self):
939
810
        trans = self.make_smart_server('target')
942
813
        target = self.make_repository('target', format='1.6')
943
814
        target = repository.Repository.open(trans.base)
944
815
        stream_source = source._get_source(target._format)
945
 
        self.assertIs(type(stream_source), repository.StreamSource)
 
816
        self.assertIs(type(stream_source), vf_repository.StreamSource)
946
817
 
947
818
    def test_stream_source_to_knit(self):
948
819
        source = self.make_repository('source', format='pack-0.92')
949
820
        target = self.make_repository('target', format='dirstate')
950
821
        stream = source._get_source(target._format)
951
 
        self.assertIs(type(stream), repository.StreamSource)
 
822
        self.assertIs(type(stream), vf_repository.StreamSource)
952
823
 
953
824
 
954
825
class TestDevelopment6FindParentIdsOfRevisions(TestCaseWithTransport):
956
827
 
957
828
    def setUp(self):
958
829
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
959
 
        self.builder = self.make_branch_builder('source',
960
 
            format='development6-rich-root')
 
830
        self.builder = self.make_branch_builder('source')
961
831
        self.builder.start_series()
962
832
        self.builder.build_snapshot('initial', None,
963
833
            [('add', ('', 'tree-root', 'directory', None))])
1033
903
            revision = _mod_revision.Revision('rev1a',
1034
904
                committer='jrandom@example.com', timestamp=0,
1035
905
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
1036
 
            repo.add_revision('rev1a',revision, inv)
 
906
            repo.add_revision('rev1a', revision, inv)
1037
907
 
1038
908
            # make rev1b, which has no Revision, but has an Inventory, and
1039
909
            # file1
1074
944
        revision = _mod_revision.Revision(revision_id,
1075
945
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
1076
946
            timezone=0, message='foo', parent_ids=parent_ids)
1077
 
        repo.add_revision(revision_id,revision, inv)
 
947
        repo.add_revision(revision_id, revision, inv)
1078
948
 
1079
949
    def add_file(self, repo, inv, filename, revision, parents):
1080
950
        file_id = filename + '-id'
1100
970
            return
1101
971
        empty_repo.lock_read()
1102
972
        self.addCleanup(empty_repo.unlock)
1103
 
        text = empty_repo.texts.get_record_stream(
1104
 
            [('file2-id', 'rev3')], 'topological', True).next()
 
973
        text = next(empty_repo.texts.get_record_stream(
 
974
            [('file2-id', 'rev3')], 'topological', True))
1105
975
        self.assertEqual('line\n', text.get_bytes_as('fulltext'))
1106
976
 
1107
977
 
1108
978
class TestRepositoryPackCollection(TestCaseWithTransport):
1109
979
 
1110
980
    def get_format(self):
1111
 
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
 
981
        return controldir.format_registry.make_controldir('pack-0.92')
1112
982
 
1113
983
    def get_packs(self):
1114
984
        format = self.get_format()
1153
1023
        obsolete_pack_trans.put_bytes('a-pack.iix', 'content\n')
1154
1024
        obsolete_pack_trans.put_bytes('another-pack.pack', 'foo\n')
1155
1025
        obsolete_pack_trans.put_bytes('not-a-pack.rix', 'foo\n')
1156
 
        res = packs._clear_obsolete_packs(preserve=set(['a-pack']))
 
1026
        res = packs._clear_obsolete_packs(preserve={'a-pack'})
1157
1027
        self.assertEqual(['a-pack', 'another-pack'], sorted(res))
1158
1028
        self.assertEqual(['a-pack.iix', 'a-pack.pack', 'a-pack.rix'],
1159
1029
                         sorted(obsolete_pack_trans.list_dir('.')))
1207
1077
                         sorted(packs._pack_transport.list_dir('.')))
1208
1078
        # names[0] should not be present in the index anymore
1209
1079
        self.assertEqual(names[1:],
1210
 
            sorted(set([osutils.splitext(n)[0] for n in
1211
 
                        packs._index_transport.list_dir('.')])))
 
1080
            sorted({osutils.splitext(n)[0] for n in
 
1081
                        packs._index_transport.list_dir('.')}))
 
1082
 
 
1083
    def test__obsolete_packs_missing_directory(self):
 
1084
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1085
        r.control_transport.rmdir('obsolete_packs')
 
1086
        names = packs.names()
 
1087
        pack = packs.get_pack_by_name(names[0])
 
1088
        # Schedule this one for removal
 
1089
        packs._remove_pack_from_memory(pack)
 
1090
        # Now trigger the obsoletion, and ensure that all the remaining files
 
1091
        # are still renamed
 
1092
        packs._obsolete_packs([pack])
 
1093
        self.assertEqual([n + '.pack' for n in names[1:]],
 
1094
                         sorted(packs._pack_transport.list_dir('.')))
 
1095
        # names[0] should not be present in the index anymore
 
1096
        self.assertEqual(names[1:],
 
1097
            sorted({osutils.splitext(n)[0] for n in
 
1098
                        packs._index_transport.list_dir('.')}))
1212
1099
 
1213
1100
    def test_pack_distribution_zero(self):
1214
1101
        packs = self.get_packs()
1390
1277
        # and remove another pack (via _remove_pack_from_memory)
1391
1278
        orig_names = packs.names()
1392
1279
        orig_at_load = packs._packs_at_load
1393
 
        to_remove_name = iter(orig_names).next()
 
1280
        to_remove_name = next(iter(orig_names))
1394
1281
        r.start_write_group()
1395
1282
        self.addCleanup(r.abort_write_group)
1396
1283
        r.texts.insert_record_stream([versionedfile.FulltextContentFactory(
1404
1291
        packs._remove_pack_from_memory(removed_pack)
1405
1292
        names = packs.names()
1406
1293
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1407
 
        new_names = set([x[0][0] for x in new_nodes])
 
1294
        new_names = {x[0][0] for x in new_nodes}
1408
1295
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1409
1296
        self.assertEqual(set(names) - set(orig_names), new_names)
1410
 
        self.assertEqual(set([new_pack.name]), new_names)
 
1297
        self.assertEqual({new_pack.name}, new_names)
1411
1298
        self.assertEqual([to_remove_name],
1412
1299
                         sorted([x[0][0] for x in deleted_nodes]))
1413
1300
        packs.reload_pack_names()
1415
1302
        self.assertEqual(orig_at_load, packs._packs_at_load)
1416
1303
        self.assertEqual(names, reloaded_names)
1417
1304
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
1418
 
        new_names = set([x[0][0] for x in new_nodes])
 
1305
        new_names = {x[0][0] for x in new_nodes}
1419
1306
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
1420
1307
        self.assertEqual(set(names) - set(orig_names), new_names)
1421
 
        self.assertEqual(set([new_pack.name]), new_names)
 
1308
        self.assertEqual({new_pack.name}, new_names)
1422
1309
        self.assertEqual([to_remove_name],
1423
1310
                         sorted([x[0][0] for x in deleted_nodes]))
1424
1311
 
1464
1351
        self.assertEqual([n + '.pack' for n in names[1:]], sorted(cur_packs))
1465
1352
        # obsolete_packs will also have stuff like .rix and .iix present.
1466
1353
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1467
 
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1354
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
1468
1355
        self.assertEqual([pack.name], sorted(obsolete_names))
1469
1356
 
1470
1357
    def test__save_pack_names_already_obsoleted(self):
1482
1369
        # Note that while we set clear_obsolete_packs=True, it should not
1483
1370
        # delete a pack file that we have also scheduled for obsoletion.
1484
1371
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
1485
 
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1372
        obsolete_names = {osutils.splitext(n)[0] for n in obsolete_packs}
1486
1373
        self.assertEqual([pack.name], sorted(obsolete_names))
1487
1374
 
 
1375
    def test_pack_no_obsolete_packs_directory(self):
 
1376
        """Bug #314314, don't fail if obsolete_packs directory does
 
1377
        not exist."""
 
1378
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1379
        r.control_transport.rmdir('obsolete_packs')
 
1380
        packs._clear_obsolete_packs()
1488
1381
 
1489
1382
 
1490
1383
class TestPack(TestCaseWithTransport):
1591
1484
        # Because of how they were built, they correspond to
1592
1485
        # ['D', 'C', 'B', 'A']
1593
1486
        packs = b.repository._pack_collection.packs
1594
 
        packer = pack_repo.Packer(b.repository._pack_collection,
 
1487
        packer = knitpack_repo.KnitPacker(b.repository._pack_collection,
1595
1488
                                  packs, 'testing',
1596
1489
                                  revision_ids=['B', 'C'])
1597
1490
        # Now, when we are copying the B & C revisions, their pack files should
1611
1504
        return repo._pack_collection
1612
1505
 
1613
1506
    def test_open_pack_will_optimise(self):
1614
 
        packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
 
1507
        packer = knitpack_repo.OptimisingKnitPacker(self.get_pack_collection(),
1615
1508
                                            [], '.test')
1616
1509
        new_pack = packer.open_pack()
1617
1510
        self.addCleanup(new_pack.abort) # ensure cleanup
1622
1515
        self.assertTrue(new_pack.signature_index._optimize_for_size)
1623
1516
 
1624
1517
 
 
1518
class TestGCCHKPacker(TestCaseWithTransport):
 
1519
 
 
1520
    def make_abc_branch(self):
 
1521
        builder = self.make_branch_builder('source')
 
1522
        builder.start_series()
 
1523
        builder.build_snapshot('A', None, [
 
1524
            ('add', ('', 'root-id', 'directory', None)),
 
1525
            ('add', ('file', 'file-id', 'file', 'content\n')),
 
1526
            ])
 
1527
        builder.build_snapshot('B', ['A'], [
 
1528
            ('add', ('dir', 'dir-id', 'directory', None))])
 
1529
        builder.build_snapshot('C', ['B'], [
 
1530
            ('modify', ('file-id', 'new content\n'))])
 
1531
        builder.finish_series()
 
1532
        return builder.get_branch()
 
1533
 
 
1534
    def make_branch_with_disjoint_inventory_and_revision(self):
 
1535
        """a repo with separate packs for a revisions Revision and Inventory.
 
1536
 
 
1537
        There will be one pack file that holds the Revision content, and one
 
1538
        for the Inventory content.
 
1539
 
 
1540
        :return: (repository,
 
1541
                  pack_name_with_rev_A_Revision,
 
1542
                  pack_name_with_rev_A_Inventory,
 
1543
                  pack_name_with_rev_C_content)
 
1544
        """
 
1545
        b_source = self.make_abc_branch()
 
1546
        b_base = b_source.controldir.sprout('base', revision_id='A').open_branch()
 
1547
        b_stacked = b_base.controldir.sprout('stacked', stacked=True).open_branch()
 
1548
        b_stacked.lock_write()
 
1549
        self.addCleanup(b_stacked.unlock)
 
1550
        b_stacked.fetch(b_source, 'B')
 
1551
        # Now re-open the stacked repo directly (no fallbacks) so that we can
 
1552
        # fill in the A rev.
 
1553
        repo_not_stacked = b_stacked.controldir.open_repository()
 
1554
        repo_not_stacked.lock_write()
 
1555
        self.addCleanup(repo_not_stacked.unlock)
 
1556
        # Now we should have a pack file with A's inventory, but not its
 
1557
        # Revision
 
1558
        self.assertEqual([('A',), ('B',)],
 
1559
                         sorted(repo_not_stacked.inventories.keys()))
 
1560
        self.assertEqual([('B',)],
 
1561
                         sorted(repo_not_stacked.revisions.keys()))
 
1562
        stacked_pack_names = repo_not_stacked._pack_collection.names()
 
1563
        # We have a couple names here, figure out which has A's inventory
 
1564
        for name in stacked_pack_names:
 
1565
            pack = repo_not_stacked._pack_collection.get_pack_by_name(name)
 
1566
            keys = [n[1] for n in pack.inventory_index.iter_all_entries()]
 
1567
            if ('A',) in keys:
 
1568
                inv_a_pack_name = name
 
1569
                break
 
1570
        else:
 
1571
            self.fail('Could not find pack containing A\'s inventory')
 
1572
        repo_not_stacked.fetch(b_source.repository, 'A')
 
1573
        self.assertEqual([('A',), ('B',)],
 
1574
                         sorted(repo_not_stacked.revisions.keys()))
 
1575
        new_pack_names = set(repo_not_stacked._pack_collection.names())
 
1576
        rev_a_pack_names = new_pack_names.difference(stacked_pack_names)
 
1577
        self.assertEqual(1, len(rev_a_pack_names))
 
1578
        rev_a_pack_name = list(rev_a_pack_names)[0]
 
1579
        # Now fetch 'C', so we have a couple pack files to join
 
1580
        repo_not_stacked.fetch(b_source.repository, 'C')
 
1581
        rev_c_pack_names = set(repo_not_stacked._pack_collection.names())
 
1582
        rev_c_pack_names = rev_c_pack_names.difference(new_pack_names)
 
1583
        self.assertEqual(1, len(rev_c_pack_names))
 
1584
        rev_c_pack_name = list(rev_c_pack_names)[0]
 
1585
        return (repo_not_stacked, rev_a_pack_name, inv_a_pack_name,
 
1586
                rev_c_pack_name)
 
1587
 
 
1588
    def test_pack_with_distant_inventories(self):
 
1589
        # See https://bugs.launchpad.net/bzr/+bug/437003
 
1590
        # When repacking, it is possible to have an inventory in a different
 
1591
        # pack file than the associated revision. An autopack can then come
 
1592
        # along, and miss that inventory, and complain.
 
1593
        (repo, rev_a_pack_name, inv_a_pack_name, rev_c_pack_name
 
1594
         ) = self.make_branch_with_disjoint_inventory_and_revision()
 
1595
        a_pack = repo._pack_collection.get_pack_by_name(rev_a_pack_name)
 
1596
        c_pack = repo._pack_collection.get_pack_by_name(rev_c_pack_name)
 
1597
        packer = groupcompress_repo.GCCHKPacker(repo._pack_collection,
 
1598
                    [a_pack, c_pack], '.test-pack')
 
1599
        # This would raise ValueError in bug #437003, but should not raise an
 
1600
        # error once fixed.
 
1601
        packer.pack()
 
1602
 
 
1603
    def test_pack_with_missing_inventory(self):
 
1604
        # Similar to test_pack_with_missing_inventory, but this time, we force
 
1605
        # the A inventory to actually be gone from the repository.
 
1606
        (repo, rev_a_pack_name, inv_a_pack_name, rev_c_pack_name
 
1607
         ) = self.make_branch_with_disjoint_inventory_and_revision()
 
1608
        inv_a_pack = repo._pack_collection.get_pack_by_name(inv_a_pack_name)
 
1609
        repo._pack_collection._remove_pack_from_memory(inv_a_pack)
 
1610
        packer = groupcompress_repo.GCCHKPacker(repo._pack_collection,
 
1611
            repo._pack_collection.all_packs(), '.test-pack')
 
1612
        e = self.assertRaises(ValueError, packer.pack)
 
1613
        packer.new_pack.abort()
 
1614
        self.assertContainsRe(str(e),
 
1615
            r"We are missing inventories for revisions: .*'A'")
 
1616
 
 
1617
 
1625
1618
class TestCrossFormatPacks(TestCaseWithTransport):
1626
1619
 
1627
1620
    def log_pack(self, hint=None):
1642
1635
        self.addCleanup(target.unlock)
1643
1636
        source = source_tree.branch.repository._get_source(target._format)
1644
1637
        self.orig_pack = target.pack
1645
 
        target.pack = self.log_pack
 
1638
        self.overrideAttr(target, "pack", self.log_pack)
1646
1639
        search = target.search_missing_revision_ids(
1647
 
            source_tree.branch.repository, tip)
 
1640
            source_tree.branch.repository, revision_ids=[tip])
1648
1641
        stream = source.get_stream(search)
1649
1642
        from_format = source_tree.branch.repository._format
1650
1643
        sink = target._get_sink()
1666
1659
        self.addCleanup(target.unlock)
1667
1660
        source = source_tree.branch.repository
1668
1661
        self.orig_pack = target.pack
1669
 
        target.pack = self.log_pack
 
1662
        self.overrideAttr(target, "pack", self.log_pack)
1670
1663
        target.fetch(source)
1671
1664
        if expect_pack_called:
1672
1665
            self.assertLength(1, self.calls)
1700
1693
    def test_IDS_format_same_no(self):
1701
1694
        # When the formats are the same, pack is not called.
1702
1695
        self.run_fetch('2a', '2a', False)
 
1696
 
 
1697
 
 
1698
class Test_LazyListJoin(tests.TestCase):
 
1699
 
 
1700
    def test__repr__(self):
 
1701
        lazy = repository._LazyListJoin(['a'], ['b'])
 
1702
        self.assertEqual("breezy.repository._LazyListJoin((['a'], ['b']))",
 
1703
                         repr(lazy))
 
1704
 
 
1705
 
 
1706
class TestFeatures(tests.TestCaseWithTransport):
 
1707
 
 
1708
    def test_open_with_present_feature(self):
 
1709
        self.addCleanup(
 
1710
            bzrrepository.RepositoryFormatMetaDir.unregister_feature,
 
1711
            "makes-cheese-sandwich")
 
1712
        bzrrepository.RepositoryFormatMetaDir.register_feature(
 
1713
            "makes-cheese-sandwich")
 
1714
        repo = self.make_repository('.')
 
1715
        repo.lock_write()
 
1716
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1717
        repo._format.check_support_status(False)
 
1718
        repo.unlock()
 
1719
 
 
1720
    def test_open_with_missing_required_feature(self):
 
1721
        repo = self.make_repository('.')
 
1722
        repo.lock_write()
 
1723
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1724
        self.assertRaises(bzrdir.MissingFeature,
 
1725
            repo._format.check_support_status, False)