view mercurial/help/internals/config.txt @ 37290:cc5a040fe150

wireproto: syntax for encoding CBOR into frames We just vendored a library for encoding and decoding the CBOR data format. While the intent of that vendor was to support state files, CBOR is really a nice data format. It is extensible and compact. I've been feeling dirty inventing my own data formats for frame payloads. While custom formats can always beat out a generic format, there is a cost to be paid in terms of implementation, comprehension, etc. CBOR is compact enough that I'm not too worried about efficiency loss. I think the benefits of using a standardized format outweigh rolling our own formats. So I plan to make heavy use of CBOR in the wire protocol going forward. This commit introduces support for encoding CBOR data in frame payloads to our function to make a frame from a human string. We do need to employ some low-level Python code in order to evaluate a string as a Python expression. But other than that, this should hopefully be pretty straightforward. Unit tests for this function have been added. Differential Revision: https://phab.mercurial-scm.org/D2948
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 28 Mar 2018 15:05:39 -0700
parents fb7f58daca48
children 5b530d767e67
line wrap: on
line source

All config options used within Mercurial should be registered.

Config Option in Core
=====================

Config options used by Mercurial core are registered in the
``mercurial.configitems`` module.

Simple entry
------------

A registration entry typically looks like::

    coreconfigitem('section', 'option',
        default=MyDefaultValue,
    )

Once registered, Mercurial will know that ``section.option`` is a legitimate
config option and that ``MyDefaultValue`` should be used if no other values are
defined in configuration files.

Complex default value
---------------------

If the default provided is a callable, it is called to retrieve the default
value when accessing the config option. This is useful for default values that
are mutable like the empty list::

    coreconfigitem('pager', 'ignore',
        default=list,
    )

In addition, there are cases where the default is not fixed, but computed from
other properties. In this case, use the ``dynamicdefault`` object as the value
for the ``default`` parameter. A default value is then explicitly required when
reading the option::

    # registration
    coreconfigitem('web', 'name',
        default=dynamicdefault,
    )

    # usage
    ui.config('web', 'name', dirname)

Free form options
-----------------

Some config sections use free form options (e.g. ``paths``). You can register
them using the ``generic`` parameters::

    coreconfigitem('paths', '.*',
        default=None,
        generic=True,
    )

When ``generic=True`` is set, the option name is matched as a regular expression
(rooted to string start). It can be used to select specific sub parameters::

    coreconfigitem('merge-tools', br'.*\.args$',
        default="$local $base $other",
        generic=True,
        priority=-1,
    )

The ``priority`` parameter controls the order used to match the generic pattern
(lower first).

Config Option in Extensions
===========================

General case
------------

Extensions should register config items through the ``registrar`` API (also used
for commands and others)::

    configtable = {}
    configitem = registrar.configitem(configtable)

    configitem('blackbox', 'dirty',
        default=False,
    )

The ``dynamicdefault`` object is then available as
``configitem.dynamicdefault``.

Supporting older versions
-------------------------

The registrar was introduced in Mercurial 4.3, and the ``generic`` parameter was
introduced in 4.4. Starting with Mercurial 4.4, all core options were registered
and developer warnings are emitted when accessing unregistered option.

Extensions supporting versions older than Mercurial 4.3 cannot rely on the
default value being registered. The simplest way to register an option while
still supporting an older version is to use ``dynamicdefault`` for options
requiring a default value. The existing code passing an explicit default can
then stay in use until compatibility with Mercurial 4.2 is dropped.

As reminder, here are the default values for each config type:
- config:      None
- configbool:  False
- configbytes: 0
- configdate:  None
- configint:   None
- configlist:  []
- configpath:  None