231
232
def is_locked(self):
232
233
return self.control_files.is_locked()
234
def lock_write(self):
235
self.control_files.lock_write()
235
def lock_write(self, token=None):
236
"""Lock this repository for writing.
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.
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
250
XXX: this docstring is duplicated in many places, e.g. lockable_files.py
252
return self.control_files.lock_write(token=token)
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()
260
def leave_lock_in_place(self):
261
"""Tell this repository not to release the physical lock when this
264
If lock_write doesn't return a token, then this method is not supported.
266
self.control_files.leave_in_place()
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.
272
If lock_write doesn't return a token, then this method is not supported.
274
self.control_files.dont_leave_in_place()
244
277
def gather_stats(self, revid=None, committers=None):
245
278
"""Gather statistics from a revision id.
363
396
:return: The newly created destination repository.
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)
405
def sprout(self, to_bzrdir, revision_id=None):
406
"""Create a descendent repository for new development.
408
Unlike clone, this does not copy the settings of the repository.
410
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
411
dest_repo.fetch(self, revision_id=revision_id)
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
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)
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.
1230
:returns: The new repository object.
1182
1232
This may raise UninitializableFormat if shared repository are not
1183
1233
compatible the a_bzrdir.
1235
raise NotImplementedError(self.initialize)
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.
1405
This copies both the repository's revision data, and configuration information
1406
such as the make_working_trees setting.
1354
1408
This is a destructive operation! Do not use it on existing
1655
1709
return f.count_copied, f.failed_revisions
1712
class InterRemoteRepository(InterRepository):
1713
"""Code for converting between RemoteRepository objects.
1715
This just gets an non-remote repository from the RemoteRepository, and calls
1716
InterRepository.get again.
1719
def __init__(self, source, target):
1720
if isinstance(source, remote.RemoteRepository):
1721
source._ensure_real()
1722
real_source = source._real_repository
1724
real_source = source
1725
if isinstance(target, remote.RemoteRepository):
1726
target._ensure_real()
1727
real_target = target._real_repository
1729
real_target = target
1730
self.real_inter = InterRepository.get(real_source, real_target)
1733
def is_compatible(source, target):
1734
if isinstance(source, remote.RemoteRepository):
1736
if isinstance(target, remote.RemoteRepository):
1740
def copy_content(self, revision_id=None):
1741
self.real_inter.copy_content(revision_id=revision_id)
1743
def fetch(self, revision_id=None, pb=None):
1744
self.real_inter.fetch(revision_id=revision_id, pb=pb)
1747
def _get_repo_format_to_test(self):
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)
1665
1759
class RepositoryTestProviderAdapter(object):
1671
1765
to make it easy to identify.
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
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():