926
926
def create_branch(self):
927
927
"""See BzrDir.create_branch."""
928
from bzrlib.branch import BranchFormat
929
return BranchFormat.get_default_format().initialize(self)
928
return self._format.get_branch_format().initialize(self)
931
930
def create_repository(self, shared=False):
932
931
"""See BzrDir.create_repository."""
1012
1011
except errors.NoRepositoryPresent:
1014
if not isinstance(self.open_branch()._format,
1015
format.get_branch_format().__class__):
1016
# the repository needs an upgrade.
1018
except errors.NotBranchError:
1014
1020
# currently there are no other possible conversions for meta1 formats.
1440
1446
_lock_class = lockdir.LockDir
1449
self._branch_format = None
1451
def get_branch_format(self):
1452
if self._branch_format is None:
1453
from bzrlib.branch import BranchFormat
1454
self._branch_format = BranchFormat.get_default_format()
1455
return self._branch_format
1457
def set_branch_format(self, format):
1458
self._branch_format = format
1442
1460
def get_converter(self, format=None):
1443
1461
"""See BzrDirFormat.get_converter()."""
1444
1462
if format is None:
1970
1988
self.pb.note('starting repository conversion')
1971
1989
converter = CopyConverter(self.target_format.repository_format)
1972
1990
converter.convert(repo, pb)
1992
branch = self.bzrdir.open_branch()
1993
except errors.NotBranchError:
1996
# Avoid circular imports
1997
from bzrlib import branch as _mod_branch
1998
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
1999
self.target_format.get_branch_format().__class__ is
2000
_mod_branch.BzrBranchFormat6):
2001
branch_converter = _mod_branch.Converter5to6()
2002
branch_converter.convert(branch)
1973
2003
return to_convert
1990
2020
def register_metadir(self, key, repo, help, native=True, deprecated=False,
1991
repo_module='bzrlib.repository'):
2021
branch_format=None):
1992
2022
"""Register a metadir subformat.
1994
2024
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
1995
2025
by the Repository format.
1997
:param repo: The repository format class name as a string.
1999
:param repo_module: The module from which the repository class
2000
should be lazily loaded. By default this is bzrlib.repository.
2027
:param repo: The fully-qualified repository format class name as a
2002
2030
# This should be expanded to support setting WorkingTree and Branch
2003
2031
# formats, once BzrDirMetaFormat1 supports that.
2005
mod = __import__(repo_module, globals(), locals(), [repo])
2007
repo_format_class = getattr(mod, repo)
2033
import bzrlib.branch
2034
mod_name, repo_factory_name = repo.rsplit('.', 1)
2036
mod = __import__(mod_name, globals(), locals(),
2037
[repo_factory_name])
2038
except ImportError, e:
2039
raise ImportError('failed to load repository %s: %s'
2042
repo_format_class = getattr(mod, repo_factory_name)
2008
2043
except AttributeError:
2009
2044
raise AttributeError('no repository format %r in module %r'
2011
2046
bd = BzrDirMetaFormat1()
2012
2047
bd.repository_format = repo_format_class()
2048
if branch_format is not None:
2049
bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2014
2051
self.register(key, helper, help, native, deprecated)
2103
2140
' support checkouts or shared repositories.',
2104
2141
deprecated=True)
2105
2142
format_registry.register_metadir('knit',
2106
'RepositoryFormatKnit1',
2143
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2107
2144
'Format using knits. Recommended.',
2108
repo_module='bzrlib.repofmt.knitrepo')
2145
branch_format='BzrBranchFormat5')
2109
2146
format_registry.set_default('knit')
2110
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
2147
format_registry.register_metadir('metaweave',
2148
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2111
2149
'Transitional format in 0.8. Slower than knit.',
2112
2150
deprecated=True,
2113
repo_module='bzrlib.repofmt.weaverepo')
2114
2152
format_registry.register_metadir('experimental-knit2',
2115
'RepositoryFormatKnit2',
2116
'Experimental successor to knit. Use at your own risk.',
2117
repo_module='bzrlib.repofmt.knitrepo')
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',
2157
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2158
'Experimental successor to knit. Use at your own risk.',
2159
branch_format='BzrBranchFormat6')