##// END OF EJS Templates
configitems: add alias support in config...
David Demelier -
r33329:e7141598 default
parent child Browse files
Show More
@@ -32,12 +32,14 b' class configitem(object):'
32 32 :section: the official config section where to find this item,
33 33 :name: the official name within the section,
34 34 :default: default value for this item,
35 :alias: optional list of tuples as alternatives.
35 36 """
36 37
37 def __init__(self, section, name, default=None):
38 def __init__(self, section, name, default=None, alias=()):
38 39 self.section = section
39 40 self.name = name
40 41 self.default = default
42 self.alias = list(alias)
41 43
42 44 coreitems = {}
43 45
@@ -194,6 +196,9 b" coreconfigitem('ui', 'interactive',"
194 196 coreconfigitem('ui', 'quiet',
195 197 default=False,
196 198 )
199 coreconfigitem('ui', 'username',
200 alias=[('ui', 'user')]
201 )
197 202 # Windows defaults to a limit of 512 open files. A buffer of 128
198 203 # should give us enough headway.
199 204 coreconfigitem('worker', 'backgroundclosemaxqueue',
@@ -448,38 +448,39 b' class ui(object):'
448 448
449 449 def _config(self, section, name, default=_unset, untrusted=False):
450 450 value = default
451 if isinstance(name, list):
452 alternates = name
453 else:
454 item = self._knownconfig.get(section, {}).get(name)
455 if default is _unset:
456 if item is None:
457 value = default
458 elif callable(item.default):
451 item = self._knownconfig.get(section, {}).get(name)
452 alternates = [(section, name)]
453
454 if item is not None:
455 alternates.extend(item.alias)
456
457 if default is _unset:
458 if item is None:
459 value = default
460 elif callable(item.default):
459 461 value = item.default()
460 else:
461 value = item.default
462 elif item is not None:
463 msg = ("specifying a default value for a registered "
464 "config item: '%s.%s' '%s'")
465 msg %= (section, name, default)
466 self.develwarn(msg, 2, 'warn-config-default')
462 else:
463 value = item.default
464 elif item is not None:
465 msg = ("specifying a default value for a registered "
466 "config item: '%s.%s' '%s'")
467 msg %= (section, name, default)
468 self.develwarn(msg, 2, 'warn-config-default')
467 469
468 alternates = [name]
469
470 for n in alternates:
471 candidate = self._data(untrusted).get(section, n, None)
470 for s, n in alternates:
471 candidate = self._data(untrusted).get(s, n, None)
472 472 if candidate is not None:
473 473 value = candidate
474 section = s
474 475 name = n
475 476 break
476 477
477 478 if self.debugflag and not untrusted and self._reportuntrusted:
478 for n in alternates:
479 uvalue = self._ucfg.get(section, n)
479 for s, n in alternates:
480 uvalue = self._ucfg.get(s, n)
480 481 if uvalue is not None and uvalue != value:
481 482 self.debug("ignoring untrusted configuration option "
482 "%s.%s = %s\n" % (section, n, uvalue))
483 "%s.%s = %s\n" % (s, n, uvalue))
483 484 return value
484 485
485 486 def configsuboptions(self, section, name, default=_unset, untrusted=False):
@@ -744,7 +745,7 b' class ui(object):'
744 745 """
745 746 user = encoding.environ.get("HGUSER")
746 747 if user is None:
747 user = self.config("ui", ["username", "user"])
748 user = self.config("ui", "username")
748 749 if user is not None:
749 750 user = os.path.expandvars(user)
750 751 if user is None:
@@ -178,3 +178,36 b' config affected by environment variables'
178 178
179 179 $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager'
180 180 --config: pager.pager=p2
181
182 verify that aliases are evaluated as well
183
184 $ hg init aliastest
185 $ cd aliastest
186 $ cat > .hg/hgrc << EOF
187 > [ui]
188 > user = repo user
189 > EOF
190 $ touch index
191 $ unset HGUSER
192 $ hg ci -Am test
193 adding index
194 $ hg log --template '{author}\n'
195 repo user
196 $ cd ..
197
198 alias has lower priority
199
200 $ hg init aliaspriority
201 $ cd aliaspriority
202 $ cat > .hg/hgrc << EOF
203 > [ui]
204 > user = alias user
205 > username = repo user
206 > EOF
207 $ touch index
208 $ unset HGUSER
209 $ hg ci -Am test
210 adding index
211 $ hg log --template '{author}\n'
212 repo user
213 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now