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."
136
137
def check_format(format, url):
137
138
dir = format._matchingbzrdir.initialize(url)
138
139
format.initialize(dir)
139
t = transport.get_transport(url)
140
found_format = repository.RepositoryFormat.find_format(dir)
140
t = transport.get_transport_from_path(url)
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(ValueError,
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,
157
167
def test_register_unregister_format(self):
439
449
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
441
def get_format_string(self):
452
def get_format_string(cls):
442
453
return "Test Format 1"
445
456
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
447
def get_format_string(self):
459
def get_format_string(cls):
448
460
return "Test Format 2"
707
719
# On a regular pass, getting the inventories and chk pages for rev-2
708
720
# would only get the newly created chk pages
709
search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
721
search = vf_search.SearchResult(set(['rev-2']), set(['rev-1']), 1,
711
723
simple_chk_records = []
712
724
for vf_name, substream in source.get_stream(search):
893
905
revision = _mod_revision.Revision('rev1a',
894
906
committer='jrandom@example.com', timestamp=0,
895
907
inventory_sha1='', timezone=0, message='foo', parent_ids=[])
896
repo.add_revision('rev1a',revision, inv)
908
repo.add_revision('rev1a', revision, inv)
898
910
# make rev1b, which has no Revision, but has an Inventory, and
934
946
revision = _mod_revision.Revision(revision_id,
935
947
committer='jrandom@example.com', timestamp=0, inventory_sha1='',
936
948
timezone=0, message='foo', parent_ids=parent_ids)
937
repo.add_revision(revision_id,revision, inv)
949
repo.add_revision(revision_id, revision, inv)
939
951
def add_file(self, repo, inv, filename, revision, parents):
940
952
file_id = filename + '-id'
1070
1082
sorted(set([osutils.splitext(n)[0] for n in
1071
1083
packs._index_transport.list_dir('.')])))
1085
def test__obsolete_packs_missing_directory(self):
1086
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1087
r.control_transport.rmdir('obsolete_packs')
1088
names = packs.names()
1089
pack = packs.get_pack_by_name(names[0])
1090
# Schedule this one for removal
1091
packs._remove_pack_from_memory(pack)
1092
# Now trigger the obsoletion, and ensure that all the remaining files
1094
packs._obsolete_packs([pack])
1095
self.assertEqual([n + '.pack' for n in names[1:]],
1096
sorted(packs._pack_transport.list_dir('.')))
1097
# names[0] should not be present in the index anymore
1098
self.assertEqual(names[1:],
1099
sorted(set([osutils.splitext(n)[0] for n in
1100
packs._index_transport.list_dir('.')])))
1073
1102
def test_pack_distribution_zero(self):
1074
1103
packs = self.get_packs()
1075
1104
self.assertEqual([0], packs.pack_distribution(0))
1345
1374
obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1346
1375
self.assertEqual([pack.name], sorted(obsolete_names))
1377
def test_pack_no_obsolete_packs_directory(self):
1378
"""Bug #314314, don't fail if obsolete_packs directory does
1380
tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1381
r.control_transport.rmdir('obsolete_packs')
1382
packs._clear_obsolete_packs()
1350
1385
class TestPack(TestCaseWithTransport):
1660
1695
def test_IDS_format_same_no(self):
1661
1696
# When the formats are the same, pack is not called.
1662
1697
self.run_fetch('2a', '2a', False)
1700
class Test_LazyListJoin(tests.TestCase):
1702
def test__repr__(self):
1703
lazy = repository._LazyListJoin(['a'], ['b'])
1704
self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",