351
353
raise NotImplementedError(self.create_workingtree)
355
def retire_bzrdir(self):
356
"""Permanently disable the bzrdir.
358
This is done by renaming it to give the user some ability to recover
359
if there was a problem.
361
This will have horrible consequences if anyone has anything locked or
364
for i in xrange(10000):
366
to_path = '.bzr.retired.%d' % i
367
self.root_transport.rename('.bzr', to_path)
368
note("renamed %s to %s"
369
% (self.root_transport.abspath('.bzr'), to_path))
371
except (errors.TransportError, IOError, errors.PathError):
353
374
def destroy_workingtree(self):
354
375
"""Destroy the working tree at this BzrDir.
432
453
"""Get the transport for use by workingtree format in this BzrDir.
434
455
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.
456
IncompatibleFormat if the workingtree format they are given has a
457
format string, and vice versa.
438
459
If workingtree_format is None, the transport is returned with no
439
460
checking. if it is not None, then the returned transport is
625
646
except errors.NoWorkingTree:
628
def cloning_metadir(self, basis=None):
629
"""Produce a metadir suitable for cloning with"""
649
def _cloning_metadir(self, basis=None):
630
650
def related_repository(bzrdir):
632
652
branch = bzrdir.open_branch()
644
664
source_repository = related_repository(self)
645
665
result_format.repository_format = source_repository._format
646
666
except errors.NoRepositoryPresent:
650
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
667
source_repository = None
669
tree = self.open_workingtree()
670
except (errors.NoWorkingTree, errors.NotLocalUrl):
671
result_format.workingtree_format = None
673
result_format.workingtree_format = tree._format.__class__()
674
return result_format, source_repository
676
def cloning_metadir(self, basis=None):
677
"""Produce a metadir suitable for cloning or sprouting with.
679
These operations may produce workingtrees (yes, even though they're
680
"cloning" something that doesn't have a tree, so a viable workingtree
681
format must be selected.
683
format, repository = self._cloning_metadir()
684
if format._workingtree_format is None:
685
if repository is None:
687
tree_format = repository._format._matchingbzrdir.workingtree_format
688
format.workingtree_format = tree_format.__class__()
691
def checkout_metadir(self):
692
return self.cloning_metadir()
694
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False,
651
696
"""Create a copy of this bzrdir prepared for use as a new line of
710
755
# case that the newly sprouted branch is a remote one
711
756
if result_repo is None or result_repo.make_working_trees():
712
757
wt = result.create_workingtree()
713
if wt.inventory.root is None:
715
wt.set_root_id(self.open_workingtree.get_root_id())
716
except errors.NoWorkingTree:
760
if wt.path2id('') is None:
762
wt.set_root_id(self.open_workingtree.get_root_id())
763
except errors.NoWorkingTree:
769
if recurse == 'down':
771
basis = wt.basis_tree()
773
subtrees = basis.iter_references()
774
recurse_branch = wt.branch
775
elif source_branch is not None:
776
basis = source_branch.basis_tree()
778
subtrees = basis.iter_references()
779
recurse_branch = source_branch
784
for path, file_id in subtrees:
785
target = urlutils.join(url, urlutils.escape(path))
786
sublocation = source_branch.reference_parent(file_id, path)
787
sublocation.bzrdir.sprout(target,
788
basis.get_reference_revision(file_id, path),
789
force_new_repo=force_new_repo, recurse=recurse)
791
if basis is not None:
934
1009
def create_workingtree(self, revision_id=None):
935
1010
"""See BzrDir.create_workingtree."""
936
1011
from bzrlib.workingtree import WorkingTreeFormat
937
return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
1012
return self._format.workingtree_format.initialize(self, revision_id)
939
1014
def destroy_workingtree(self):
940
1015
"""See BzrDir.destroy_workingtree."""
1014
1089
if not isinstance(self.open_branch()._format,
1015
1090
format.get_branch_format().__class__):
1016
# the repository needs an upgrade.
1091
# the branch needs an upgrade.
1018
1093
except errors.NotBranchError:
1020
# currently there are no other possible conversions for meta1 formats.
1096
if not isinstance(self.open_workingtree()._format,
1097
format.workingtree_format.__class__):
1098
# the workingtree needs an upgrade.
1100
except (errors.NoWorkingTree, errors.NotLocalUrl):
1023
1104
def open_branch(self, unsupported=False):
1446
1527
_lock_class = lockdir.LockDir
1448
1529
def __init__(self):
1530
self._workingtree_format = None
1449
1531
self._branch_format = None
1533
def __eq__(self, other):
1534
if other.__class__ is not self.__class__:
1536
if other.repository_format != self.repository_format:
1538
if other.workingtree_format != self.workingtree_format:
1542
def __ne__(self, other):
1543
return not self == other
1451
1545
def get_branch_format(self):
1452
1546
if self._branch_format is None:
1453
1547
from bzrlib.branch import BranchFormat
1492
1586
repository_format = property(__return_repository_format, __set_repository_format)
1588
def __get_workingtree_format(self):
1589
if self._workingtree_format is None:
1590
from bzrlib.workingtree import WorkingTreeFormat
1591
self._workingtree_format = WorkingTreeFormat.get_default_format()
1592
return self._workingtree_format
1594
def __set_workingtree_format(self, wt_format):
1595
self._workingtree_format = wt_format
1597
workingtree_format = property(__get_workingtree_format,
1598
__set_workingtree_format)
1495
1601
BzrDirFormat.register_format(BzrDirFormat4())
1496
1602
BzrDirFormat.register_format(BzrDirFormat5())
2000
2108
_mod_branch.BzrBranchFormat6):
2001
2109
branch_converter = _mod_branch.Converter5to6()
2002
2110
branch_converter.convert(branch)
2112
tree = self.bzrdir.open_workingtree()
2113
except (errors.NoWorkingTree, errors.NotLocalUrl):
2116
# TODO: conversions of Branch and Tree should be done by
2117
# InterXFormat lookups
2118
if (isinstance(tree, workingtree.WorkingTree3) and
2119
not isinstance(tree, workingtree_4.WorkingTree4) and
2120
isinstance(self.target_format.workingtree_format,
2121
workingtree_4.WorkingTreeFormat4)):
2122
workingtree_4.Converter3to4().convert(tree)
2003
2123
return to_convert
2017
2137
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2020
def register_metadir(self, key, repo, help, native=True, deprecated=False,
2021
branch_format=None):
2140
def register_metadir(self, key,
2141
repository_format, help, native=True, deprecated=False,
2022
2144
"""Register a metadir subformat.
2024
2146
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2025
2147
by the Repository format.
2027
:param repo: The fully-qualified repository format class name as a
2149
:param repository_format: The fully-qualified repository format class
2151
:param branch_format: Fully-qualified branch format class name as
2153
:param tree_format: Fully-qualified tree format class name as
2030
2156
# This should be expanded to support setting WorkingTree and Branch
2031
2157
# formats, once BzrDirMetaFormat1 supports that.
2033
import bzrlib.branch
2034
mod_name, repo_factory_name = repo.rsplit('.', 1)
2158
def _load(full_name):
2159
mod_name, factory_name = full_name.rsplit('.', 1)
2036
2161
mod = __import__(mod_name, globals(), locals(),
2037
[repo_factory_name])
2038
2163
except ImportError, e:
2039
raise ImportError('failed to load repository %s: %s'
2164
raise ImportError('failed to load %s: %s' % (full_name, e))
2042
repo_format_class = getattr(mod, repo_factory_name)
2166
factory = getattr(mod, factory_name)
2043
2167
except AttributeError:
2044
raise AttributeError('no repository format %r in module %r'
2168
raise AttributeError('no factory %s in module %r'
2046
2173
bd = BzrDirMetaFormat1()
2047
bd.repository_format = repo_format_class()
2048
2174
if branch_format is not None:
2049
bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2175
bd.set_branch_format(_load(branch_format))
2176
if tree_format is not None:
2177
bd.workingtree_format = _load(tree_format)
2178
if repository_format is not None:
2179
bd.repository_format = _load(repository_format)
2051
2181
self.register(key, helper, help, native, deprecated)
2141
2271
deprecated=True)
2142
2272
format_registry.register_metadir('knit',
2143
2273
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2144
'Format using knits. Recommended.',
2145
branch_format='BzrBranchFormat5')
2146
format_registry.set_default('knit')
2274
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2275
branch_format='bzrlib.branch.BzrBranchFormat5',
2276
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2147
2277
format_registry.register_metadir('metaweave',
2148
2278
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2149
2279
'Transitional format in 0.8. Slower than knit.',
2152
format_registry.register_metadir('experimental-knit2',
2153
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
2154
'Experimental successor to knit. Use at your own risk.',
2155
branch_format='BzrBranchFormat5')
2156
format_registry.register_metadir('experimental-branch6',
2280
branch_format='bzrlib.branch.BzrBranchFormat5',
2281
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2283
format_registry.register_metadir('dirstate',
2157
2284
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2158
'Experimental successor to knit. Use at your own risk.',
2159
branch_format='BzrBranchFormat6')
2285
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2286
'above when accessed over the network.',
2287
branch_format='bzrlib.branch.BzrBranchFormat5',
2288
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2289
# directly from workingtree_4 triggers a circular import.
2290
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2292
format_registry.register_metadir('dirstate-with-subtree',
2293
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2294
help='New in 0.15: Fast local operations and improved scaling for '
2295
'network operations. Additionally adds support for versioning nested '
2296
'bzr branches. Incompatible with bzr < 0.15.',
2297
branch_format='bzrlib.branch.BzrBranchFormat6',
2298
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2300
format_registry.set_default('dirstate')