432
432
"""Get the transport for use by workingtree format in this BzrDir.
434
434
Note that bzr dirs that do not support format strings will raise
435
IncompatibleFormat if the workingtree format they are given has
436
a format string, and vice versa.
435
IncompatibleFormat if the workingtree format they are given has a
436
format string, and vice versa.
438
438
If workingtree_format is None, the transport is returned with no
439
439
checking. if it is not None, then the returned transport is
625
625
except errors.NoWorkingTree:
628
def cloning_metadir(self, basis=None):
629
"""Produce a metadir suitable for cloning with"""
628
def _cloning_metadir(self, basis=None):
630
629
def related_repository(bzrdir):
632
631
branch = bzrdir.open_branch()
644
643
source_repository = related_repository(self)
645
644
result_format.repository_format = source_repository._format
646
645
except errors.NoRepositoryPresent:
650
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
646
source_repository = None
648
tree = self.open_workingtree()
649
except (errors.NoWorkingTree, errors.NotLocalUrl):
650
result_format.workingtree_format = None
652
result_format.workingtree_format = tree._format.__class__()
653
return result_format, source_repository
655
def cloning_metadir(self, basis=None):
656
"""Produce a metadir suitable for cloning or sprouting with.
658
These operations may produce workingtrees (yes, even though they're
659
"cloning" something that doesn't have a tree, so a viable workingtree
660
format must be selected.
662
format, repository = self._cloning_metadir()
663
if format._workingtree_format is None:
664
if repository is None:
666
tree_format = repository._format._matchingbzrdir.workingtree_format
667
format.workingtree_format = tree_format.__class__()
670
def checkout_metadir(self):
671
return self.cloning_metadir()
673
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False,
651
675
"""Create a copy of this bzrdir prepared for use as a new line of
748
if recurse == 'down':
750
entries = wt.iter_reference_entries()
751
recurse_branch = wt.branch
752
elif source_branch is not None:
753
entries = source_branch.basis_tree().iter_reference_entries()
754
recurse_branch = source_branch
757
for path, entry in entries:
758
target = urlutils.join(url, urlutils.escape(path))
759
sublocation = source_branch.reference_parent(entry.file_id,
761
sublocation.bzrdir.sprout(target, entry.reference_revision,
762
force_new_repo=force_new_repo, recurse=recurse)
938
979
def create_workingtree(self, revision_id=None):
939
980
"""See BzrDir.create_workingtree."""
940
981
from bzrlib.workingtree import WorkingTreeFormat
941
return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
982
return self._format.workingtree_format.initialize(self, revision_id)
943
984
def destroy_workingtree(self):
944
985
"""See BzrDir.destroy_workingtree."""
1450
1491
_lock_class = lockdir.LockDir
1452
1493
def __init__(self):
1494
self._workingtree_format = None
1453
1495
self._branch_format = None
1497
def __eq__(self, other):
1498
if other.__class__ is not self.__class__:
1500
if other.repository_format != self.repository_format:
1502
if other.workingtree_format != self.workingtree_format:
1506
def __ne__(self, other):
1507
return not self == other
1455
1509
def get_branch_format(self):
1456
1510
if self._branch_format is None:
1457
1511
from bzrlib.branch import BranchFormat
1496
1550
repository_format = property(__return_repository_format, __set_repository_format)
1552
def __get_workingtree_format(self):
1553
if self._workingtree_format is None:
1554
from bzrlib.workingtree import WorkingTreeFormat
1555
self._workingtree_format = WorkingTreeFormat.get_default_format()
1556
return self._workingtree_format
1558
def __set_workingtree_format(self, wt_format):
1559
self._workingtree_format = wt_format
1561
workingtree_format = property(__get_workingtree_format,
1562
__set_workingtree_format)
1499
1565
BzrDirFormat.register_format(BzrDirFormat4())
1500
1566
BzrDirFormat.register_format(BzrDirFormat5())
2024
2090
def register_metadir(self, key, repo, help, native=True, deprecated=False,
2025
branch_format=None):
2091
branch_format=None, tree='WorkingTreeFormat3'):
2026
2092
"""Register a metadir subformat.
2028
2094
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2035
2101
# formats, once BzrDirMetaFormat1 supports that.
2037
2103
import bzrlib.branch
2104
import bzrlib.repository
2105
import bzrlib.workingtree
2106
tree_format = getattr(bzrlib.workingtree, tree)
2038
2107
mod_name, repo_factory_name = repo.rsplit('.', 1)
2040
2109
mod = __import__(mod_name, globals(), locals(),
2048
2117
raise AttributeError('no repository format %r in module %r'
2050
2119
bd = BzrDirMetaFormat1()
2120
bd.workingtree_format = tree_format()
2051
2121
bd.repository_format = repo_format_class()
2052
2122
if branch_format is not None:
2053
2123
bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2151
2221
format_registry.register_metadir('metaweave',
2152
2222
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2153
2223
'Transitional format in 0.8. Slower than knit.',
2156
2225
format_registry.register_metadir('experimental-knit2',
2157
2226
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
2158
2227
'Experimental successor to knit. Use at your own risk.',
2159
branch_format='BzrBranchFormat5')
2228
branch_format='BzrBranchFormat5',
2229
tree='WorkingTreeFormat3'
2231
format_registry.register_metadir('experimental-knit3',
2232
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2233
'Experimental successor to knit2. Use at your own risk.',
2234
branch_format='BzrBranchFormat5',
2235
tree='WorkingTreeFormatAB1')
2160
2236
format_registry.register_metadir('experimental-branch6',
2161
2237
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2162
2238
'Experimental successor to knit. Use at your own risk.',
2163
branch_format='BzrBranchFormat6')
2239
branch_format='BzrBranchFormat6',
2240
tree='WorkingTreeFormat3')