comparison mercurial/ui.py @ 27252:dccbebcff075

ui: add method to return option and all sub-options Apparently ":" has been blessed as a generic separator for options and sub-options. We formalize this by introducing an API for obtaining an option and all its sub-options. This will be used in a subsequent patch for declaring sub-options for [paths].
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 05 Dec 2015 20:20:57 -0800
parents 3553e40d0770
children f43988e5954c
comparison
equal deleted inserted replaced
27251:d9bfe6289acf 27252:dccbebcff075
277 uvalue = self._ucfg.get(section, n) 277 uvalue = self._ucfg.get(section, n)
278 if uvalue is not None and uvalue != value: 278 if uvalue is not None and uvalue != value:
279 self.debug("ignoring untrusted configuration option " 279 self.debug("ignoring untrusted configuration option "
280 "%s.%s = %s\n" % (section, n, uvalue)) 280 "%s.%s = %s\n" % (section, n, uvalue))
281 return value 281 return value
282
283 def configsuboptions(self, section, name, default=None, untrusted=False):
284 """Get a config option and all sub-options.
285
286 Some config options have sub-options that are declared with the
287 format "key:opt = value". This method is used to return the main
288 option and all its declared sub-options.
289
290 Returns a 2-tuple of ``(option, sub-options)``, where `sub-options``
291 is a dict of defined sub-options where keys and values are strings.
292 """
293 data = self._data(untrusted)
294 main = data.get(section, name, default)
295 if self.debugflag and not untrusted and self._reportuntrusted:
296 uvalue = self._ucfg.get(section, name)
297 if uvalue is not None and uvalue != main:
298 self.debug('ignoring untrusted configuration option '
299 '%s.%s = %s\n' % (section, name, uvalue))
300
301 sub = {}
302 prefix = '%s:' % name
303 for k, v in data.items(section):
304 if k.startswith(prefix):
305 sub[k[len(prefix):]] = v
306
307 if self.debugflag and not untrusted and self._reportuntrusted:
308 for k, v in sub.items():
309 uvalue = self._ucfg.get(section, '%s:%s' % (name, k))
310 if uvalue is not None and uvalue != v:
311 self.debug('ignoring untrusted configuration option '
312 '%s:%s.%s = %s\n' % (section, name, k, uvalue))
313
314 return main, sub
282 315
283 def configpath(self, section, name, default=None, untrusted=False): 316 def configpath(self, section, name, default=None, untrusted=False):
284 'get a path config item, expanded relative to repo root or config file' 317 'get a path config item, expanded relative to repo root or config file'
285 v = self.config(section, name, default, untrusted) 318 v = self.config(section, name, default, untrusted)
286 if v is None: 319 if v is None: