Standardizing config option naming
Matt Mackall
mpm at selenic.com
Thu Aug 11 11:23:46 CDT 2011
On Thu, 2011-08-11 at 12:10 +0200, Martin Geisler wrote:
> Matt Mackall <mpm at selenic.com> writes:
>
> > So we've been fairly inconsistent with naming config options. It's
> > time to lay down the law here. And based on existing usage, the law
> > should be: no separator on new options.
>
> I like "foo-bar" much more than "foobar" and I've though of simply
> letting "-" and "_" be invisible: so the user can write "foo-bar" (and
> we would document it as such) but an old "foo_bar" or "foobar" would
> still work since the code uses "foobar" internally.
>
> I didn't come up with this out of the blue: zsh ignores all underscores
> in options:
>
> http://zsh.sourceforge.net/Doc/Release/Options.html
That's a little weird. I don't think it's a good fit here.
> > (My favorite is this one: web.allow_push vs web.allowpull)
>
> Yeah, that's a classic :-)
>
> > We should probably figure out how to normalize the existing options in
> > a backward-compatible way. This means removing the separators from the
> > docs and adding some sort of compatibility fallback for the old option
> > names. Though we need to be aware of conflicts like 'hooks.premerge'
> > (standard merge hook) vs 'hooks.pre-merge' (generic command hook).
>
> That is what stopped the above idea, plus the fact that there are some
> sections where the keys are freeform, such as merge-patterns. Maybe that
> could be solved by marking some sections as having significant keys?
We've actually got -a lot- of those sections.
My current thought is to let the config functions take a list of item
names and then manually fix up the roughly 10 options that use the wrong
style:
diff -r 72f312f41a4a mercurial/ui.py
--- a/mercurial/ui.py Wed Aug 10 13:52:52 2011 -0500
+++ b/mercurial/ui.py Thu Aug 11 11:19:11 2011 -0500
@@ -155,7 +155,19 @@
return self._data(untrusted).source(section, name) or 'none'
def config(self, section, name, default=None, untrusted=False):
- value = self._data(untrusted).get(section, name, default)
+ if isinstance(name, list):
+ alternates = name
+ else:
+ alternates = [name]
+
+ for n in alternates:
+ value = self._data(untrusted).get(section, name, None)
+ if value is not None:
+ name = n
+ break
+ else:
+ value = default
+
if self.debugflag and not untrusted and self._reportuntrusted:
uvalue = self._ucfg.get(section, name)
if uvalue is not None and uvalue != value:
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list