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