1986
1996
format.repository_format = repository.RepositoryFormatKnit2()
1987
1997
format.workingtree_format = workingtree.WorkingTreeFormat4()
2001
class BzrDirFormatInfo(object):
2003
def __init__(self, native, deprecated):
2004
self.deprecated = deprecated
2005
self.native = native
2008
class BzrDirFormatRegistry(registry.Registry):
2009
"""Registry of user-selectable BzrDir subformats.
2011
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2012
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
2015
def register_metadir(self, key, repo, help, native=True, deprecated=False):
2016
"""Register a metadir subformat.
2018
repo is the repository format name as a string.
2020
# This should be expanded to support setting WorkingTree and Branch
2021
# formats, once BzrDirMetaFormat1 supports that.
2023
import bzrlib.repository
2024
repo_format = getattr(bzrlib.repository, repo)
2025
bd = BzrDirMetaFormat1()
2026
bd.repository_format = repo_format()
2028
self.register(key, helper, help, native, deprecated)
2030
def register(self, key, factory, help, native=True, deprecated=False):
2031
"""Register a BzrDirFormat factory.
2033
The factory must be a callable that takes one parameter: the key.
2034
It must produce an instance of the BzrDirFormat when called.
2036
This function mainly exists to prevent the info object from being
2039
registry.Registry.register(self, key, factory, help,
2040
BzrDirFormatInfo(native, deprecated))
2042
def register_lazy(self, key, module_name, member_name, help, native=True,
2044
registry.Registry.register_lazy(self, key, module_name, member_name,
2045
help, BzrDirFormatInfo(native, deprecated))
2047
def set_default(self, key):
2048
"""Set the 'default' key to be a clone of the supplied key.
2050
This method must be called once and only once.
2052
registry.Registry.register(self, 'default', self.get(key),
2053
self.get_help(key), info=self.get_info(key))
2055
def set_default_repository(self, key):
2056
"""Set the FormatRegistry default and Repository default.
2058
This is a transitional method while Repository.set_default_format
2061
if 'default' in self:
2062
self.remove('default')
2063
self.set_default(key)
2064
format = self.get('default')()
2065
assert isinstance(format, BzrDirMetaFormat1)
2066
from bzrlib import repository
2067
repository.RepositoryFormat._set_default_format(
2068
format.repository_format)
2070
def make_bzrdir(self, key):
2071
return self.get(key)()
2073
def help_topic(self, topic):
2074
output = textwrap.dedent("""\
2075
Bazaar directory formats
2076
------------------------
2078
These formats can be used for creating branches, working trees, and
2082
default_help = self.get_help('default')
2084
for key in self.keys():
2085
if key == 'default':
2087
help = self.get_help(key)
2088
if help == default_help:
2089
default_realkey = key
2091
help_pairs.append((key, help))
2093
def wrapped(key, help, info):
2095
help = '(native) ' + help
2096
return ' %s:\n%s\n\n' % (key,
2097
textwrap.fill(help, initial_indent=' ',
2098
subsequent_indent=' '))
2099
output += wrapped('%s/default' % default_realkey, default_help,
2100
self.get_info('default'))
2101
deprecated_pairs = []
2102
for key, help in help_pairs:
2103
info = self.get_info(key)
2105
deprecated_pairs.append((key, help))
2107
output += wrapped(key, help, info)
2108
if len(deprecated_pairs) > 0:
2109
output += "Deprecated formats\n------------------\n\n"
2110
for key, help in deprecated_pairs:
2111
info = self.get_info(key)
2112
output += wrapped(key, help, info)
2117
format_registry = BzrDirFormatRegistry()
2118
format_registry.register('weave', BzrDirFormat6,
2119
'Pre-0.8 format. Slower than knit and does not'
2120
' support checkouts or shared repositories.', deprecated=True)
2121
format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
2122
'Format using knits. Recommended.')
2123
format_registry.set_default('knit')
2124
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
2125
'Transitional format in 0.8. Slower than knit.',
2127
format_registry.register_metadir('experimental-knit2', 'RepositoryFormatKnit2',
2128
'Experimental successor to knit. Use at your own risk.')