Show More
@@ -0,0 +1,108 b'' | |||
|
1 | All config options used within Mercurial should be registered. | |
|
2 | ||
|
3 | Config Option in Core | |
|
4 | ===================== | |
|
5 | ||
|
6 | Config options used by Mercurial core are registered in the | |
|
7 | ``mercurial.configitems`` module. | |
|
8 | ||
|
9 | Simple entry | |
|
10 | ------------ | |
|
11 | ||
|
12 | A registration entry typically looks like:: | |
|
13 | ||
|
14 | coreconfigitem('section', 'option', | |
|
15 | default=MyDefaultValue, | |
|
16 | ) | |
|
17 | ||
|
18 | Once registered, Mercurial will know that ``section.option`` is a legitimate | |
|
19 | config option and that ``MyDefaultValue`` should be used if no other values are | |
|
20 | defined in configuration files. | |
|
21 | ||
|
22 | Complex default value | |
|
23 | --------------------- | |
|
24 | ||
|
25 | If the default provided is a callable, it is called to retrieve the default | |
|
26 | value when accessing the config option. This is useful for default value that | |
|
27 | are mutable like the empty list:: | |
|
28 | ||
|
29 | coreconfigitem('pager', 'ignore', | |
|
30 | default=list, | |
|
31 | ) | |
|
32 | ||
|
33 | In addition, there are cases where the default is not fixed, but computed from | |
|
34 | other properties. In this case, use the ``dynamicdefault`` object as value for | |
|
35 | the ``default`` parameters. A default value is then explicitly required when | |
|
36 | reading the option:: | |
|
37 | ||
|
38 | # registration | |
|
39 | coreconfigitem('web', 'name', | |
|
40 | default=dynamicdefault, | |
|
41 | ) | |
|
42 | ||
|
43 | # usage | |
|
44 | ui.config('web', 'name', dirnam) | |
|
45 | ||
|
46 | Free form options | |
|
47 | ----------------- | |
|
48 | ||
|
49 | Some config sections use free form options (e.g. ``paths``). You can register | |
|
50 | them using the ``generic`` parameters:: | |
|
51 | ||
|
52 | coreconfigitem('paths', '.*', | |
|
53 | default=None, | |
|
54 | generic=True, | |
|
55 | ) | |
|
56 | ||
|
57 | When ``generic=True`` is set, the option name is matched as a regular expression | |
|
58 | (rooted to string start). It can be used to select specific sub parameters:: | |
|
59 | ||
|
60 | coreconfigitem('merge-tools', br'.*\.args$', | |
|
61 | default="$local $base $other", | |
|
62 | generic=True, | |
|
63 | priority=-1, | |
|
64 | ) | |
|
65 | ||
|
66 | The ``priority`` parameter control the order used to match the generic pattern | |
|
67 | (lower first). | |
|
68 | ||
|
69 | Config Option in Extensions | |
|
70 | =========================== | |
|
71 | ||
|
72 | General case | |
|
73 | ------------ | |
|
74 | ||
|
75 | Extensions should register config items through the ``registrar`` API (also used | |
|
76 | for commands and others):: | |
|
77 | ||
|
78 | configtable = {} | |
|
79 | configitem = registrar.configitem(configtable) | |
|
80 | ||
|
81 | configitem('blackbox', 'dirty', | |
|
82 | default=False, | |
|
83 | ) | |
|
84 | ||
|
85 | The ``dynamicdefault`` object is then available as | |
|
86 | ``configitem.dynamicdefault``. | |
|
87 | ||
|
88 | Supporting older version | |
|
89 | ------------------------ | |
|
90 | ||
|
91 | The register was introduced in Mercurial 4.3, the ``generic`` parameter was | |
|
92 | introduced in 4.4. Starting with Mercurial 4.4, all core options were registered | |
|
93 | and developer warnings are emitted when accessing unregistered option. | |
|
94 | ||
|
95 | Extensions supporting version older than Mercurial-4.3 cannot rely on the | |
|
96 | default value registered. The simplest way to register option while still | |
|
97 | supporting older version is to use ``dynamicdefault`` for option requiring a | |
|
98 | default value. The existing code passing an explicit default can then stay in | |
|
99 | use until compatibility to Mercurial 4.2 is dropped. | |
|
100 | ||
|
101 | As reminder here are the default value for each config types: | |
|
102 | - config: None | |
|
103 | - configbool: False | |
|
104 | - configbytes: 0 | |
|
105 | - configdate: None | |
|
106 | - configint: None | |
|
107 | - configlist: [] | |
|
108 | - configpath: None |
@@ -42,6 +42,7 b'' | |||
|
42 | 42 | <File Id="internals.bundles.txt" Name="bundles.txt" KeyPath="yes" /> |
|
43 | 43 | <File Id="internals.censor.txt" Name="censor.txt" /> |
|
44 | 44 | <File Id="internals.changegroups.txt" Name="changegroups.txt" /> |
|
45 | <File Id="internals.config.txt" Name="config.txt" /> | |
|
45 | 46 | <File Id="internals.requirements.txt" Name="requirements.txt" /> |
|
46 | 47 | <File Id="internals.revlogs.txt" Name="revlogs.txt" /> |
|
47 | 48 | <File Id="internals.wireprotocol.txt" Name="wireprotocol.txt" /> |
@@ -202,6 +202,8 b' internalstable = sorted([' | |||
|
202 | 202 | loaddoc('censor', subdir='internals')), |
|
203 | 203 | (['changegroups'], _('Changegroups'), |
|
204 | 204 | loaddoc('changegroups', subdir='internals')), |
|
205 | (['config'], _('Config Register'), | |
|
206 | loaddoc('config', subdir='internals')), | |
|
205 | 207 | (['requirements'], _('Repository Requirements'), |
|
206 | 208 | loaddoc('requirements', subdir='internals')), |
|
207 | 209 | (['revlogs'], _('Revision Logs'), |
@@ -980,6 +980,7 b' internals topic renders index of availab' | |||
|
980 | 980 | bundles Bundles |
|
981 | 981 | censor Censor |
|
982 | 982 | changegroups Changegroups |
|
983 | config Config Register | |
|
983 | 984 | requirements Repository Requirements |
|
984 | 985 | revlogs Revision Logs |
|
985 | 986 | wireprotocol Wire Protocol |
@@ -3054,6 +3055,13 b' Sub-topic indexes rendered properly' | |||
|
3054 | 3055 | Changegroups |
|
3055 | 3056 | </td></tr> |
|
3056 | 3057 | <tr><td> |
|
3058 | <a href="/help/internals.config"> | |
|
3059 | config | |
|
3060 | </a> | |
|
3061 | </td><td> | |
|
3062 | Config Register | |
|
3063 | </td></tr> | |
|
3064 | <tr><td> | |
|
3057 | 3065 | <a href="/help/internals.requirements"> |
|
3058 | 3066 | requirements |
|
3059 | 3067 | </a> |
General Comments 0
You need to be logged in to leave comments.
Login now