/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

Add RepositoryPackCollection.reload_pack_names()

This refactors the _save_pack_names code into helper functions, and
exposes a public member for outside entities to call to refresh the
list. It updates the internal names and also re-updates the various
indexes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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))
919
919
 
 
920
    def test_reload_pack_names_new_entry(self):
 
921
        tree = self.make_branch_and_tree('.')
 
922
        tree.lock_write()
 
923
        self.addCleanup(tree.unlock)
 
924
        rev1 = tree.commit('one')
 
925
        rev2 = tree.commit('two')
 
926
        r = repository.Repository.open('.')
 
927
        r.lock_read()
 
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]))
 
945
 
 
946
    def test_reload_pack_names_added_and_removed(self):
 
947
        tree = self.make_branch_and_tree('.')
 
948
        tree.lock_write()
 
949
        self.addCleanup(tree.unlock)
 
950
        rev1 = tree.commit('one')
 
951
        rev2 = tree.commit('two')
 
952
        r = repository.Repository.open('.')
 
953
        r.lock_read()
 
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]))
 
968
 
920
969
 
921
970
class TestPack(TestCaseWithTransport):
922
971
    """Tests for the Pack object."""