comparison mercurial/ui.py @ 32976:4a3f1d362e5f

config: explicitly track the use of the standard default value We introduce a small object used to detect that no specific default value has been passed to 'ui.config'. We need this explicit special value since "None" is a valid and common default value. The end goal here is to make progress on a centralised and explicit declaration of the available config option. A first good usecase for this are "default" value. Before starting looking further down this alley we needs to rework the handling of default value in the 'ui' object to have all configxyz methods going through the same logic. This is the first changeset on this trek.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 17 Jun 2017 12:51:11 +0200
parents 9fcb6df413c9
children b39dafe681df
comparison
equal deleted inserted replaced
32975:067173e3c8a6 32976:4a3f1d362e5f
151 def find_user_password(self, *args, **kwargs): 151 def find_user_password(self, *args, **kwargs):
152 return self._get_mgr().find_user_password(*args, **kwargs) 152 return self._get_mgr().find_user_password(*args, **kwargs)
153 153
154 def _catchterm(*args): 154 def _catchterm(*args):
155 raise error.SignalInterrupt 155 raise error.SignalInterrupt
156
157 # unique object used to detect no default value has been provided when
158 # retrieving configuration value.
159 _unset = object()
156 160
157 class ui(object): 161 class ui(object):
158 def __init__(self, src=None): 162 def __init__(self, src=None):
159 """Create a fresh new ui object if no src given 163 """Create a fresh new ui object if no src given
160 164
430 return untrusted and self._ucfg or self._tcfg 434 return untrusted and self._ucfg or self._tcfg
431 435
432 def configsource(self, section, name, untrusted=False): 436 def configsource(self, section, name, untrusted=False):
433 return self._data(untrusted).source(section, name) 437 return self._data(untrusted).source(section, name)
434 438
435 def config(self, section, name, default=None, untrusted=False): 439 def config(self, section, name, default=_unset, untrusted=False):
440 if default is _unset:
441 default = None
436 if isinstance(name, list): 442 if isinstance(name, list):
437 alternates = name 443 alternates = name
438 else: 444 else:
439 alternates = [name] 445 alternates = [name]
440 446