92
92
old_format.__class__)
95
class SampleRepositoryFormat(repository.RepositoryFormat):
95
class SampleRepositoryFormat(repository.RepositoryFormatMetaDir):
98
98
this format is initializable, unsupported to aid in testing the
99
99
open and open(unsupported=True) routines.
102
def get_format_string(self):
103
def get_format_string(cls):
103
104
"""See RepositoryFormat.get_format_string()."""
104
105
return "Sample .bzr repository format."
137
138
dir = format._matchingbzrdir.initialize(url)
138
139
format.initialize(dir)
139
140
t = transport.get_transport_from_path(url)
140
found_format = repository.RepositoryFormat.find_format(dir)
141
found_format = repository.RepositoryFormatMetaDir.find_format(dir)
141
142
self.assertIsInstance(found_format, format.__class__)
142
143
check_format(repository.format_registry.get_default(), "bar")
144
145
def test_find_format_no_repository(self):
145
146
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
146
147
self.assertRaises(errors.NoRepositoryPresent,
147
repository.RepositoryFormat.find_format,
148
repository.RepositoryFormatMetaDir.find_format,
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.")
150
160
def test_find_format_unknown_format(self):
151
161
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
162
SampleRepositoryFormat().initialize(dir)
153
163
self.assertRaises(UnknownFormatError,
154
repository.RepositoryFormat.find_format,
164
repository.RepositoryFormatMetaDir.find_format,
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.assertEquals(found_format.features.get("name"), "necessity")
173
self.assertRaises(errors.MissingFeature, found_format.check_support_status,
175
self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
177
repository.RepositoryFormatMetaDir.register_feature("name")
178
found_format.check_support_status(True)
157
180
def test_register_unregister_format(self):
158
181
# Test deprecated format registration functions
159
182
format = SampleRepositoryFormat()
439
462
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
441
def get_format_string(self):
465
def get_format_string(cls):
442
466
return "Test Format 1"
445
469
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
447
def get_format_string(self):
472
def get_format_string(cls):
448
473
return "Test Format 2"
707
732
# On a regular pass, getting the inventories and chk pages for rev-2
708
733
# would only get the newly created chk pages
709
search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
734
search = vf_search.SearchResult(set(['rev-2']), set(['rev-1']), 1,
711
736
simple_chk_records = []
712
737
for vf_name, substream in source.get_stream(search):
893
918
revision = _mod_revision.Revision('rev1a',
894
919
committer='jrandom@example.com', timestamp=0,
895
920
inventory_sha1='', timezone=0, message='foo', parent_ids=[])
896
repo.add_revision('rev1a',revision, inv)
921
repo.add_revision('rev1a', revision, inv)
898
923
# make rev1b, which has no Revision, but has an Inventory, and
934
959
revision = _mod_revision.Revision(revision_id,
935
960
committer='jrandom@example.com', timestamp=0, inventory_sha1='',
936
961
timezone=0, message='foo', parent_ids=parent_ids)
937
repo.add_revision(revision_id,revision, inv)
962
repo.add_revision(revision_id, revision, inv)
939
964
def add_file(self, repo, inv, filename, revision, parents):
940
965
file_id = filename + '-id'
1070
1095
sorted(set([osutils.splitext(n)[0] for n in
1071
1096
packs._index_transport.list_dir('.')])))
1098
def test__obsolete_packs_missing_directory(self):
1099
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1100
r.control_transport.rmdir('obsolete_packs')
1101
names = packs.names()
1102
pack = packs.get_pack_by_name(names[0])
1103
# Schedule this one for removal
1104
packs._remove_pack_from_memory(pack)
1105
# Now trigger the obsoletion, and ensure that all the remaining files
1107
packs._obsolete_packs([pack])
1108
self.assertEqual([n + '.pack' for n in names[1:]],
1109
sorted(packs._pack_transport.list_dir('.')))
1110
# names[0] should not be present in the index anymore
1111
self.assertEqual(names[1:],
1112
sorted(set([osutils.splitext(n)[0] for n in
1113
packs._index_transport.list_dir('.')])))
1073
1115
def test_pack_distribution_zero(self):
1074
1116
packs = self.get_packs()
1075
1117
self.assertEqual([0], packs.pack_distribution(0))
1345
1387
obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1346
1388
self.assertEqual([pack.name], sorted(obsolete_names))
1390
def test_pack_no_obsolete_packs_directory(self):
1391
"""Bug #314314, don't fail if obsolete_packs directory does
1393
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1394
r.control_transport.rmdir('obsolete_packs')
1395
packs._clear_obsolete_packs()
1350
1398
class TestPack(TestCaseWithTransport):
1668
1716
lazy = repository._LazyListJoin(['a'], ['b'])
1669
1717
self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",
1721
class TestFeatures(tests.TestCaseWithTransport):
1723
def test_open_with_present_feature(self):
1725
repository.RepositoryFormatMetaDir.unregister_feature,
1726
"makes-cheese-sandwich")
1727
repository.RepositoryFormatMetaDir.register_feature(
1728
"makes-cheese-sandwich")
1729
repo = self.make_repository('.')
1731
repo._format.features["makes-cheese-sandwich"] = "required"
1732
repo._format.check_support_status(False)
1735
def test_open_with_missing_required_feature(self):
1736
repo = self.make_repository('.')
1738
repo._format.features["makes-cheese-sandwich"] = "required"
1739
self.assertRaises(errors.MissingFeature,
1740
repo._format.check_support_status, False)