2990
2971
BzrDirMetaFormat1._set_repository_format) #.im_func)
2993
ControlDirFormat.register_server_format(RemoteBzrDirFormat)
2996
class BzrDirFormatInfo(object):
2998
def __init__(self, native, deprecated, hidden, experimental):
2999
self.deprecated = deprecated
3000
self.native = native
3001
self.hidden = hidden
3002
self.experimental = experimental
3005
class BzrDirFormatRegistry(registry.Registry):
3006
"""Registry of user-selectable BzrDir subformats.
3008
Differs from ControlDirFormat._formats in that it provides sub-formats,
3009
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
3013
"""Create a BzrDirFormatRegistry."""
3014
self._aliases = set()
3015
self._registration_order = list()
3016
super(BzrDirFormatRegistry, self).__init__()
3019
"""Return a set of the format names which are aliases."""
3020
return frozenset(self._aliases)
3022
def register_metadir(self, key,
3023
repository_format, help, native=True, deprecated=False,
3029
"""Register a metadir subformat.
3031
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3032
by the Repository/Branch/WorkingTreeformats.
3034
:param repository_format: The fully-qualified repository format class
3036
:param branch_format: Fully-qualified branch format class name as
3038
:param tree_format: Fully-qualified tree format class name as
3041
# This should be expanded to support setting WorkingTree and Branch
3042
# formats, once BzrDirMetaFormat1 supports that.
3043
def _load(full_name):
3044
mod_name, factory_name = full_name.rsplit('.', 1)
3046
mod = __import__(mod_name, globals(), locals(),
3048
except ImportError, e:
3049
raise ImportError('failed to load %s: %s' % (full_name, e))
3051
factory = getattr(mod, factory_name)
3052
except AttributeError:
3053
raise AttributeError('no factory %s in module %r'
3058
bd = BzrDirMetaFormat1()
3059
if branch_format is not None:
3060
bd.set_branch_format(_load(branch_format))
3061
if tree_format is not None:
3062
bd.workingtree_format = _load(tree_format)
3063
if repository_format is not None:
3064
bd.repository_format = _load(repository_format)
3066
self.register(key, helper, help, native, deprecated, hidden,
3067
experimental, alias)
3069
def register(self, key, factory, help, native=True, deprecated=False,
3070
hidden=False, experimental=False, alias=False):
3071
"""Register a BzrDirFormat factory.
3073
The factory must be a callable that takes one parameter: the key.
3074
It must produce an instance of the BzrDirFormat when called.
3076
This function mainly exists to prevent the info object from being
3079
registry.Registry.register(self, key, factory, help,
3080
BzrDirFormatInfo(native, deprecated, hidden, experimental))
3082
self._aliases.add(key)
3083
self._registration_order.append(key)
3085
def register_lazy(self, key, module_name, member_name, help, native=True,
3086
deprecated=False, hidden=False, experimental=False, alias=False):
3087
registry.Registry.register_lazy(self, key, module_name, member_name,
3088
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
3090
self._aliases.add(key)
3091
self._registration_order.append(key)
3093
def set_default(self, key):
3094
"""Set the 'default' key to be a clone of the supplied key.
3096
This method must be called once and only once.
3098
registry.Registry.register(self, 'default', self.get(key),
3099
self.get_help(key), info=self.get_info(key))
3100
self._aliases.add('default')
3102
def set_default_repository(self, key):
3103
"""Set the FormatRegistry default and Repository default.
3105
This is a transitional method while Repository.set_default_format
3108
if 'default' in self:
3109
self.remove('default')
3110
self.set_default(key)
3111
format = self.get('default')()
3113
def make_bzrdir(self, key):
3114
return self.get(key)()
3116
def help_topic(self, topic):
3118
default_realkey = None
3119
default_help = self.get_help('default')
3121
for key in self._registration_order:
3122
if key == 'default':
3124
help = self.get_help(key)
3125
if help == default_help:
3126
default_realkey = key
3128
help_pairs.append((key, help))
3130
def wrapped(key, help, info):
3132
help = '(native) ' + help
3133
return ':%s:\n%s\n\n' % (key,
3134
textwrap.fill(help, initial_indent=' ',
3135
subsequent_indent=' ',
3136
break_long_words=False))
3137
if default_realkey is not None:
3138
output += wrapped(default_realkey, '(default) %s' % default_help,
3139
self.get_info('default'))
3140
deprecated_pairs = []
3141
experimental_pairs = []
3142
for key, help in help_pairs:
3143
info = self.get_info(key)
3146
elif info.deprecated:
3147
deprecated_pairs.append((key, help))
3148
elif info.experimental:
3149
experimental_pairs.append((key, help))
3151
output += wrapped(key, help, info)
3152
output += "\nSee :doc:`formats-help` for more about storage formats."
3154
if len(experimental_pairs) > 0:
3155
other_output += "Experimental formats are shown below.\n\n"
3156
for key, help in experimental_pairs:
3157
info = self.get_info(key)
3158
other_output += wrapped(key, help, info)
3161
"No experimental formats are available.\n\n"
3162
if len(deprecated_pairs) > 0:
3163
other_output += "\nDeprecated formats are shown below.\n\n"
3164
for key, help in deprecated_pairs:
3165
info = self.get_info(key)
3166
other_output += wrapped(key, help, info)
3169
"\nNo deprecated formats are available.\n\n"
3171
"\nSee :doc:`formats-help` for more about storage formats."
3173
if topic == 'other-formats':
2974
ControlDirFormat.register_server_prober(RemoteBzrProber)
3179
2977
class RepositoryAcquisitionPolicy(object):
3333
3131
return self._repository, False
3336
# Please register new formats after old formats so that formats
3337
# appear in chronological order and format descriptions can build
3339
format_registry = BzrDirFormatRegistry()
3134
def register_metadir(key,
3135
repository_format, help, native=True, deprecated=False,
3141
"""Register a metadir subformat.
3143
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3144
by the Repository/Branch/WorkingTreeformats.
3146
:param repository_format: The fully-qualified repository format class
3148
:param branch_format: Fully-qualified branch format class name as
3150
:param tree_format: Fully-qualified tree format class name as
3153
# This should be expanded to support setting WorkingTree and Branch
3154
# formats, once BzrDirMetaFormat1 supports that.
3155
def _load(full_name):
3156
mod_name, factory_name = full_name.rsplit('.', 1)
3158
mod = __import__(mod_name, globals(), locals(),
3160
except ImportError, e:
3161
raise ImportError('failed to load %s: %s' % (full_name, e))
3163
factory = getattr(mod, factory_name)
3164
except AttributeError:
3165
raise AttributeError('no factory %s in module %r'
3170
bd = BzrDirMetaFormat1()
3171
if branch_format is not None:
3172
bd.set_branch_format(_load(branch_format))
3173
if tree_format is not None:
3174
bd.workingtree_format = _load(tree_format)
3175
if repository_format is not None:
3176
bd.repository_format = _load(repository_format)
3178
format_registry.register(key, helper, help, native, deprecated, hidden,
3179
experimental, alias)
3340
3181
# The pre-0.8 formats have their repository format network name registered in
3341
3182
# repository.py. MetaDir formats have their repository format network name
3342
3183
# inferred from their disk format string.
3345
3186
' support checkouts or shared repositories.',
3347
3188
deprecated=True)
3348
format_registry.register_metadir('metaweave',
3189
register_metadir('metaweave',
3349
3190
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3350
3191
'Transitional format in 0.8. Slower than knit.',
3351
3192
branch_format='bzrlib.branch.BzrBranchFormat5',
3352
3193
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3354
3195
deprecated=True)
3355
format_registry.register_metadir('knit',
3196
register_metadir('knit',
3356
3197
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3357
3198
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3358
3199
branch_format='bzrlib.branch.BzrBranchFormat5',
3359
3200
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3361
3202
deprecated=True)
3362
format_registry.register_metadir('dirstate',
3203
register_metadir('dirstate',
3363
3204
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3364
3205
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3365
3206
'above when accessed over the network.',