~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_pack_repository.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
720
720
        self.assertEqual(self.format_supports_external_lookups,
721
721
            repo._format.supports_external_lookups)
722
722
 
 
723
    def _lock_write(self, write_lockable):
 
724
        """Lock write_lockable, add a cleanup and return the result.
 
725
        
 
726
        :param write_lockable: An object with a lock_write method.
 
727
        :return: The result of write_lockable.lock_write().
 
728
        """
 
729
        result = write_lockable.lock_write()
 
730
        self.addCleanup(result.unlock)
 
731
        return result
 
732
 
723
733
    def test_abort_write_group_does_not_raise_when_suppressed(self):
724
734
        """Similar to per_repository.test_write_group's test of the same name.
725
735
 
727
737
        """
728
738
        self.vfs_transport_factory = memory.MemoryServer
729
739
        repo = self.make_repository('repo', format=self.get_format())
730
 
        token = repo.lock_write()
731
 
        self.addCleanup(repo.unlock)
 
740
        token = self._lock_write(repo).repository_token
732
741
        repo.start_write_group()
733
742
        # Damage the repository on the filesystem
734
743
        self.get_transport('').rename('repo', 'foo')
744
753
    def test_abort_write_group_does_raise_when_not_suppressed(self):
745
754
        self.vfs_transport_factory = memory.MemoryServer
746
755
        repo = self.make_repository('repo', format=self.get_format())
747
 
        token = repo.lock_write()
748
 
        self.addCleanup(repo.unlock)
 
756
        token = self._lock_write(repo).repository_token
749
757
        repo.start_write_group()
750
758
        # Damage the repository on the filesystem
751
759
        self.get_transport('').rename('repo', 'foo')
757
765
    def test_suspend_write_group(self):
758
766
        self.vfs_transport_factory = memory.MemoryServer
759
767
        repo = self.make_repository('repo', format=self.get_format())
760
 
        token = repo.lock_write()
761
 
        self.addCleanup(repo.unlock)
 
768
        token = self._lock_write(repo).repository_token
762
769
        repo.start_write_group()
763
770
        repo.texts.add_lines(('file-id', 'revid'), (), ['lines'])
764
771
        wg_tokens = repo.suspend_write_group()
779
786
        repo = self.make_repository('repo', format=self.get_format())
780
787
        if repo.chk_bytes is None:
781
788
            raise TestNotApplicable('no chk_bytes for this repository')
782
 
        token = repo.lock_write()
783
 
        self.addCleanup(repo.unlock)
 
789
        token = self._lock_write(repo).repository_token
784
790
        repo.start_write_group()
785
791
        text = 'a bit of text\n'
786
792
        key = ('sha1:' + osutils.sha_string(text),)
801
807
        # Create a repo, start a write group, insert some data, suspend.
802
808
        self.vfs_transport_factory = memory.MemoryServer
803
809
        repo = self.make_repository('repo', format=self.get_format())
804
 
        token = repo.lock_write()
805
 
        self.addCleanup(repo.unlock)
 
810
        token = self._lock_write(repo).repository_token
806
811
        repo.start_write_group()
807
812
        text_key = ('file-id', 'revid')
808
813
        repo.texts.add_lines(text_key, (), ['lines'])
822
827
    def test_commit_resumed_write_group(self):
823
828
        self.vfs_transport_factory = memory.MemoryServer
824
829
        repo = self.make_repository('repo', format=self.get_format())
825
 
        token = repo.lock_write()
826
 
        self.addCleanup(repo.unlock)
 
830
        token = self._lock_write(repo).repository_token
827
831
        repo.start_write_group()
828
832
        text_key = ('file-id', 'revid')
829
833
        repo.texts.add_lines(text_key, (), ['lines'])
851
855
        self.vfs_transport_factory = memory.MemoryServer
852
856
        # Make a repository with a suspended write group
853
857
        repo = self.make_repository('repo', format=self.get_format())
854
 
        token = repo.lock_write()
855
 
        self.addCleanup(repo.unlock)
 
858
        token = self._lock_write(repo).repository_token
856
859
        repo.start_write_group()
857
860
        text_key = ('file-id', 'revid')
858
861
        repo.texts.add_lines(text_key, (), ['lines'])
859
862
        wg_tokens = repo.suspend_write_group()
860
863
        # Make a new repository
861
864
        new_repo = self.make_repository('new_repo', format=self.get_format())
862
 
        token = new_repo.lock_write()
863
 
        self.addCleanup(new_repo.unlock)
 
865
        token = self._lock_write(new_repo).repository_token
864
866
        hacked_wg_token = (
865
867
            '../../../../repo/.bzr/repository/upload/' + wg_tokens[0])
866
868
        self.assertRaises(