2094
1928
self.pb.note('starting repository conversion')
2095
1929
converter = CopyConverter(self.target_format.repository_format)
2096
1930
converter.convert(repo, pb)
2098
branch = self.bzrdir.open_branch()
2099
except errors.NotBranchError:
2102
# TODO: conversions of Branch and Tree should be done by
2103
# InterXFormat lookups
2104
# Avoid circular imports
2105
from bzrlib import branch as _mod_branch
2106
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2107
self.target_format.get_branch_format().__class__ is
2108
_mod_branch.BzrBranchFormat6):
2109
branch_converter = _mod_branch.Converter5to6()
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)
2123
1931
return to_convert
2126
class BzrDirFormatInfo(object):
2128
def __init__(self, native, deprecated):
2129
self.deprecated = deprecated
2130
self.native = native
2133
class BzrDirFormatRegistry(registry.Registry):
2134
"""Registry of user-selectable BzrDir subformats.
2136
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2137
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2140
def register_metadir(self, key,
2141
repository_format, help, native=True, deprecated=False,
2144
"""Register a metadir subformat.
2146
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2147
by the Repository format.
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
2156
# This should be expanded to support setting WorkingTree and Branch
2157
# formats, once BzrDirMetaFormat1 supports that.
2158
def _load(full_name):
2159
mod_name, factory_name = full_name.rsplit('.', 1)
2161
mod = __import__(mod_name, globals(), locals(),
2163
except ImportError, e:
2164
raise ImportError('failed to load %s: %s' % (full_name, e))
2166
factory = getattr(mod, factory_name)
2167
except AttributeError:
2168
raise AttributeError('no factory %s in module %r'
2173
bd = BzrDirMetaFormat1()
2174
if branch_format is not None:
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)
2181
self.register(key, helper, help, native, deprecated)
2183
def register(self, key, factory, help, native=True, deprecated=False):
2184
"""Register a BzrDirFormat factory.
2186
The factory must be a callable that takes one parameter: the key.
2187
It must produce an instance of the BzrDirFormat when called.
2189
This function mainly exists to prevent the info object from being
2192
registry.Registry.register(self, key, factory, help,
2193
BzrDirFormatInfo(native, deprecated))
2195
def register_lazy(self, key, module_name, member_name, help, native=True,
2197
registry.Registry.register_lazy(self, key, module_name, member_name,
2198
help, BzrDirFormatInfo(native, deprecated))
2200
def set_default(self, key):
2201
"""Set the 'default' key to be a clone of the supplied key.
2203
This method must be called once and only once.
2205
registry.Registry.register(self, 'default', self.get(key),
2206
self.get_help(key), info=self.get_info(key))
2208
def set_default_repository(self, key):
2209
"""Set the FormatRegistry default and Repository default.
2211
This is a transitional method while Repository.set_default_format
2214
if 'default' in self:
2215
self.remove('default')
2216
self.set_default(key)
2217
format = self.get('default')()
2218
assert isinstance(format, BzrDirMetaFormat1)
2220
def make_bzrdir(self, key):
2221
return self.get(key)()
2223
def help_topic(self, topic):
2224
output = textwrap.dedent("""\
2225
Bazaar directory formats
2226
------------------------
2228
These formats can be used for creating branches, working trees, and
2232
default_help = self.get_help('default')
2234
for key in self.keys():
2235
if key == 'default':
2237
help = self.get_help(key)
2238
if help == default_help:
2239
default_realkey = key
2241
help_pairs.append((key, help))
2243
def wrapped(key, help, info):
2245
help = '(native) ' + help
2246
return ' %s:\n%s\n\n' % (key,
2247
textwrap.fill(help, initial_indent=' ',
2248
subsequent_indent=' '))
2249
output += wrapped('%s/default' % default_realkey, default_help,
2250
self.get_info('default'))
2251
deprecated_pairs = []
2252
for key, help in help_pairs:
2253
info = self.get_info(key)
2255
deprecated_pairs.append((key, help))
2257
output += wrapped(key, help, info)
2258
if len(deprecated_pairs) > 0:
2259
output += "Deprecated formats\n------------------\n\n"
2260
for key, help in deprecated_pairs:
2261
info = self.get_info(key)
2262
output += wrapped(key, help, info)
2267
format_registry = BzrDirFormatRegistry()
2268
format_registry.register('weave', BzrDirFormat6,
2269
'Pre-0.8 format. Slower than knit and does not'
2270
' support checkouts or shared repositories.',
2272
format_registry.register_metadir('knit',
2273
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2274
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2275
branch_format='bzrlib.branch.BzrBranchFormat5',
2276
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2277
format_registry.register_metadir('metaweave',
2278
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2279
'Transitional format in 0.8. Slower than knit.',
2280
branch_format='bzrlib.branch.BzrBranchFormat5',
2281
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2283
format_registry.register_metadir('dirstate',
2284
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
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')