[PATCH 3 of 6 V2] ui: add hasconfig method to check if a config item is set
Matt Mackall
mpm at selenic.com
Wed Apr 8 14:20:21 CDT 2015
On Tue, 2015-04-07 at 21:00 +0200, mathias.demare at gmail.com wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare at gmail.com>
> # Date 1428348883 -7200
> # Mon Apr 06 21:34:43 2015 +0200
> # Node ID 29f1d521db03dea5d14aa4d3cbd6705e038849d5
> # Parent 411bfd6b77b418249d42817816b3a2526863b0b0
> ui: add hasconfig method to check if a config item is set
>
> diff -r 411bfd6b77b4 -r 29f1d521db03 mercurial/ui.py
> --- a/mercurial/ui.py Mon Apr 06 21:32:27 2015 +0200
> +++ b/mercurial/ui.py Mon Apr 06 21:34:43 2015 +0200
> @@ -456,6 +456,11 @@
> '''tell whether section exists in config.'''
> return section in self._data(untrusted)
>
> + def hasconfig(self, section, config, untrusted=False):
> + '''tell whether config item exists in config.'''
> + return self.has_section(section, untrusted) \
> + and config in self._data(untrusted)[section]
> +
A better way to do this is:
if ui.config("foo", "bar", None) != None
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list