Show More
@@ -1,62 +1,70 b'' | |||
|
1 | 1 | # configitems.py - centralized declaration of configuration option |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import functools |
|
11 | 11 | |
|
12 | 12 | from . import ( |
|
13 | 13 | error, |
|
14 | 14 | ) |
|
15 | 15 | |
|
16 | 16 | def loadconfigtable(ui, extname, configtable): |
|
17 | 17 | """update config item known to the ui with the extension ones""" |
|
18 | 18 | for section, items in configtable.items(): |
|
19 |
ui._knownconfig.setdefault(section, {}) |
|
|
19 | knownitems = ui._knownconfig.setdefault(section, {}) | |
|
20 | knownkeys = set(knownitems) | |
|
21 | newkeys = set(items) | |
|
22 | for key in sorted(knownkeys & newkeys): | |
|
23 | msg = "extension '%s' overwrite config item '%s.%s'" | |
|
24 | msg %= (extname, section, key) | |
|
25 | ui.develwarn(msg, config='warn-config') | |
|
26 | ||
|
27 | knownitems.update(items) | |
|
20 | 28 | |
|
21 | 29 | class configitem(object): |
|
22 | 30 | """represent a known config item |
|
23 | 31 | |
|
24 | 32 | :section: the official config section where to find this item, |
|
25 | 33 | :name: the official name within the section, |
|
26 | 34 | :default: default value for this item, |
|
27 | 35 | """ |
|
28 | 36 | |
|
29 | 37 | def __init__(self, section, name, default=None): |
|
30 | 38 | self.section = section |
|
31 | 39 | self.name = name |
|
32 | 40 | self.default = default |
|
33 | 41 | |
|
34 | 42 | coreitems = {} |
|
35 | 43 | |
|
36 | 44 | def _register(configtable, *args, **kwargs): |
|
37 | 45 | item = configitem(*args, **kwargs) |
|
38 | 46 | section = configtable.setdefault(item.section, {}) |
|
39 | 47 | if item.name in section: |
|
40 | 48 | msg = "duplicated config item registration for '%s.%s'" |
|
41 | 49 | raise error.ProgrammingError(msg % (item.section, item.name)) |
|
42 | 50 | section[item.name] = item |
|
43 | 51 | |
|
44 | 52 | # Registering actual config items |
|
45 | 53 | |
|
46 | 54 | def getitemregister(configtable): |
|
47 | 55 | return functools.partial(_register, configtable) |
|
48 | 56 | |
|
49 | 57 | coreconfigitem = getitemregister(coreitems) |
|
50 | 58 | |
|
51 | 59 | coreconfigitem('patch', 'fuzz', |
|
52 | 60 | default=2, |
|
53 | 61 | ) |
|
54 | 62 | coreconfigitem('ui', 'clonebundleprefers', |
|
55 | 63 | default=[], |
|
56 | 64 | ) |
|
57 | 65 | coreconfigitem('ui', 'interactive', |
|
58 | 66 | default=None, |
|
59 | 67 | ) |
|
60 | 68 | coreconfigitem('ui', 'quiet', |
|
61 | 69 | default=False, |
|
62 | 70 | ) |
@@ -1,216 +1,228 b'' | |||
|
1 | 1 | |
|
2 | 2 | $ cat << EOF > buggylocking.py |
|
3 | 3 | > """A small extension that tests our developer warnings |
|
4 | 4 | > """ |
|
5 | 5 | > |
|
6 | 6 | > from mercurial import error, registrar, repair, util |
|
7 | 7 | > |
|
8 | 8 | > cmdtable = {} |
|
9 | 9 | > command = registrar.command(cmdtable) |
|
10 | 10 | > |
|
11 | 11 | > @command(b'buggylocking', [], '') |
|
12 | 12 | > def buggylocking(ui, repo): |
|
13 | 13 | > lo = repo.lock() |
|
14 | 14 | > wl = repo.wlock() |
|
15 | 15 | > wl.release() |
|
16 | 16 | > lo.release() |
|
17 | 17 | > |
|
18 | 18 | > @command(b'buggytransaction', [], '') |
|
19 | 19 | > def buggylocking(ui, repo): |
|
20 | 20 | > tr = repo.transaction('buggy') |
|
21 | 21 | > # make sure we rollback the transaction as we don't want to rely on the__del__ |
|
22 | 22 | > tr.release() |
|
23 | 23 | > |
|
24 | 24 | > @command(b'properlocking', [], '') |
|
25 | 25 | > def properlocking(ui, repo): |
|
26 | 26 | > """check that reentrance is fine""" |
|
27 | 27 | > wl = repo.wlock() |
|
28 | 28 | > lo = repo.lock() |
|
29 | 29 | > tr = repo.transaction('proper') |
|
30 | 30 | > tr2 = repo.transaction('proper') |
|
31 | 31 | > lo2 = repo.lock() |
|
32 | 32 | > wl2 = repo.wlock() |
|
33 | 33 | > wl2.release() |
|
34 | 34 | > lo2.release() |
|
35 | 35 | > tr2.close() |
|
36 | 36 | > tr.close() |
|
37 | 37 | > lo.release() |
|
38 | 38 | > wl.release() |
|
39 | 39 | > |
|
40 | 40 | > @command(b'nowaitlocking', [], '') |
|
41 | 41 | > def nowaitlocking(ui, repo): |
|
42 | 42 | > lo = repo.lock() |
|
43 | 43 | > wl = repo.wlock(wait=False) |
|
44 | 44 | > wl.release() |
|
45 | 45 | > lo.release() |
|
46 | 46 | > |
|
47 | 47 | > @command(b'stripintr', [], '') |
|
48 | 48 | > def stripintr(ui, repo): |
|
49 | 49 | > lo = repo.lock() |
|
50 | 50 | > tr = repo.transaction('foobar') |
|
51 | 51 | > try: |
|
52 | 52 | > repair.strip(repo.ui, repo, [repo['.'].node()]) |
|
53 | 53 | > finally: |
|
54 | 54 | > lo.release() |
|
55 | 55 | > @command(b'oldanddeprecated', [], '') |
|
56 | 56 | > def oldanddeprecated(ui, repo): |
|
57 | 57 | > """test deprecation warning API""" |
|
58 | 58 | > def foobar(ui): |
|
59 | 59 | > ui.deprecwarn('foorbar is deprecated, go shopping', '42.1337') |
|
60 | 60 | > foobar(ui) |
|
61 | 61 | > @command(b'nouiwarning', [], '') |
|
62 | 62 | > def nouiwarning(ui, repo): |
|
63 | 63 | > util.nouideprecwarn('this is a test', '13.37') |
|
64 | 64 | > @command(b'programmingerror', [], '') |
|
65 | 65 | > def programmingerror(ui, repo): |
|
66 | 66 | > raise error.ProgrammingError('something went wrong', hint='try again') |
|
67 | 67 | > EOF |
|
68 | 68 | |
|
69 | 69 | $ cat << EOF >> $HGRCPATH |
|
70 | 70 | > [extensions] |
|
71 | 71 | > buggylocking=$TESTTMP/buggylocking.py |
|
72 | 72 | > mock=$TESTDIR/mockblackbox.py |
|
73 | 73 | > blackbox= |
|
74 | 74 | > [devel] |
|
75 | 75 | > all-warnings=1 |
|
76 | 76 | > EOF |
|
77 | 77 | |
|
78 | 78 | $ hg init lock-checker |
|
79 | 79 | $ cd lock-checker |
|
80 | 80 | $ hg buggylocking |
|
81 | 81 | devel-warn: "wlock" acquired after "lock" at: $TESTTMP/buggylocking.py:* (buggylocking) (glob) |
|
82 | 82 | $ cat << EOF >> $HGRCPATH |
|
83 | 83 | > [devel] |
|
84 | 84 | > all=0 |
|
85 | 85 | > check-locks=1 |
|
86 | 86 | > EOF |
|
87 | 87 | $ hg buggylocking |
|
88 | 88 | devel-warn: "wlock" acquired after "lock" at: $TESTTMP/buggylocking.py:* (buggylocking) (glob) |
|
89 | 89 | $ hg buggylocking --traceback |
|
90 | 90 | devel-warn: "wlock" acquired after "lock" at: |
|
91 | 91 | */hg:* in * (glob) |
|
92 | 92 | */mercurial/dispatch.py:* in run (glob) |
|
93 | 93 | */mercurial/dispatch.py:* in dispatch (glob) |
|
94 | 94 | */mercurial/dispatch.py:* in _runcatch (glob) |
|
95 | 95 | */mercurial/dispatch.py:* in _callcatch (glob) |
|
96 | 96 | */mercurial/scmutil.py* in callcatch (glob) |
|
97 | 97 | */mercurial/dispatch.py:* in _runcatchfunc (glob) |
|
98 | 98 | */mercurial/dispatch.py:* in _dispatch (glob) |
|
99 | 99 | */mercurial/dispatch.py:* in runcommand (glob) |
|
100 | 100 | */mercurial/dispatch.py:* in _runcommand (glob) |
|
101 | 101 | */mercurial/dispatch.py:* in <lambda> (glob) |
|
102 | 102 | */mercurial/util.py:* in check (glob) |
|
103 | 103 | $TESTTMP/buggylocking.py:* in buggylocking (glob) |
|
104 | 104 | $ hg properlocking |
|
105 | 105 | $ hg nowaitlocking |
|
106 | 106 | |
|
107 | 107 | $ echo a > a |
|
108 | 108 | $ hg add a |
|
109 | 109 | $ hg commit -m a |
|
110 | 110 | $ hg stripintr 2>&1 | egrep -v '^(\*\*| )' |
|
111 | 111 | Traceback (most recent call last): |
|
112 | 112 | mercurial.error.ProgrammingError: cannot strip from inside a transaction |
|
113 | 113 | |
|
114 | 114 | $ hg oldanddeprecated |
|
115 | 115 | devel-warn: foorbar is deprecated, go shopping |
|
116 | 116 | (compatibility will be dropped after Mercurial-42.1337, update your code.) at: $TESTTMP/buggylocking.py:* (oldanddeprecated) (glob) |
|
117 | 117 | |
|
118 | 118 | $ hg oldanddeprecated --traceback |
|
119 | 119 | devel-warn: foorbar is deprecated, go shopping |
|
120 | 120 | (compatibility will be dropped after Mercurial-42.1337, update your code.) at: |
|
121 | 121 | */hg:* in <module> (glob) |
|
122 | 122 | */mercurial/dispatch.py:* in run (glob) |
|
123 | 123 | */mercurial/dispatch.py:* in dispatch (glob) |
|
124 | 124 | */mercurial/dispatch.py:* in _runcatch (glob) |
|
125 | 125 | */mercurial/dispatch.py:* in _callcatch (glob) |
|
126 | 126 | */mercurial/scmutil.py* in callcatch (glob) |
|
127 | 127 | */mercurial/dispatch.py:* in _runcatchfunc (glob) |
|
128 | 128 | */mercurial/dispatch.py:* in _dispatch (glob) |
|
129 | 129 | */mercurial/dispatch.py:* in runcommand (glob) |
|
130 | 130 | */mercurial/dispatch.py:* in _runcommand (glob) |
|
131 | 131 | */mercurial/dispatch.py:* in <lambda> (glob) |
|
132 | 132 | */mercurial/util.py:* in check (glob) |
|
133 | 133 | $TESTTMP/buggylocking.py:* in oldanddeprecated (glob) |
|
134 | 134 | $ hg blackbox -l 7 |
|
135 | 135 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> oldanddeprecated |
|
136 | 136 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> devel-warn: foorbar is deprecated, go shopping |
|
137 | 137 | (compatibility will be dropped after Mercurial-42.1337, update your code.) at: $TESTTMP/buggylocking.py:* (oldanddeprecated) (glob) |
|
138 | 138 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> oldanddeprecated exited 0 after * seconds (glob) |
|
139 | 139 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> oldanddeprecated --traceback |
|
140 | 140 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> devel-warn: foorbar is deprecated, go shopping |
|
141 | 141 | (compatibility will be dropped after Mercurial-42.1337, update your code.) at: |
|
142 | 142 | */hg:* in <module> (glob) |
|
143 | 143 | */mercurial/dispatch.py:* in run (glob) |
|
144 | 144 | */mercurial/dispatch.py:* in dispatch (glob) |
|
145 | 145 | */mercurial/dispatch.py:* in _runcatch (glob) |
|
146 | 146 | */mercurial/dispatch.py:* in _callcatch (glob) |
|
147 | 147 | */mercurial/scmutil.py* in callcatch (glob) |
|
148 | 148 | */mercurial/dispatch.py:* in _runcatchfunc (glob) |
|
149 | 149 | */mercurial/dispatch.py:* in _dispatch (glob) |
|
150 | 150 | */mercurial/dispatch.py:* in runcommand (glob) |
|
151 | 151 | */mercurial/dispatch.py:* in _runcommand (glob) |
|
152 | 152 | */mercurial/dispatch.py:* in <lambda> (glob) |
|
153 | 153 | */mercurial/util.py:* in check (glob) |
|
154 | 154 | $TESTTMP/buggylocking.py:* in oldanddeprecated (glob) |
|
155 | 155 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> oldanddeprecated --traceback exited 0 after * seconds (glob) |
|
156 | 156 | 1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> blackbox -l 7 |
|
157 | 157 | |
|
158 | 158 | Test programming error failure: |
|
159 | 159 | |
|
160 | 160 | $ hg buggytransaction 2>&1 | egrep -v '^ ' |
|
161 | 161 | ** Unknown exception encountered with possibly-broken third-party extension buggylocking |
|
162 | 162 | ** which supports versions unknown of Mercurial. |
|
163 | 163 | ** Please disable buggylocking and try your action again. |
|
164 | 164 | ** If that fixes the bug please report it to the extension author. |
|
165 | 165 | ** Python * (glob) |
|
166 | 166 | ** Mercurial Distributed SCM (*) (glob) |
|
167 | 167 | ** Extensions loaded: * (glob) |
|
168 | 168 | ** ProgrammingError: transaction requires locking |
|
169 | 169 | Traceback (most recent call last): |
|
170 | 170 | mercurial.error.ProgrammingError: transaction requires locking |
|
171 | 171 | |
|
172 | 172 | $ hg programmingerror 2>&1 | egrep -v '^ ' |
|
173 | 173 | ** Unknown exception encountered with possibly-broken third-party extension buggylocking |
|
174 | 174 | ** which supports versions unknown of Mercurial. |
|
175 | 175 | ** Please disable buggylocking and try your action again. |
|
176 | 176 | ** If that fixes the bug please report it to the extension author. |
|
177 | 177 | ** Python * (glob) |
|
178 | 178 | ** Mercurial Distributed SCM (*) (glob) |
|
179 | 179 | ** Extensions loaded: * (glob) |
|
180 | 180 | ** ProgrammingError: something went wrong |
|
181 | 181 | ** (try again) |
|
182 | 182 | Traceback (most recent call last): |
|
183 | 183 | mercurial.error.ProgrammingError: something went wrong |
|
184 | 184 | |
|
185 | 185 | Old style deprecation warning |
|
186 | 186 | |
|
187 | 187 | $ hg nouiwarning |
|
188 | 188 | $TESTTMP/buggylocking.py:61: DeprecationWarning: this is a test |
|
189 | 189 | (compatibility will be dropped after Mercurial-13.37, update your code.) |
|
190 | 190 | util.nouideprecwarn('this is a test', '13.37') |
|
191 | 191 | |
|
192 | 192 | (disabled outside of test run) |
|
193 | 193 | |
|
194 | 194 | $ HGEMITWARNINGS= hg nouiwarning |
|
195 | 195 | |
|
196 | 196 | Test warning on config option access and registration |
|
197 | 197 | |
|
198 | 198 | $ cat << EOF > ${TESTTMP}/buggyconfig.py |
|
199 | 199 | > """A small extension that tests our developer warnings for config""" |
|
200 | 200 | > |
|
201 | 201 | > from mercurial import registrar |
|
202 | 202 | > |
|
203 | 203 | > cmdtable = {} |
|
204 | 204 | > command = registrar.command(cmdtable) |
|
205 | 205 | > |
|
206 | > configtable = {} | |
|
207 | > configitem = registrar.configitem(configtable) | |
|
208 | > | |
|
209 | > configitem('test', 'some', default='foo') | |
|
210 | > # overwrite a core config | |
|
211 | > configitem('ui', 'quiet', default=False) | |
|
212 | > configitem('ui', 'interactive', default=None) | |
|
213 | > | |
|
206 | 214 | > @command(b'buggyconfig') |
|
207 | 215 | > def cmdbuggyconfig(ui, repo): |
|
208 | 216 | > repo.ui.config('ui', 'quiet', False) |
|
209 | 217 | > repo.ui.config('ui', 'interactive', None) |
|
218 | > repo.ui.config('test', 'some', 'foo') | |
|
210 | 219 | > EOF |
|
211 | 220 | |
|
212 | 221 | $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig |
|
222 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.interactive' at: */mercurial/extensions.py:* (loadall) (glob) | |
|
223 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.quiet' at: */mercurial/extensions.py:* (loadall) (glob) | |
|
213 | 224 | devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
214 | 225 | devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
226 | devel-warn: specifying a default value for a registered config item: 'test.some' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
|
215 | 227 | |
|
216 | 228 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now