/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-12 00:01:34 UTC
  • mfrom: (5582.10.97 weave-plugin)
  • Revision ID: pqm@pqm.ubuntu.com-20110312000134-exy10w8ctjs8tpiu
Tags: upstream-2.4.0~beta1~bzr5718
(jelmer) Add Prober.known_formats() in favour of
 BzrDirFormat.register_format() and ControlDirFormat.register_format().
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
"""
24
24
 
25
25
from stat import S_ISDIR
26
 
import sys
27
26
 
28
27
import bzrlib
29
28
from bzrlib.errors import (
30
 
    NoSuchFile,
31
29
    UnknownFormatError,
32
30
    UnsupportedFormatError,
33
31
    )
47
45
    )
48
46
from bzrlib import (
49
47
    bzrdir,
50
 
    bzrdir_weave,
51
48
    errors,
52
49
    inventory,
53
50
    osutils,
61
58
    groupcompress_repo,
62
59
    knitrepo,
63
60
    pack_repo,
64
 
    weaverepo,
65
61
    )
66
62
 
67
63
 
210
206
        self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
211
207
 
212
208
 
213
 
class TestFormat6(TestCaseWithTransport):
214
 
 
215
 
    def test_attribute__fetch_order(self):
216
 
        """Weaves need topological data insertion."""
217
 
        control = bzrdir_weave.BzrDirFormat6().initialize(self.get_url())
218
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
219
 
        self.assertEqual('topological', repo._format._fetch_order)
220
 
 
221
 
    def test_attribute__fetch_uses_deltas(self):
222
 
        """Weaves do not reuse deltas."""
223
 
        control = bzrdir_weave.BzrDirFormat6().initialize(self.get_url())
224
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
225
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
226
 
 
227
 
    def test_attribute__fetch_reconcile(self):
228
 
        """Weave repositories need a reconcile after fetch."""
229
 
        control = bzrdir_weave.BzrDirFormat6().initialize(self.get_url())
230
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
231
 
        self.assertEqual(True, repo._format._fetch_reconcile)
232
 
 
233
 
    def test_no_ancestry_weave(self):
234
 
        control = bzrdir_weave.BzrDirFormat6().initialize(self.get_url())
235
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
236
 
        # We no longer need to create the ancestry.weave file
237
 
        # since it is *never* used.
238
 
        self.assertRaises(NoSuchFile,
239
 
                          control.transport.get,
240
 
                          'ancestry.weave')
241
 
 
242
 
    def test_supports_external_lookups(self):
243
 
        control = bzrdir_weave.BzrDirFormat6().initialize(self.get_url())
244
 
        repo = weaverepo.RepositoryFormat6().initialize(control)
245
 
        self.assertFalse(repo._format.supports_external_lookups)
246
 
 
247
 
 
248
 
class TestFormat7(TestCaseWithTransport):
249
 
 
250
 
    def test_attribute__fetch_order(self):
251
 
        """Weaves need topological data insertion."""
252
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
253
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
254
 
        self.assertEqual('topological', repo._format._fetch_order)
255
 
 
256
 
    def test_attribute__fetch_uses_deltas(self):
257
 
        """Weaves do not reuse deltas."""
258
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
259
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
260
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
261
 
 
262
 
    def test_attribute__fetch_reconcile(self):
263
 
        """Weave repositories need a reconcile after fetch."""
264
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
265
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
266
 
        self.assertEqual(True, repo._format._fetch_reconcile)
267
 
 
268
 
    def test_disk_layout(self):
269
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
270
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
271
 
        # in case of side effects of locking.
272
 
        repo.lock_write()
273
 
        repo.unlock()
274
 
        # we want:
275
 
        # format 'Bazaar-NG Repository format 7'
276
 
        # lock ''
277
 
        # inventory.weave == empty_weave
278
 
        # empty revision-store directory
279
 
        # empty weaves directory
280
 
        t = control.get_repository_transport(None)
281
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
282
 
                             t.get('format').read())
283
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
284
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
285
 
        self.assertEqualDiff('# bzr weave file v5\n'
286
 
                             'w\n'
287
 
                             'W\n',
288
 
                             t.get('inventory.weave').read())
289
 
        # Creating a file with id Foo:Bar results in a non-escaped file name on
290
 
        # disk.
291
 
        control.create_branch()
292
 
        tree = control.create_workingtree()
293
 
        tree.add(['foo'], ['Foo:Bar'], ['file'])
294
 
        tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
295
 
        try:
296
 
            tree.commit('first post', rev_id='first')
297
 
        except errors.IllegalPath:
298
 
            if sys.platform != 'win32':
299
 
                raise
300
 
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
301
 
                              ' in repo format 7')
302
 
            return
303
 
        self.assertEqualDiff(
304
 
            '# bzr weave file v5\n'
305
 
            'i\n'
306
 
            '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
307
 
            'n first\n'
308
 
            '\n'
309
 
            'w\n'
310
 
            '{ 0\n'
311
 
            '. content\n'
312
 
            '}\n'
313
 
            'W\n',
314
 
            t.get('weaves/74/Foo%3ABar.weave').read())
315
 
 
316
 
    def test_shared_disk_layout(self):
317
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
318
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
319
 
        # we want:
320
 
        # format 'Bazaar-NG Repository format 7'
321
 
        # inventory.weave == empty_weave
322
 
        # empty revision-store directory
323
 
        # empty weaves directory
324
 
        # a 'shared-storage' marker file.
325
 
        # lock is not present when unlocked
326
 
        t = control.get_repository_transport(None)
327
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
328
 
                             t.get('format').read())
329
 
        self.assertEqualDiff('', t.get('shared-storage').read())
330
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
331
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
332
 
        self.assertEqualDiff('# bzr weave file v5\n'
333
 
                             'w\n'
334
 
                             'W\n',
335
 
                             t.get('inventory.weave').read())
336
 
        self.assertFalse(t.has('branch-lock'))
337
 
 
338
 
    def test_creates_lockdir(self):
339
 
        """Make sure it appears to be controlled by a LockDir existence"""
340
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
341
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
342
 
        t = control.get_repository_transport(None)
343
 
        # TODO: Should check there is a 'lock' toplevel directory,
344
 
        # regardless of contents
345
 
        self.assertFalse(t.has('lock/held/info'))
346
 
        repo.lock_write()
347
 
        try:
348
 
            self.assertTrue(t.has('lock/held/info'))
349
 
        finally:
350
 
            # unlock so we don't get a warning about failing to do so
351
 
            repo.unlock()
352
 
 
353
 
    def test_uses_lockdir(self):
354
 
        """repo format 7 actually locks on lockdir"""
355
 
        base_url = self.get_url()
356
 
        control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
357
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
358
 
        t = control.get_repository_transport(None)
359
 
        repo.lock_write()
360
 
        repo.unlock()
361
 
        del repo
362
 
        # make sure the same lock is created by opening it
363
 
        repo = repository.Repository.open(base_url)
364
 
        repo.lock_write()
365
 
        self.assertTrue(t.has('lock/held/info'))
366
 
        repo.unlock()
367
 
        self.assertFalse(t.has('lock/held/info'))
368
 
 
369
 
    def test_shared_no_tree_disk_layout(self):
370
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
371
 
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
372
 
        repo.set_make_working_trees(False)
373
 
        # we want:
374
 
        # format 'Bazaar-NG Repository format 7'
375
 
        # lock ''
376
 
        # inventory.weave == empty_weave
377
 
        # empty revision-store directory
378
 
        # empty weaves directory
379
 
        # a 'shared-storage' marker file.
380
 
        t = control.get_repository_transport(None)
381
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
382
 
                             t.get('format').read())
383
 
        ## self.assertEqualDiff('', t.get('lock').read())
384
 
        self.assertEqualDiff('', t.get('shared-storage').read())
385
 
        self.assertEqualDiff('', t.get('no-working-trees').read())
386
 
        repo.set_make_working_trees(True)
387
 
        self.assertFalse(t.has('no-working-trees'))
388
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
389
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
390
 
        self.assertEqualDiff('# bzr weave file v5\n'
391
 
                             'w\n'
392
 
                             'W\n',
393
 
                             t.get('inventory.weave').read())
394
 
 
395
 
    def test_supports_external_lookups(self):
396
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
397
 
        repo = weaverepo.RepositoryFormat7().initialize(control)
398
 
        self.assertFalse(repo._format.supports_external_lookups)
399
 
 
400
 
 
401
209
class TestFormatKnit1(TestCaseWithTransport):
402
210
 
403
211
    def test_attribute__fetch_order(self):
620
428
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
621
429
 
622
430
 
623
 
class TestInterWeaveRepo(TestCaseWithTransport):
624
 
 
625
 
    def test_is_compatible_and_registered(self):
626
 
        # InterWeaveRepo is compatible when either side
627
 
        # is a format 5/6/7 branch
628
 
        from bzrlib.repofmt import knitrepo, weaverepo
629
 
        formats = [weaverepo.RepositoryFormat5(),
630
 
                   weaverepo.RepositoryFormat6(),
631
 
                   weaverepo.RepositoryFormat7()]
632
 
        incompatible_formats = [weaverepo.RepositoryFormat4(),
633
 
                                knitrepo.RepositoryFormatKnit1(),
634
 
                                ]
635
 
        repo_a = self.make_repository('a')
636
 
        repo_b = self.make_repository('b')
637
 
        is_compatible = weaverepo.InterWeaveRepo.is_compatible
638
 
        for source in incompatible_formats:
639
 
            # force incompatible left then right
640
 
            repo_a._format = source
641
 
            repo_b._format = formats[0]
642
 
            self.assertFalse(is_compatible(repo_a, repo_b))
643
 
            self.assertFalse(is_compatible(repo_b, repo_a))
644
 
        for source in formats:
645
 
            repo_a._format = source
646
 
            for target in formats:
647
 
                repo_b._format = target
648
 
                self.assertTrue(is_compatible(repo_a, repo_b))
649
 
        self.assertEqual(weaverepo.InterWeaveRepo,
650
 
                         repository.InterRepository.get(repo_a,
651
 
                                                        repo_b).__class__)
652
 
 
653
 
 
654
431
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
655
432
 
656
433
    def get_format_string(self):