1961
1971
converter = CopyConverter(self.target_format.repository_format)
1962
1972
converter.convert(repo, pb)
1963
1973
return to_convert
1976
class BzrDirFormatInfo(object):
1978
def __init__(self, native, deprecated):
1979
self.deprecated = deprecated
1980
self.native = native
1983
class BzrDirFormatRegistry(registry.Registry):
1984
"""Registry of user-selectable BzrDir subformats.
1986
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
1987
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
1990
def register_metadir(self, key, repo, help, native=True, deprecated=False):
1991
"""Register a metadir subformat.
1993
repo is the repository format name as a string.
1995
# This should be expanded to support setting WorkingTree and Branch
1996
# formats, once BzrDirMetaFormat1 supports that.
1998
import bzrlib.repository
1999
repo_format = getattr(bzrlib.repository, repo)
2000
bd = BzrDirMetaFormat1()
2001
bd.repository_format = repo_format()
2003
self.register(key, helper, help, native, deprecated)
2005
def register(self, key, factory, help, native=True, deprecated=False):
2006
"""Register a BzrDirFormat factory.
2008
The factory must be a callable that takes one parameter: the key.
2009
It must produce an instance of the BzrDirFormat when called.
2011
This function mainly exists to prevent the info object from being
2014
registry.Registry.register(self, key, factory, help,
2015
BzrDirFormatInfo(native, deprecated))
2017
def register_lazy(self, key, module_name, member_name, help, native=True,
2019
registry.Registry.register_lazy(self, key, module_name, member_name,
2020
help, BzrDirFormatInfo(native, deprecated))
2022
def set_default(self, key):
2023
"""Set the 'default' key to be a clone of the supplied key.
2025
This method must be called once and only once.
2027
registry.Registry.register(self, 'default', self.get(key),
2028
self.get_help(key), info=self.get_info(key))
2030
def set_default_repository(self, key):
2031
"""Set the FormatRegistry default and Repository default.
2033
This is a transitional method while Repository.set_default_format
2036
if 'default' in self:
2037
self.remove('default')
2038
self.set_default(key)
2039
format = self.get('default')()
2040
assert isinstance(format, BzrDirMetaFormat1)
2041
from bzrlib import repository
2042
repository.RepositoryFormat._set_default_format(
2043
format.repository_format)
2045
def make_bzrdir(self, key):
2046
return self.get(key)()
2048
def help_topic(self, topic):
2049
output = textwrap.dedent("""\
2050
Bazaar directory formats
2051
------------------------
2053
These formats can be used for creating branches, working trees, and
2057
default_help = self.get_help('default')
2059
for key in self.keys():
2060
if key == 'default':
2062
help = self.get_help(key)
2063
if help == default_help:
2064
default_realkey = key
2066
help_pairs.append((key, help))
2068
def wrapped(key, help, info):
2070
help = '(native) ' + help
2071
return ' %s:\n%s\n\n' % (key,
2072
textwrap.fill(help, initial_indent=' ',
2073
subsequent_indent=' '))
2074
output += wrapped('%s/default' % default_realkey, default_help,
2075
self.get_info('default'))
2076
deprecated_pairs = []
2077
for key, help in help_pairs:
2078
info = self.get_info(key)
2080
deprecated_pairs.append((key, help))
2082
output += wrapped(key, help, info)
2083
if len(deprecated_pairs) > 0:
2084
output += "Deprecated formats\n------------------\n\n"
2085
for key, help in deprecated_pairs:
2086
info = self.get_info(key)
2087
output += wrapped(key, help, info)
2092
format_registry = BzrDirFormatRegistry()
2093
format_registry.register('weave', BzrDirFormat6,
2094
'Pre-0.8 format. Slower than knit and does not'
2095
' support checkouts or shared repositories.', deprecated=True)
2096
format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
2097
'Format using knits. Recommended.')
2098
format_registry.set_default('knit')
2099
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
2100
'Transitional format in 0.8. Slower than knit.',
2102
format_registry.register_metadir('experimental-knit2', 'RepositoryFormatKnit2',
2103
'Experimental successor to knit. Use at your own risk.')