~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    lockdir,
35
35
    osutils,
36
36
    registry,
 
37
    remote,
37
38
    revision as _mod_revision,
38
39
    symbol_versioning,
39
40
    transactions,
231
232
    def is_locked(self):
232
233
        return self.control_files.is_locked()
233
234
 
234
 
    def lock_write(self):
235
 
        self.control_files.lock_write()
 
235
    def lock_write(self, token=None):
 
236
        """Lock this repository for writing.
 
237
        
 
238
        :param token: if this is already locked, then lock_write will fail
 
239
            unless the token matches the existing lock.
 
240
        :returns: a token if this instance supports tokens, otherwise None.
 
241
        :raises TokenLockingNotSupported: when a token is given but this
 
242
            instance doesn't support using token locks.
 
243
        :raises MismatchedToken: if the specified token doesn't match the token
 
244
            of the existing lock.
 
245
 
 
246
        A token should be passed in if you know that you have locked the object
 
247
        some other way, and need to synchronise this object's state with that
 
248
        fact.
 
249
 
 
250
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
 
251
        """
 
252
        return self.control_files.lock_write(token=token)
236
253
 
237
254
    def lock_read(self):
238
255
        self.control_files.lock_read()
240
257
    def get_physical_lock_status(self):
241
258
        return self.control_files.get_physical_lock_status()
242
259
 
 
260
    def leave_lock_in_place(self):
 
261
        """Tell this repository not to release the physical lock when this
 
262
        object is unlocked.
 
263
        
 
264
        If lock_write doesn't return a token, then this method is not supported.
 
265
        """
 
266
        self.control_files.leave_in_place()
 
267
 
 
268
    def dont_leave_lock_in_place(self):
 
269
        """Tell this repository to release the physical lock when this
 
270
        object is unlocked, even if it didn't originally acquire it.
 
271
 
 
272
        If lock_write doesn't return a token, then this method is not supported.
 
273
        """
 
274
        self.control_files.dont_leave_in_place()
 
275
 
243
276
    @needs_read_lock
244
277
    def gather_stats(self, revid=None, committers=None):
245
278
        """Gather statistics from a revision id.
362
395
 
363
396
        :return: The newly created destination repository.
364
397
        """
 
398
        # TODO: deprecate after 0.16; cloning this with all its settings is
 
399
        # probably not very useful -- mbp 20070423
 
400
        dest_repo = self._create_sprouting_repo(a_bzrdir, shared=self.is_shared())
 
401
        self.copy_content_into(dest_repo, revision_id)
 
402
        return dest_repo
 
403
 
 
404
    @needs_read_lock
 
405
    def sprout(self, to_bzrdir, revision_id=None):
 
406
        """Create a descendent repository for new development.
 
407
 
 
408
        Unlike clone, this does not copy the settings of the repository.
 
409
        """
 
410
        dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
 
411
        dest_repo.fetch(self, revision_id=revision_id)
 
412
        return dest_repo
 
413
 
 
414
    def _create_sprouting_repo(self, a_bzrdir, shared):
365
415
        if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
366
416
            # use target default format.
367
417
            dest_repo = a_bzrdir.create_repository()
369
419
            # Most control formats need the repository to be specifically
370
420
            # created, but on some old all-in-one formats it's not needed
371
421
            try:
372
 
                dest_repo = self._format.initialize(a_bzrdir, shared=self.is_shared())
 
422
                dest_repo = self._format.initialize(a_bzrdir, shared=shared)
373
423
            except errors.UninitializableFormat:
374
424
                dest_repo = a_bzrdir.open_repository()
375
 
        self.copy_content_into(dest_repo, revision_id)
376
425
        return dest_repo
377
426
 
378
427
    @needs_read_lock
739
788
        reconciler = RepoReconciler(self, thorough=thorough)
740
789
        reconciler.reconcile()
741
790
        return reconciler
742
 
    
 
791
 
743
792
    @needs_read_lock
744
793
    def revision_tree(self, revision_id):
745
794
        """Return Tree for a revision on this branch.
1178
1227
 
1179
1228
        :param a_bzrdir: The bzrdir to put the new repository in it.
1180
1229
        :param shared: The repository should be initialized as a sharable one.
1181
 
 
 
1230
        :returns: The new repository object.
 
1231
        
1182
1232
        This may raise UninitializableFormat if shared repository are not
1183
1233
        compatible the a_bzrdir.
1184
1234
        """
 
1235
        raise NotImplementedError(self.initialize)
1185
1236
 
1186
1237
    def is_supported(self):
1187
1238
        """Is this format supported?
1350
1401
    @needs_write_lock
1351
1402
    def copy_content(self, revision_id=None):
1352
1403
        """Make a complete copy of the content in self into destination.
 
1404
 
 
1405
        This copies both the repository's revision data, and configuration information
 
1406
        such as the make_working_trees setting.
1353
1407
        
1354
1408
        This is a destructive operation! Do not use it on existing 
1355
1409
        repositories.
1655
1709
        return f.count_copied, f.failed_revisions
1656
1710
 
1657
1711
 
 
1712
class InterRemoteRepository(InterRepository):
 
1713
    """Code for converting between RemoteRepository objects.
 
1714
 
 
1715
    This just gets an non-remote repository from the RemoteRepository, and calls
 
1716
    InterRepository.get again.
 
1717
    """
 
1718
 
 
1719
    def __init__(self, source, target):
 
1720
        if isinstance(source, remote.RemoteRepository):
 
1721
            source._ensure_real()
 
1722
            real_source = source._real_repository
 
1723
        else:
 
1724
            real_source = source
 
1725
        if isinstance(target, remote.RemoteRepository):
 
1726
            target._ensure_real()
 
1727
            real_target = target._real_repository
 
1728
        else:
 
1729
            real_target = target
 
1730
        self.real_inter = InterRepository.get(real_source, real_target)
 
1731
 
 
1732
    @staticmethod
 
1733
    def is_compatible(source, target):
 
1734
        if isinstance(source, remote.RemoteRepository):
 
1735
            return True
 
1736
        if isinstance(target, remote.RemoteRepository):
 
1737
            return True
 
1738
        return False
 
1739
 
 
1740
    def copy_content(self, revision_id=None):
 
1741
        self.real_inter.copy_content(revision_id=revision_id)
 
1742
 
 
1743
    def fetch(self, revision_id=None, pb=None):
 
1744
        self.real_inter.fetch(revision_id=revision_id, pb=pb)
 
1745
 
 
1746
    @classmethod
 
1747
    def _get_repo_format_to_test(self):
 
1748
        return None
 
1749
 
 
1750
 
1658
1751
InterRepository.register_optimiser(InterSameDataRepository)
1659
1752
InterRepository.register_optimiser(InterWeaveRepo)
1660
1753
InterRepository.register_optimiser(InterKnitRepo)
1661
1754
InterRepository.register_optimiser(InterModel1and2)
1662
1755
InterRepository.register_optimiser(InterKnit1and2)
 
1756
InterRepository.register_optimiser(InterRemoteRepository)
1663
1757
 
1664
1758
 
1665
1759
class RepositoryTestProviderAdapter(object):
1671
1765
    to make it easy to identify.
1672
1766
    """
1673
1767
 
1674
 
    def __init__(self, transport_server, transport_readonly_server, formats):
 
1768
    def __init__(self, transport_server, transport_readonly_server, formats,
 
1769
                 vfs_transport_factory=None):
1675
1770
        self._transport_server = transport_server
1676
1771
        self._transport_readonly_server = transport_readonly_server
 
1772
        self._vfs_transport_factory = vfs_transport_factory
1677
1773
        self._formats = formats
1678
1774
    
1679
1775
    def adapt(self, test):
1683
1779
            new_test = deepcopy(test)
1684
1780
            new_test.transport_server = self._transport_server
1685
1781
            new_test.transport_readonly_server = self._transport_readonly_server
 
1782
            # Only override the test's vfs_transport_factory if one was
 
1783
            # specified, otherwise just leave the default in place.
 
1784
            if self._vfs_transport_factory:
 
1785
                new_test.vfs_transport_factory = self._vfs_transport_factory
1686
1786
            new_test.bzrdir_format = bzrdir_format
1687
1787
            new_test.repository_format = repository_format
1688
1788
            def make_new_test_id():