46
from bzrlib.repofmt import knitrepo, weaverepo
48
49
class TestDefaultFormat(TestCase):
50
51
def test_get_set_default_format(self):
51
old_format = RepositoryFormat.get_default_format()
52
test_format = SampleRepositoryFormat()
53
RepositoryFormat.register_format(test_format)
52
old_default = bzrdir.format_registry.get('default')
53
private_default = old_default().repository_format.__class__
54
old_format = repository.RepositoryFormat.get_default_format()
55
self.assertTrue(isinstance(old_format, private_default))
56
def make_sample_bzrdir():
57
my_bzrdir = bzrdir.BzrDirMetaFormat1()
58
my_bzrdir.repository_format = SampleRepositoryFormat()
60
bzrdir.format_registry.remove('default')
61
bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
62
bzrdir.format_registry.set_default('sample')
63
# creating a repository should now create an instrumented dir.
55
self.applyDeprecated(symbol_versioning.zero_fourteen,
56
RepositoryFormat.set_default_format,
58
# creating a repository should now create an instrumented dir.
60
# the default branch format is used by the meta dir format
61
# which is not the default bzrdir format at this point
62
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
63
result = dir.create_repository()
64
self.assertEqual(result, 'A bzr repository dir')
66
self.applyDeprecated(symbol_versioning.zero_fourteen,
67
RepositoryFormat.set_default_format, old_format)
65
# the default branch format is used by the meta dir format
66
# which is not the default bzrdir format at this point
67
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
68
result = dir.create_repository()
69
self.assertEqual(result, 'A bzr repository dir')
69
RepositoryFormat.unregister_format(test_format)
70
self.assertEqual(old_format, RepositoryFormat.get_default_format())
71
bzrdir.format_registry.remove('default')
72
bzrdir.format_registry.register('default', old_default, '')
73
self.assertIsInstance(repository.RepositoryFormat.get_default_format(),
73
77
class SampleRepositoryFormat(repository.RepositoryFormat):
108
112
t = get_transport(url)
109
113
found_format = repository.RepositoryFormat.find_format(dir)
110
114
self.failUnless(isinstance(found_format, format.__class__))
111
check_format(repository.RepositoryFormat7(), "bar")
115
check_format(weaverepo.RepositoryFormat7(), "bar")
113
117
def test_find_format_no_repository(self):
114
118
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
144
148
def test_no_ancestry_weave(self):
145
149
control = bzrdir.BzrDirFormat6().initialize(self.get_url())
146
repo = repository.RepositoryFormat6().initialize(control)
150
repo = weaverepo.RepositoryFormat6().initialize(control)
147
151
# We no longer need to create the ancestry.weave file
148
152
# since it is *never* used.
149
153
self.assertRaises(NoSuchFile,
178
182
def test_shared_disk_layout(self):
179
183
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
180
repo = repository.RepositoryFormat7().initialize(control, shared=True)
184
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
182
186
# format 'Bazaar-NG Repository format 7'
183
187
# inventory.weave == empty_weave
200
204
def test_creates_lockdir(self):
201
205
"""Make sure it appears to be controlled by a LockDir existence"""
202
206
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
203
repo = repository.RepositoryFormat7().initialize(control, shared=True)
207
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
204
208
t = control.get_repository_transport(None)
205
209
# TODO: Should check there is a 'lock' toplevel directory,
206
210
# regardless of contents
216
220
"""repo format 7 actually locks on lockdir"""
217
221
base_url = self.get_url()
218
222
control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
219
repo = repository.RepositoryFormat7().initialize(control, shared=True)
223
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
220
224
t = control.get_repository_transport(None)
221
225
repo.lock_write()
231
235
def test_shared_no_tree_disk_layout(self):
232
236
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
233
repo = repository.RepositoryFormat7().initialize(control, shared=True)
237
repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
234
238
repo.set_make_working_trees(False)
236
240
# format 'Bazaar-NG Repository format 7'
293
297
def test_shared_disk_layout(self):
294
298
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
295
repo = repository.RepositoryFormatKnit1().initialize(control, shared=True)
299
repo = knitrepo.RepositoryFormatKnit1().initialize(control, shared=True)
297
301
# format 'Bazaar-NG Knit Repository Format 1'
298
302
# lock: is a directory
312
316
def test_shared_no_tree_disk_layout(self):
313
317
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
314
repo = repository.RepositoryFormatKnit1().initialize(control, shared=True)
318
repo = knitrepo.RepositoryFormatKnit1().initialize(control, shared=True)
315
319
repo.set_make_working_trees(False)
317
321
# format 'Bazaar-NG Knit Repository Format 1'
399
403
def test_is_compatible_and_registered(self):
400
404
# InterWeaveRepo is compatible when either side
401
405
# is a format 5/6/7 branch
402
formats = [repository.RepositoryFormat5(),
403
repository.RepositoryFormat6(),
404
repository.RepositoryFormat7()]
405
incompatible_formats = [repository.RepositoryFormat4(),
406
repository.RepositoryFormatKnit1(),
406
from bzrlib.repofmt import knitrepo, weaverepo
407
formats = [weaverepo.RepositoryFormat5(),
408
weaverepo.RepositoryFormat6(),
409
weaverepo.RepositoryFormat7()]
410
incompatible_formats = [weaverepo.RepositoryFormat4(),
411
knitrepo.RepositoryFormatKnit1(),
408
413
repo_a = self.make_repository('a')
409
414
repo_b = self.make_repository('b')
430
435
t = get_transport(self.get_url('.'))
431
436
t.mkdir('repository')
432
437
repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
433
repo = repository.RepositoryFormat7().initialize(repo_dir)
434
target_format = repository.RepositoryFormatKnit1()
438
repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
439
target_format = knitrepo.RepositoryFormatKnit1()
435
440
converter = repository.CopyConverter(target_format)
436
441
pb = bzrlib.ui.ui_factory.nested_progress_bar()
454
459
def test_convert(self):
455
460
"""Ensure the upgrade adds weaves for roots"""
456
461
format = bzrdir.BzrDirMetaFormat1()
457
format.repository_format = repository.RepositoryFormatKnit1()
462
format.repository_format = knitrepo.RepositoryFormatKnit1()
458
463
tree = self.make_branch_and_tree('.', format)
459
464
tree.commit("Dull commit", rev_id="dull")
460
465
revision_tree = tree.branch.repository.revision_tree('dull')
461
466
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
462
467
revision_tree.inventory.root.file_id)
463
468
format = bzrdir.BzrDirMetaFormat1()
464
format.repository_format = repository.RepositoryFormatKnit2()
469
format.repository_format = knitrepo.RepositoryFormatKnit2()
465
470
upgrade.Convert('.', format)
466
471
tree = workingtree.WorkingTree.open('.')
467
472
revision_tree = tree.branch.repository.revision_tree('dull')