55
55
turns on create_signatures.
56
56
create_signatures - this option controls whether bzr will always create
57
57
gpg signatures or not on commits. There is an unused
58
option which in future is expected to work if
58
option which in future is expected to work if
59
59
branch settings require signatures.
60
60
log_format - this option sets the default log format. Possible values are
61
61
long, short, line, or a plugin can register new formats.
239
240
return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,
243
def get_mail_client(self):
244
"""Get a mail client to use"""
245
selected_client = self.get_user_option('mail_client')
246
_registry = mail_client.mail_client_registry
248
mail_client_class = _registry.get(selected_client)
250
raise errors.UnknownMailClient(selected_client)
251
return mail_client_class(self)
242
253
def _get_signature_checking(self):
243
254
"""Template method to override signature checking policy."""
2373
2382
raise AssertionError('%r is not supported as a default value'
2375
2384
self.default_from_env = default_from_env
2377
2386
self.from_unicode = from_unicode
2378
2387
self.unquote = unquote
2379
2388
if invalid and invalid not in ('warning', 'error'):
2380
2389
raise AssertionError("%s not supported for 'invalid'" % (invalid,))
2381
2390
self.invalid = invalid
2387
2392
def convert_from_unicode(self, store, unicode_value):
2388
2393
if self.unquote and store is not None and unicode_value is not None:
2389
2394
unicode_value = store.unquote(unicode_value)
2532
class RegistryOption(Option):
2533
"""Option for a choice from a registry."""
2535
def __init__(self, name, registry, default_from_env=None,
2536
help=None, invalid=None):
2537
"""A registry based Option definition.
2539
This overrides the base class so the conversion from a unicode string
2540
can take quoting into account.
2542
super(RegistryOption, self).__init__(
2543
name, default=lambda: unicode(registry.default_key),
2544
default_from_env=default_from_env,
2545
from_unicode=self.from_unicode, help=help,
2546
invalid=invalid, unquote=False)
2547
self.registry = registry
2549
def from_unicode(self, unicode_str):
2550
if not isinstance(unicode_str, basestring):
2553
return self.registry.get(unicode_str)
2556
"Invalid value %s for %s."
2557
"See help for a list of possible values." % (unicode_str,
2562
ret = [self._help, "\n\nThe following values are supported:\n"]
2563
for key in self.registry.keys():
2564
ret.append(" %s - %s\n" % (key, self.registry.get_help(key)))
2568
2537
class OptionRegistry(registry.Registry):
2569
2538
"""Register config options by their name.
2661
2630
Whether revisions associated with tags should be fetched.
2663
option_registry.register_lazy(
2664
'bzr.transform.orphan_policy', 'bzrlib.transform', 'opt_transform_orphan')
2665
2632
option_registry.register(
2666
2633
Option('bzr.workingtree.worth_saving_limit', default=10,
2667
2634
from_unicode=int_from_store, invalid='warning',
2675
2642
a file has been touched.
2677
2644
option_registry.register(
2678
Option('bugtracker', default=None,
2680
Default bug tracker to use.
2682
This bug tracker will be used for example when marking bugs
2683
as fixed using ``bzr commit --fixes``, if no explicit
2684
bug tracker was specified.
2686
option_registry.register(
2687
2645
Option('check_signatures', default=CHECK_IF_POSSIBLE,
2688
2646
from_unicode=signature_policy_from_unicode,
2791
2749
Standard log formats are ``long``, ``short`` and ``line``. Additional formats
2792
2750
may be provided by plugins.
2794
option_registry.register_lazy('mail_client', 'bzrlib.mail_client',
2796
2752
option_registry.register(
2797
2753
Option('output_encoding',
2798
2754
help= 'Unicode encoding for output'
2895
2851
option_registry.register(
2896
2852
Option('submit_to',
2897
2853
help='''Where submissions from this branch are mailed to.'''))
2898
option_registry.register(
2899
ListOption('suppress_warnings',
2901
help="List of warning classes to suppress."))
2902
option_registry.register(
2903
Option('validate_signatures_in_log', default=False,
2904
from_unicode=bool_from_store, invalid='warning',
2905
help='''Whether to validate signatures in bzr log.'''))
2906
2855
option_registry.register_lazy('ssl.ca_certs',
2907
2856
'bzrlib.transport.http._urllib2_wrappers', 'opt_ssl_ca_certs')
3418
3368
self.branch = branch
3419
3369
self.id = 'branch'
3371
def lock_write(self, token=None):
3372
return self.branch.lock_write(token)
3375
return self.branch.unlock()
3379
# We need to be able to override the undecorated implementation
3380
self.save_without_locking()
3382
def save_without_locking(self):
3383
super(BranchStore, self).save()
3422
3386
class ControlStore(LockableIniFileStore):
3645
3609
self.store = store
3646
3610
self.mutable_section_id = mutable_section_id
3648
def iter_sections(self):
3649
"""Iterate all the defined sections."""
3650
# Ensuring lazy loading is achieved by delaying section matching (which
3651
# implies querying the persistent storage) until it can't be avoided
3652
# anymore by using callables to describe (possibly empty) section
3654
for sections in self.sections_def:
3655
for store, section in sections():
3656
yield store, section
3658
def get(self, name, expand=None, convert=True):
3612
def get(self, name, expand=None):
3659
3613
"""Return the *first* option value found in the sections.
3661
3615
This is where we guarantee that sections coming from Store are loaded
3709
3660
value = opt.get_override()
3710
3661
value = expand_and_convert(value)
3711
3662
if value is None:
3712
for store, section in self.iter_sections():
3713
value = section.get(name)
3663
# Ensuring lazy loading is achieved by delaying section matching
3664
# (which implies querying the persistent storage) until it can't be
3665
# avoided anymore by using callables to describe (possibly empty)
3667
for sections in self.sections_def:
3668
for store, section in sections():
3669
value = section.get(name)
3670
if value is not None:
3714
3673
if value is not None:
3717
3675
value = expand_and_convert(value)
3718
3676
if opt is not None and value is None:
3965
3923
self.branch = branch
3967
def lock_write(self, token=None):
3968
return self.branch.lock_write(token)
3971
return self.branch.unlock()
3974
def set(self, name, value):
3975
super(BranchStack, self).set(name, value)
3976
# Unlocking the branch will trigger a store.save_changes() so the last
3977
# unlock saves all the changes.
3980
def remove(self, name):
3981
super(BranchStack, self).remove(name)
3982
# Unlocking the branch will trigger a store.save_changes() so the last
3983
# unlock saves all the changes.
3986
3926
class RemoteControlStack(_CompatibleStack):
3987
3927
"""Remote control-only options stack."""
4013
3953
self.branch = branch
4015
def lock_write(self, token=None):
4016
return self.branch.lock_write(token)
4019
return self.branch.unlock()
4022
def set(self, name, value):
4023
super(BranchOnlyStack, self).set(name, value)
4024
# Force a write to persistent storage
4025
self.store.save_changes()
4028
def remove(self, name):
4029
super(BranchOnlyStack, self).remove(name)
4030
# Force a write to persistent storage
4031
self.store.save_changes()
3956
# Use a an empty dict to initialize an empty configobj avoiding all
3957
# parsing and encoding checks
3958
_quoting_config = configobj.ConfigObj(
3959
{}, encoding='utf-8', interpolation=False, list_values=True)
4034
3961
class cmd_config(commands.Command):
4035
3962
__doc__ = """Display, set or remove a configuration option.
4097
4024
# Set the option value
4098
4025
self._set_config_option(name, value, directory, scope)
4100
def _get_stack(self, directory, scope=None, write_access=False):
4027
def _get_stack(self, directory, scope=None):
4101
4028
"""Get the configuration stack specified by ``directory`` and ``scope``.
4103
4030
:param directory: Where the configurations are derived from.
4105
4032
:param scope: A specific config to start from.
4107
:param write_access: Whether a write access to the stack will be
4110
4034
# FIXME: scope should allow access to plugin-specific stacks (even
4111
4035
# reduced to the plugin-specific store), related to
4129
4051
controldir.ControlDir.open_containing_tree_or_branch(
4132
self.add_cleanup(br.lock_write().unlock)
4133
4053
return br.get_config_stack()
4134
4054
except errors.NotBranchError:
4135
4055
return LocationStack(directory)
4137
def _quote_multiline(self, value):
4139
value = '"""' + value + '"""'
4142
4057
def _show_value(self, name, directory, scope):
4143
4058
conf = self._get_stack(directory, scope)
4144
value = conf.get(name, expand=True, convert=False)
4059
value = conf.get(name, expand=True)
4145
4060
if value is not None:
4146
4061
# Quote the value appropriately
4147
value = self._quote_multiline(value)
4062
value = _quoting_config._quote(value)
4148
4063
self.outf.write('%s\n' % (value,))
4150
4065
raise errors.NoSuchConfigOption(name)
4158
4073
cur_store_id = None
4159
4074
cur_section = None
4160
4075
conf = self._get_stack(directory, scope)
4161
for store, section in conf.iter_sections():
4162
for oname in section.iter_option_names():
4163
if name.search(oname):
4164
if cur_store_id != store.id:
4165
# Explain where the options are defined
4166
self.outf.write('%s:\n' % (store.id,))
4167
cur_store_id = store.id
4169
if (section.id is not None and cur_section != section.id):
4170
# Display the section id as it appears in the store
4171
# (None doesn't appear by definition)
4172
self.outf.write(' [%s]\n' % (section.id,))
4173
cur_section = section.id
4174
value = section.get(oname, expand=False)
4175
# Quote the value appropriately
4176
value = self._quote_multiline(value)
4177
self.outf.write(' %s = %s\n' % (oname, value))
4076
for sections in conf.sections_def:
4077
for store, section in sections():
4078
for oname in section.iter_option_names():
4079
if name.search(oname):
4080
if cur_store_id != store.id:
4081
# Explain where the options are defined
4082
self.outf.write('%s:\n' % (store.id,))
4083
cur_store_id = store.id
4085
if (section.id is not None
4086
and cur_section != section.id):
4087
# Display the section id as it appears in the store
4088
# (None doesn't appear by definition)
4089
self.outf.write(' [%s]\n' % (section.id,))
4090
cur_section = section.id
4091
value = section.get(oname, expand=False)
4092
# Since we don't use the stack, we need to restore a
4095
opt = option_registry.get(oname)
4096
value = opt.convert_from_unicode(store, value)
4098
value = store.unquote(value)
4099
value = _quoting_config._quote(value)
4100
self.outf.write(' %s = %s\n' % (oname, value))
4179
4102
def _set_config_option(self, name, value, directory, scope):
4180
conf = self._get_stack(directory, scope, write_access=True)
4103
conf = self._get_stack(directory, scope)
4181
4104
conf.set(name, value)
4183
4106
def _remove_config_option(self, name, directory, scope):
4184
4107
if name is None:
4185
4108
raise errors.BzrCommandError(
4186
4109
'--remove expects an option to remove.')
4187
conf = self._get_stack(directory, scope, write_access=True)
4110
conf = self._get_stack(directory, scope)
4189
4112
conf.remove(name)
4190
4113
except KeyError: