74
75
my_bzrdir = bzrdir.BzrDirMetaFormat1()
75
76
my_bzrdir.repository_format = SampleRepositoryFormat()
77
bzrdir.format_registry.remove('default')
78
bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
79
bzrdir.format_registry.set_default('sample')
78
controldir.format_registry.remove('default')
79
controldir.format_registry.register('sample', make_sample_bzrdir, '')
80
controldir.format_registry.set_default('sample')
80
81
# creating a repository should now create an instrumented dir.
82
83
# the default branch format is used by the meta dir format
85
86
result = dir.create_repository()
86
87
self.assertEqual(result, 'A bzr repository dir')
88
bzrdir.format_registry.remove('default')
89
bzrdir.format_registry.remove('sample')
90
bzrdir.format_registry.register('default', old_default, '')
89
controldir.format_registry.remove('default')
90
controldir.format_registry.remove('sample')
91
controldir.format_registry.register('default', old_default, '')
91
92
self.assertIsInstance(repository.format_registry.get_default(),
92
93
old_format.__class__)
95
class SampleRepositoryFormat(repository.RepositoryFormat):
96
class SampleRepositoryFormat(repository.RepositoryFormatMetaDir):
98
99
this format is initializable, unsupported to aid in testing the
99
100
open and open(unsupported=True) routines.
102
def get_format_string(self):
104
def get_format_string(cls):
103
105
"""See RepositoryFormat.get_format_string()."""
104
106
return "Sample .bzr repository format."
137
139
dir = format._matchingbzrdir.initialize(url)
138
140
format.initialize(dir)
139
141
t = transport.get_transport_from_path(url)
140
found_format = repository.RepositoryFormat.find_format(dir)
142
found_format = repository.RepositoryFormatMetaDir.find_format(dir)
141
143
self.assertIsInstance(found_format, format.__class__)
142
144
check_format(repository.format_registry.get_default(), "bar")
144
146
def test_find_format_no_repository(self):
145
147
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
146
148
self.assertRaises(errors.NoRepositoryPresent,
147
repository.RepositoryFormat.find_format,
149
repository.RepositoryFormatMetaDir.find_format,
152
def test_from_string(self):
153
self.assertIsInstance(
154
SampleRepositoryFormat.from_string(
155
"Sample .bzr repository format."),
156
SampleRepositoryFormat)
157
self.assertRaises(AssertionError,
158
SampleRepositoryFormat.from_string,
159
"Different .bzr repository format.")
150
161
def test_find_format_unknown_format(self):
151
162
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
163
SampleRepositoryFormat().initialize(dir)
153
164
self.assertRaises(UnknownFormatError,
154
repository.RepositoryFormat.find_format,
165
repository.RepositoryFormatMetaDir.find_format,
157
def test_register_unregister_format(self):
158
# Test deprecated format registration functions
159
format = SampleRepositoryFormat()
161
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
163
format.initialize(dir)
164
# register a format for it.
165
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
166
repository.RepositoryFormat.register_format, format)
167
# which repository.Open will refuse (not supported)
168
self.assertRaises(UnsupportedFormatError, repository.Repository.open,
170
# but open(unsupported) will work
171
self.assertEqual(format.open(dir), "opened repository.")
172
# unregister the format
173
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
174
repository.RepositoryFormat.unregister_format, format)
168
def test_find_format_with_features(self):
169
tree = self.make_branch_and_tree('.', format='2a')
170
tree.branch.repository.update_feature_flags({"name": "necessity"})
171
found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
172
self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
173
self.assertEquals(found_format.features.get("name"), "necessity")
174
self.assertRaises(errors.MissingFeature, found_format.check_support_status,
176
self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
178
repository.RepositoryFormatMetaDir.register_feature("name")
179
found_format.check_support_status(True)
177
182
class TestRepositoryFormatRegistry(TestCase):
213
218
def test_attribute__fetch_order(self):
214
219
"""Knits need topological data insertion."""
215
220
repo = self.make_repository('.',
216
format=bzrdir.format_registry.get('knit')())
221
format=controldir.format_registry.get('knit')())
217
222
self.assertEqual('topological', repo._format._fetch_order)
219
224
def test_attribute__fetch_uses_deltas(self):
220
225
"""Knits reuse deltas."""
221
226
repo = self.make_repository('.',
222
format=bzrdir.format_registry.get('knit')())
227
format=controldir.format_registry.get('knit')())
223
228
self.assertEqual(True, repo._format._fetch_uses_deltas)
225
230
def test_disk_layout(self):
319
324
def test_deserialise_uses_global_revision_id(self):
320
325
"""If it is set, then we re-use the global revision id"""
321
326
repo = self.make_repository('.',
322
format=bzrdir.format_registry.get('knit')())
327
format=controldir.format_registry.get('knit')())
323
328
inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
324
329
'</inventory>\n')
325
330
# Arguably, the deserialise_inventory should detect a mismatch, and
509
516
revision_tree = tree.branch.repository.revision_tree('dull')
510
517
revision_tree.lock_read()
512
revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
519
revision_tree.get_file_lines(revision_tree.get_root_id())
514
521
revision_tree.unlock()
515
522
tree.commit("Another dull commit", rev_id='dull2')
516
523
revision_tree = tree.branch.repository.revision_tree('dull2')
517
524
revision_tree.lock_read()
518
525
self.addCleanup(revision_tree.unlock)
519
self.assertEqual('dull', revision_tree.inventory.root.revision)
526
self.assertEqual('dull',
527
revision_tree.get_file_revision(revision_tree.get_root_id()))
521
529
def test_supports_external_lookups(self):
522
530
format = bzrdir.BzrDirMetaFormat1()
893
901
revision = _mod_revision.Revision('rev1a',
894
902
committer='jrandom@example.com', timestamp=0,
895
903
inventory_sha1='', timezone=0, message='foo', parent_ids=[])
896
repo.add_revision('rev1a',revision, inv)
904
repo.add_revision('rev1a', revision, inv)
898
906
# make rev1b, which has no Revision, but has an Inventory, and
934
942
revision = _mod_revision.Revision(revision_id,
935
943
committer='jrandom@example.com', timestamp=0, inventory_sha1='',
936
944
timezone=0, message='foo', parent_ids=parent_ids)
937
repo.add_revision(revision_id,revision, inv)
945
repo.add_revision(revision_id, revision, inv)
939
947
def add_file(self, repo, inv, filename, revision, parents):
940
948
file_id = filename + '-id'
1070
1078
sorted(set([osutils.splitext(n)[0] for n in
1071
1079
packs._index_transport.list_dir('.')])))
1081
def test__obsolete_packs_missing_directory(self):
1082
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1083
r.control_transport.rmdir('obsolete_packs')
1084
names = packs.names()
1085
pack = packs.get_pack_by_name(names[0])
1086
# Schedule this one for removal
1087
packs._remove_pack_from_memory(pack)
1088
# Now trigger the obsoletion, and ensure that all the remaining files
1090
packs._obsolete_packs([pack])
1091
self.assertEqual([n + '.pack' for n in names[1:]],
1092
sorted(packs._pack_transport.list_dir('.')))
1093
# names[0] should not be present in the index anymore
1094
self.assertEqual(names[1:],
1095
sorted(set([osutils.splitext(n)[0] for n in
1096
packs._index_transport.list_dir('.')])))
1073
1098
def test_pack_distribution_zero(self):
1074
1099
packs = self.get_packs()
1075
1100
self.assertEqual([0], packs.pack_distribution(0))
1345
1370
obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1346
1371
self.assertEqual([pack.name], sorted(obsolete_names))
1373
def test_pack_no_obsolete_packs_directory(self):
1374
"""Bug #314314, don't fail if obsolete_packs directory does
1376
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1377
r.control_transport.rmdir('obsolete_packs')
1378
packs._clear_obsolete_packs()
1350
1381
class TestPack(TestCaseWithTransport):
1668
1699
lazy = repository._LazyListJoin(['a'], ['b'])
1669
1700
self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",
1704
class TestFeatures(tests.TestCaseWithTransport):
1706
def test_open_with_present_feature(self):
1708
repository.RepositoryFormatMetaDir.unregister_feature,
1709
"makes-cheese-sandwich")
1710
repository.RepositoryFormatMetaDir.register_feature(
1711
"makes-cheese-sandwich")
1712
repo = self.make_repository('.')
1714
repo._format.features["makes-cheese-sandwich"] = "required"
1715
repo._format.check_support_status(False)
1718
def test_open_with_missing_required_feature(self):
1719
repo = self.make_repository('.')
1721
repo._format.features["makes-cheese-sandwich"] = "required"
1722
self.assertRaises(errors.MissingFeature,
1723
repo._format.check_support_status, False)