2275
2275
value, in which config files it can be stored, etc (TBC).
2278
def __init__(self, name, default=None, help=None):
2278
def __init__(self, name, default=None):
2279
2279
self.name = name
2280
2280
self.default = default
2283
2282
def get_default(self):
2284
2283
return self.default
2287
class OptionRegistry(registry.Registry):
2288
"""Register config options by their name.
2290
This overrides ``registry.Registry`` to simplify registration by acquiring
2291
some information from the option object itself.
2294
def register(self, option):
2295
"""Register a new option to its name.
2297
:param option: The option to register. Its name is used as the key.
2299
super(OptionRegistry, self).register(option.name, option,
2302
def register_lazy(self, key, module_name, member_name):
2303
"""Register a new option to be loaded on request.
2305
:param key: This is the key to use to request the option later. Since
2306
the registration is lazy, it should be provided and match the
2309
:param module_name: The python path to the module. Such as 'os.path'.
2311
:param member_name: The member of the module to return. If empty or
2312
None, get() will return the module itself.
2314
super(OptionRegistry, self).register_lazy(key,
2315
module_name, member_name)
2317
def get_help(self, key=None):
2318
"""Get the help text associated with the given key"""
2319
option = self.get(key)
2320
the_help = option.help
2321
if callable(the_help):
2322
return the_help(self, key)
2326
option_registry = OptionRegistry()
2329
# Registered options in lexicographical order
2331
option_registry.register(
2332
Option('dirstate.fdatasync', default=True,
2334
Flush dirstate changes onto physical disk?
2336
If true (default), working tree metadata changes are flushed through the
2337
OS buffers to physical disk. This is somewhat slower, but means data
2338
should not be lost if the machine crashes. See also repository.fdatasync.
2340
option_registry.register(
2341
Option('default_format', default='2a',
2342
help='Format used when creating branches.'))
2343
option_registry.register(
2345
help='The command called to launch an editor to enter a message.'))
2346
option_registry.register(
2348
help='Language to translate messages into.'))
2349
option_registry.register(
2350
Option('output_encoding',
2351
help= 'Unicode encoding for output'
2352
' (terminal encoding if not specified).'))
2353
option_registry.register(
2354
Option('repository.fdatasync', default=True,
2356
Flush repository changes onto physical disk?
2358
If true (default), repository changes are flushed through the OS buffers
2359
to physical disk. This is somewhat slower, but means data should not be
2360
lost if the machine crashes. See also dirstate.fdatasync.
2288
option_registry = registry.Registry()
2291
option_registry.register(
2292
'editor', Option('editor'),
2293
help='The command called to launch an editor to enter a message.')
2295
option_registry.register(
2296
'dirstate.fdatasync', Option('dirstate.fdatasync', default=True),
2297
help='Flush dirstate changes onto physical disk?')
2299
option_registry.register(
2300
'repository.fdatasync',
2301
Option('repository.fdatasync', default=True),
2302
help='Flush repository changes onto physical disk?')
2364
2305
class Section(object):