116
99
source_repo_format.check_conversion_target(target_repo_format)
119
def _check_supported(format, allow_unsupported,
120
recommend_upgrade=True,
122
"""Give an error or warning on old formats.
124
:param format: may be any kind of format - workingtree, branch,
127
:param allow_unsupported: If true, allow opening
128
formats that are strongly deprecated, and which may
129
have limited functionality.
131
:param recommend_upgrade: If true (default), warn
132
the user through the ui object that they may wish
133
to upgrade the object.
102
def _check_supported(format, allow_unsupported):
103
"""Check whether format is a supported format.
105
If allow_unsupported is True, this is a no-op.
135
# TODO: perhaps move this into a base Format class; it's not BzrDir
136
# specific. mbp 20070323
137
107
if not allow_unsupported and not format.is_supported():
138
108
# see open_downlevel to open legacy branches.
139
109
raise errors.UnsupportedFormatError(format=format)
140
if recommend_upgrade \
141
and getattr(format, 'upgrade_recommended', False):
142
ui.ui_factory.recommend_upgrade(
143
format.get_format_description(),
146
def clone(self, url, revision_id=None, force_new_repo=False):
111
def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
147
112
"""Clone this bzrdir and its contents to url verbatim.
149
114
If urls last component does not exist, it will be created.
667
576
workingtree and discards it, and that's somewhat expensive.)
670
self.open_workingtree(recommend_upgrade=False)
579
self.open_workingtree()
672
581
except errors.NoWorkingTree:
675
def _cloning_metadir(self):
584
def cloning_metadir(self, basis=None):
585
"""Produce a metadir suitable for cloning with"""
586
def related_repository(bzrdir):
588
branch = bzrdir.open_branch()
589
return branch.repository
590
except errors.NotBranchError:
592
return bzrdir.open_repository()
676
593
result_format = self._format.__class__()
679
branch = self.open_branch()
680
source_repository = branch.repository
681
except errors.NotBranchError:
683
source_repository = self.open_repository()
596
source_repository = related_repository(self)
597
except errors.NoRepositoryPresent:
600
source_repository = related_repository(self)
684
601
result_format.repository_format = source_repository._format
685
602
except errors.NoRepositoryPresent:
686
source_repository = None
688
# TODO: Couldn't we just probe for the format in these cases,
689
# rather than opening the whole tree? It would be a little
690
# faster. mbp 20070401
691
tree = self.open_workingtree(recommend_upgrade=False)
692
except (errors.NoWorkingTree, errors.NotLocalUrl):
693
result_format.workingtree_format = None
695
result_format.workingtree_format = tree._format.__class__()
696
return result_format, source_repository
698
def cloning_metadir(self):
699
"""Produce a metadir suitable for cloning or sprouting with.
701
These operations may produce workingtrees (yes, even though they're
702
"cloning" something that doesn't have a tree, so a viable workingtree
703
format must be selected.
705
format, repository = self._cloning_metadir()
706
if format._workingtree_format is None:
707
if repository is None:
709
tree_format = repository._format._matchingbzrdir.workingtree_format
710
format.workingtree_format = tree_format.__class__()
713
def checkout_metadir(self):
714
return self.cloning_metadir()
716
def sprout(self, url, revision_id=None, force_new_repo=False,
606
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
718
607
"""Create a copy of this bzrdir prepared for use as a new line of
2120
1884
self.pb.note('starting repository conversion')
2121
1885
converter = CopyConverter(self.target_format.repository_format)
2122
1886
converter.convert(repo, pb)
2124
branch = self.bzrdir.open_branch()
2125
except errors.NotBranchError:
2128
# TODO: conversions of Branch and Tree should be done by
2129
# InterXFormat lookups
2130
# Avoid circular imports
2131
from bzrlib import branch as _mod_branch
2132
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2133
self.target_format.get_branch_format().__class__ is
2134
_mod_branch.BzrBranchFormat6):
2135
branch_converter = _mod_branch.Converter5to6()
2136
branch_converter.convert(branch)
2138
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2139
except (errors.NoWorkingTree, errors.NotLocalUrl):
2142
# TODO: conversions of Branch and Tree should be done by
2143
# InterXFormat lookups
2144
if (isinstance(tree, workingtree.WorkingTree3) and
2145
not isinstance(tree, workingtree_4.WorkingTree4) and
2146
isinstance(self.target_format.workingtree_format,
2147
workingtree_4.WorkingTreeFormat4)):
2148
workingtree_4.Converter3to4().convert(tree)
2149
1887
return to_convert
2152
class BzrDirFormatInfo(object):
2154
def __init__(self, native, deprecated, hidden):
2155
self.deprecated = deprecated
2156
self.native = native
2157
self.hidden = hidden
2160
class BzrDirFormatRegistry(registry.Registry):
2161
"""Registry of user-selectable BzrDir subformats.
2163
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2164
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2167
def register_metadir(self, key,
2168
repository_format, help, native=True, deprecated=False,
2172
"""Register a metadir subformat.
2174
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2175
by the Repository format.
2177
:param repository_format: The fully-qualified repository format class
2179
:param branch_format: Fully-qualified branch format class name as
2181
:param tree_format: Fully-qualified tree format class name as
2184
# This should be expanded to support setting WorkingTree and Branch
2185
# formats, once BzrDirMetaFormat1 supports that.
2186
def _load(full_name):
2187
mod_name, factory_name = full_name.rsplit('.', 1)
2189
mod = __import__(mod_name, globals(), locals(),
2191
except ImportError, e:
2192
raise ImportError('failed to load %s: %s' % (full_name, e))
2194
factory = getattr(mod, factory_name)
2195
except AttributeError:
2196
raise AttributeError('no factory %s in module %r'
2201
bd = BzrDirMetaFormat1()
2202
if branch_format is not None:
2203
bd.set_branch_format(_load(branch_format))
2204
if tree_format is not None:
2205
bd.workingtree_format = _load(tree_format)
2206
if repository_format is not None:
2207
bd.repository_format = _load(repository_format)
2209
self.register(key, helper, help, native, deprecated, hidden)
2211
def register(self, key, factory, help, native=True, deprecated=False,
2213
"""Register a BzrDirFormat factory.
2215
The factory must be a callable that takes one parameter: the key.
2216
It must produce an instance of the BzrDirFormat when called.
2218
This function mainly exists to prevent the info object from being
2221
registry.Registry.register(self, key, factory, help,
2222
BzrDirFormatInfo(native, deprecated, hidden))
2224
def register_lazy(self, key, module_name, member_name, help, native=True,
2225
deprecated=False, hidden=False):
2226
registry.Registry.register_lazy(self, key, module_name, member_name,
2227
help, BzrDirFormatInfo(native, deprecated, hidden))
2229
def set_default(self, key):
2230
"""Set the 'default' key to be a clone of the supplied key.
2232
This method must be called once and only once.
2234
registry.Registry.register(self, 'default', self.get(key),
2235
self.get_help(key), info=self.get_info(key))
2237
def set_default_repository(self, key):
2238
"""Set the FormatRegistry default and Repository default.
2240
This is a transitional method while Repository.set_default_format
2243
if 'default' in self:
2244
self.remove('default')
2245
self.set_default(key)
2246
format = self.get('default')()
2247
assert isinstance(format, BzrDirMetaFormat1)
2249
def make_bzrdir(self, key):
2250
return self.get(key)()
2252
def help_topic(self, topic):
2253
output = textwrap.dedent("""\
2254
Bazaar directory formats
2255
------------------------
2257
These formats can be used for creating branches, working trees, and
2261
default_help = self.get_help('default')
2263
for key in self.keys():
2264
if key == 'default':
2266
help = self.get_help(key)
2267
if help == default_help:
2268
default_realkey = key
2270
help_pairs.append((key, help))
2272
def wrapped(key, help, info):
2274
help = '(native) ' + help
2275
return ' %s:\n%s\n\n' % (key,
2276
textwrap.fill(help, initial_indent=' ',
2277
subsequent_indent=' '))
2278
output += wrapped('%s/default' % default_realkey, default_help,
2279
self.get_info('default'))
2280
deprecated_pairs = []
2281
for key, help in help_pairs:
2282
info = self.get_info(key)
2285
elif info.deprecated:
2286
deprecated_pairs.append((key, help))
2288
output += wrapped(key, help, info)
2289
if len(deprecated_pairs) > 0:
2290
output += "Deprecated formats\n------------------\n\n"
2291
for key, help in deprecated_pairs:
2292
info = self.get_info(key)
2293
output += wrapped(key, help, info)
2298
format_registry = BzrDirFormatRegistry()
2299
format_registry.register('weave', BzrDirFormat6,
2300
'Pre-0.8 format. Slower than knit and does not'
2301
' support checkouts or shared repositories.',
2303
format_registry.register_metadir('knit',
2304
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2305
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2306
branch_format='bzrlib.branch.BzrBranchFormat5',
2307
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2308
format_registry.register_metadir('metaweave',
2309
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2310
'Transitional format in 0.8. Slower than knit.',
2311
branch_format='bzrlib.branch.BzrBranchFormat5',
2312
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2314
format_registry.register_metadir('dirstate',
2315
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2316
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2317
'above when accessed over the network.',
2318
branch_format='bzrlib.branch.BzrBranchFormat5',
2319
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2320
# directly from workingtree_4 triggers a circular import.
2321
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2323
format_registry.register_metadir('dirstate-tags',
2324
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2325
help='New in 0.15: Fast local operations and improved scaling for '
2326
'network operations. Additionally adds support for tags.'
2327
' Incompatible with bzr < 0.15.',
2328
branch_format='bzrlib.branch.BzrBranchFormat6',
2329
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2331
format_registry.register_metadir('dirstate-with-subtree',
2332
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2333
help='New in 0.15: Fast local operations and improved scaling for '
2334
'network operations. Additionally adds support for versioning nested '
2335
'bzr branches. Incompatible with bzr < 0.15.',
2336
branch_format='bzrlib.branch.BzrBranchFormat6',
2337
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2340
format_registry.set_default('dirstate')