917
917
# and the same instance should be returned on successive calls.
918
918
self.assertTrue(pack_1 is packs.get_pack_by_name(name))
920
def test_reload_pack_names_new_entry(self):
921
tree = self.make_branch_and_tree('.')
923
self.addCleanup(tree.unlock)
924
rev1 = tree.commit('one')
925
rev2 = tree.commit('two')
926
r = repository.Repository.open('.')
928
self.addCleanup(r.unlock)
929
packs = r._pack_collection
930
packs.ensure_loaded()
931
names = packs.names()
932
# Add a new pack file into the repository
933
rev3 = tree.commit('three')
934
new_names = tree.branch.repository._pack_collection.names()
935
new_name = set(new_names).difference(names)
936
self.assertEqual(1, len(new_name))
937
new_name = new_name.pop()
938
# The old collection hasn't noticed yet
939
self.assertEqual(names, packs.names())
940
# [removed], [added], [modified]
941
self.assertEqual(([], [new_name], []), packs.reload_pack_names())
942
self.assertEqual(new_names, packs.names())
943
# And the repository can access the new revision
944
self.assertEqual({rev3:(rev2,)}, r.get_parent_map([rev3]))
946
def test_reload_pack_names_added_and_removed(self):
947
tree = self.make_branch_and_tree('.')
949
self.addCleanup(tree.unlock)
950
rev1 = tree.commit('one')
951
rev2 = tree.commit('two')
952
r = repository.Repository.open('.')
954
self.addCleanup(r.unlock)
955
packs = r._pack_collection
956
packs.ensure_loaded()
957
names = packs.names()
958
# Now repack the whole thing
959
tree.branch.repository.pack()
960
new_names = tree.branch.repository._pack_collection.names()
961
# The other collection hasn't noticed yet
962
self.assertEqual(names, packs.names())
963
removed, added, modified = packs.reload_pack_names()
964
self.assertEqual(new_names, packs.names())
965
self.assertEqual((names, new_names, []),
966
(sorted(removed), sorted(added), sorted(modified)))
967
self.assertEqual({rev2:(rev1,)}, r.get_parent_map([rev2]))
921
970
class TestPack(TestCaseWithTransport):
922
971
"""Tests for the Pack object."""