##// END OF EJS Templates
ui: add support for a tweakdefaults knob...
Augie Fackler -
r32872:9fcb6df4 default
parent child Browse files
Show More
@@ -2093,6 +2093,15 b' User interface controls.'
2093 on all exceptions, even those recognized by Mercurial (such as
2093 on all exceptions, even those recognized by Mercurial (such as
2094 IOError or MemoryError). (default: False)
2094 IOError or MemoryError). (default: False)
2095
2095
2096 ``tweakdefaults``
2097
2098 By default Mercurial's behavior changes very little from release
2099 to release, but over time the recommended config settings
2100 shift. Enable this config to opt in to get automatic tweaks to
2101 Mercurial's behavior over time. This config setting will have no
2102 effet if ``HGPLAIN` is set or ``HGPLAINEXCEPT`` is set and does
2103 not include ``tweakdefaults``. (default: False)
2104
2096 ``username``
2105 ``username``
2097 The committer of a changeset created when running "commit".
2106 The committer of a changeset created when running "commit".
2098 Typically a person's name and email address, e.g. ``Fred Widget
2107 Typically a person's name and email address, e.g. ``Fred Widget
@@ -43,6 +43,20 b' urlreq = util.urlreq'
43 _keepalnum = ''.join(c for c in map(pycompat.bytechr, range(256))
43 _keepalnum = ''.join(c for c in map(pycompat.bytechr, range(256))
44 if not c.isalnum())
44 if not c.isalnum())
45
45
46 # The config knobs that will be altered (if unset) by ui.tweakdefaults.
47 tweakrc = """
48 [ui]
49 # The rollback command is dangerous. As a rule, don't use it.
50 rollback = False
51
52 [commands]
53 # Make `hg status` emit cwd-relative paths by default.
54 status.relative = yes
55
56 [diff]
57 git = 1
58 """
59
46 samplehgrcs = {
60 samplehgrcs = {
47 'user':
61 'user':
48 """# example user config (see 'hg help config' for more info)
62 """# example user config (see 'hg help config' for more info)
@@ -182,6 +196,7 b' class ui(object):'
182 self.fin = src.fin
196 self.fin = src.fin
183 self.pageractive = src.pageractive
197 self.pageractive = src.pageractive
184 self._disablepager = src._disablepager
198 self._disablepager = src._disablepager
199 self._tweaked = src._tweaked
185
200
186 self._tcfg = src._tcfg.copy()
201 self._tcfg = src._tcfg.copy()
187 self._ucfg = src._ucfg.copy()
202 self._ucfg = src._ucfg.copy()
@@ -205,6 +220,7 b' class ui(object):'
205 self.fin = util.stdin
220 self.fin = util.stdin
206 self.pageractive = False
221 self.pageractive = False
207 self._disablepager = False
222 self._disablepager = False
223 self._tweaked = False
208
224
209 # shared read-only environment
225 # shared read-only environment
210 self.environ = encoding.environ
226 self.environ = encoding.environ
@@ -241,8 +257,29 b' class ui(object):'
241 u.fixconfig(section=section)
257 u.fixconfig(section=section)
242 else:
258 else:
243 raise error.ProgrammingError('unknown rctype: %s' % t)
259 raise error.ProgrammingError('unknown rctype: %s' % t)
260 u._maybetweakdefaults()
244 return u
261 return u
245
262
263 def _maybetweakdefaults(self):
264 if not self.configbool('ui', 'tweakdefaults'):
265 return
266 if self._tweaked or self.plain('tweakdefaults'):
267 return
268
269 # Note: it is SUPER IMPORTANT that you set self._tweaked to
270 # True *before* any calls to setconfig(), otherwise you'll get
271 # infinite recursion between setconfig and this method.
272 #
273 # TODO: We should extract an inner method in setconfig() to
274 # avoid this weirdness.
275 self._tweaked = True
276 tmpcfg = config.config()
277 tmpcfg.parse('<tweakdefaults>', tweakrc)
278 for section in tmpcfg:
279 for name, value in tmpcfg.items(section):
280 if not self.hasconfig(section, name):
281 self.setconfig(section, name, value, "<tweakdefaults>")
282
246 def copy(self):
283 def copy(self):
247 return self.__class__(self)
284 return self.__class__(self)
248
285
@@ -387,6 +424,7 b' class ui(object):'
387 for cfg in (self._ocfg, self._tcfg, self._ucfg):
424 for cfg in (self._ocfg, self._tcfg, self._ucfg):
388 cfg.set(section, name, value, source)
425 cfg.set(section, name, value, source)
389 self.fixconfig(section=section)
426 self.fixconfig(section=section)
427 self._maybetweakdefaults()
390
428
391 def _data(self, untrusted):
429 def _data(self, untrusted):
392 return untrusted and self._ucfg or self._tcfg
430 return untrusted and self._ucfg or self._tcfg
@@ -107,6 +107,29 b' combining patterns with root and pattern'
107 ? a/in_a
107 ? a/in_a
108 ? b/in_b
108 ? b/in_b
109
109
110 tweaking defaults works
111 $ hg status --cwd a --config ui.tweakdefaults=yes
112 ? 1/in_a_1
113 ? in_a
114 ? ../b/1/in_b_1
115 ? ../b/2/in_b_2
116 ? ../b/in_b
117 ? ../in_root
118 $ HGPLAIN=1 hg status --cwd a --config ui.tweakdefaults=yes
119 ? a/1/in_a_1 (glob)
120 ? a/in_a (glob)
121 ? b/1/in_b_1 (glob)
122 ? b/2/in_b_2 (glob)
123 ? b/in_b (glob)
124 ? in_root
125 $ HGPLAINEXCEPT=tweakdefaults hg status --cwd a --config ui.tweakdefaults=yes
126 ? 1/in_a_1
127 ? in_a
128 ? ../b/1/in_b_1
129 ? ../b/2/in_b_2
130 ? ../b/in_b
131 ? ../in_root
132
110 relative paths can be requested
133 relative paths can be requested
111
134
112 $ cat >> $HGRCPATH <<EOF
135 $ cat >> $HGRCPATH <<EOF
@@ -128,6 +151,19 b' relative paths can be requested'
128 ? b/in_b (glob)
151 ? b/in_b (glob)
129 ? in_root
152 ? in_root
130
153
154 if relative paths are explicitly off, tweakdefaults doesn't change it
155 $ cat >> $HGRCPATH <<EOF
156 > [commands]
157 > status.relative = False
158 > EOF
159 $ hg status --cwd a --config ui.tweakdefaults=yes
160 ? a/1/in_a_1 (glob)
161 ? a/in_a (glob)
162 ? b/1/in_b_1 (glob)
163 ? b/2/in_b_2 (glob)
164 ? b/in_b (glob)
165 ? in_root
166
131 $ cd ..
167 $ cd ..
132
168
133 $ hg init repo2
169 $ hg init repo2
General Comments 0
You need to be logged in to leave comments. Login now