2270
2262
The option *values* are stored in config files and found in sections.
2272
2264
Here we define various properties about the option itself, its default
2273
value, how to convert it from stores, what to do when invalid values are
2274
encoutered, in which config files it can be stored.
2265
value, in which config files it can be stored, etc (TBC).
2277
def __init__(self, name, default=None, help=None, from_unicode=None,
2279
"""Build an option definition.
2281
:param name: the name used to refer to the option.
2283
:param default: the default value to use when none exist in the config
2286
:param help: a doc string to explain the option to the user.
2288
:param from_unicode: a callable to convert the unicode string
2289
representing the option value in a store. This is not called for
2292
:param invalid: the action to be taken when an invalid value is
2293
encountered in a store. This is called only when from_unicode is
2294
invoked to convert a string and returns None or raise ValueError or
2295
TypeError. Accepted values are: None (ignore invalid values),
2296
'warning' (emit a warning), 'error' (emit an error message and
2268
def __init__(self, name, default=None):
2299
2269
self.name = name
2300
2270
self.default = default
2302
self.from_unicode = from_unicode
2303
if invalid and invalid not in ('warning', 'error'):
2304
raise AssertionError("%s not supported for 'invalid'" % (invalid,))
2305
self.invalid = invalid
2307
2272
def get_default(self):
2308
2273
return self.default
2310
def get_help_text(self, additional_see_also=None, plain=True):
2312
from bzrlib import help_topics
2313
result += help_topics._format_see_also(additional_see_also)
2315
result = help_topics.help_as_plain_text(result)
2319
# Predefined converters to get proper values from store
2321
def bool_from_store(unicode_str):
2322
return ui.bool_from_string(unicode_str)
2325
def int_from_store(unicode_str):
2326
return int(unicode_str)
2329
def list_from_store(unicode_str):
2330
# ConfigObj return '' instead of u''. Use 'str' below to catch all cases.
2331
if isinstance(unicode_str, (str, unicode)):
2333
# A single value, most probably the user forgot (or didn't care to
2334
# add) the final ','
2337
# The empty string, convert to empty list
2340
# We rely on ConfigObj providing us with a list already
2345
class OptionRegistry(registry.Registry):
2346
"""Register config options by their name.
2348
This overrides ``registry.Registry`` to simplify registration by acquiring
2349
some information from the option object itself.
2352
def register(self, option):
2353
"""Register a new option to its name.
2355
:param option: The option to register. Its name is used as the key.
2357
super(OptionRegistry, self).register(option.name, option,
2360
def register_lazy(self, key, module_name, member_name):
2361
"""Register a new option to be loaded on request.
2363
:param key: the key to request the option later. Since the registration
2364
is lazy, it should be provided and match the option name.
2366
:param module_name: the python path to the module. Such as 'os.path'.
2368
:param member_name: the member of the module to return. If empty or
2369
None, get() will return the module itself.
2371
super(OptionRegistry, self).register_lazy(key,
2372
module_name, member_name)
2374
def get_help(self, key=None):
2375
"""Get the help text associated with the given key"""
2376
option = self.get(key)
2377
the_help = option.help
2378
if callable(the_help):
2379
return the_help(self, key)
2383
option_registry = OptionRegistry()
2386
# Registered options in lexicographical order
2388
option_registry.register(
2389
Option('bzr.workingtree.worth_saving_limit', default=10,
2390
from_unicode=int_from_store, invalid='warning',
2392
How many changes before saving the dirstate.
2394
-1 means that we will never rewrite the dirstate file for only
2395
stat-cache changes. Regardless of this setting, we will always rewrite
2396
the dirstate file if a file is added/removed/renamed/etc. This flag only
2397
affects the behavior of updating the dirstate file after we notice that
2398
a file has been touched.
2400
option_registry.register(
2401
Option('dirstate.fdatasync', default=True,
2402
from_unicode=bool_from_store,
2404
Flush dirstate changes onto physical disk?
2406
If true (default), working tree metadata changes are flushed through the
2407
OS buffers to physical disk. This is somewhat slower, but means data
2408
should not be lost if the machine crashes. See also repository.fdatasync.
2410
option_registry.register(
2411
Option('debug_flags', default=[], from_unicode=list_from_store,
2412
help='Debug flags to activate.'))
2413
option_registry.register(
2414
Option('default_format', default='2a',
2415
help='Format used when creating branches.'))
2416
option_registry.register(
2418
help='The command called to launch an editor to enter a message.'))
2419
option_registry.register(
2420
Option('ignore_missing_extensions', default=False,
2421
from_unicode=bool_from_store,
2423
Control the missing extensions warning display.
2425
The warning will not be emitted if set to True.
2427
option_registry.register(
2429
help='Language to translate messages into.'))
2430
option_registry.register(
2431
Option('locks.steal_dead', default=False, from_unicode=bool_from_store,
2433
Steal locks that appears to be dead.
2435
If set to True, bzr will check if a lock is supposed to be held by an
2436
active process from the same user on the same machine. If the user and
2437
machine match, but no process with the given PID is active, then bzr
2438
will automatically break the stale lock, and create a new lock for
2440
Otherwise, bzr will prompt as normal to break the lock.
2442
option_registry.register(
2443
Option('output_encoding',
2444
help= 'Unicode encoding for output'
2445
' (terminal encoding if not specified).'))
2446
option_registry.register(
2447
Option('repository.fdatasync', default=True, from_unicode=bool_from_store,
2449
Flush repository changes onto physical disk?
2451
If true (default), repository changes are flushed through the OS buffers
2452
to physical disk. This is somewhat slower, but means data should not be
2453
lost if the machine crashes. See also dirstate.fdatasync.
2278
option_registry = registry.Registry()
2281
option_registry.register(
2282
'editor', Option('editor'),
2283
help='The command called to launch an editor to enter a message.')
2457
2286
class Section(object):