Show More
@@ -32,12 +32,14 b' class configitem(object):' | |||||
32 | :section: the official config section where to find this item, |
|
32 | :section: the official config section where to find this item, | |
33 | :name: the official name within the section, |
|
33 | :name: the official name within the section, | |
34 | :default: default value for this item, |
|
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 | self.section = section |
|
39 | self.section = section | |
39 | self.name = name |
|
40 | self.name = name | |
40 | self.default = default |
|
41 | self.default = default | |
|
42 | self.alias = list(alias) | |||
41 |
|
43 | |||
42 | coreitems = {} |
|
44 | coreitems = {} | |
43 |
|
45 | |||
@@ -194,6 +196,9 b" coreconfigitem('ui', 'interactive'," | |||||
194 | coreconfigitem('ui', 'quiet', |
|
196 | coreconfigitem('ui', 'quiet', | |
195 | default=False, |
|
197 | default=False, | |
196 | ) |
|
198 | ) | |
|
199 | coreconfigitem('ui', 'username', | |||
|
200 | alias=[('ui', 'user')] | |||
|
201 | ) | |||
197 | # Windows defaults to a limit of 512 open files. A buffer of 128 |
|
202 | # Windows defaults to a limit of 512 open files. A buffer of 128 | |
198 | # should give us enough headway. |
|
203 | # should give us enough headway. | |
199 | coreconfigitem('worker', 'backgroundclosemaxqueue', |
|
204 | coreconfigitem('worker', 'backgroundclosemaxqueue', |
@@ -448,38 +448,39 b' class ui(object):' | |||||
448 |
|
448 | |||
449 | def _config(self, section, name, default=_unset, untrusted=False): |
|
449 | def _config(self, section, name, default=_unset, untrusted=False): | |
450 | value = default |
|
450 | value = default | |
451 | if isinstance(name, list): |
|
451 | item = self._knownconfig.get(section, {}).get(name) | |
452 |
|
|
452 | alternates = [(section, name)] | |
453 | else: |
|
453 | ||
454 | item = self._knownconfig.get(section, {}).get(name) |
|
454 | if item is not None: | |
455 | if default is _unset: |
|
455 | alternates.extend(item.alias) | |
456 | if item is None: |
|
456 | ||
457 | value = default |
|
457 | if default is _unset: | |
458 | elif callable(item.default): |
|
458 | if item is None: | |
|
459 | value = default | |||
|
460 | elif callable(item.default): | |||
459 | value = item.default() |
|
461 | value = item.default() | |
460 |
|
|
462 | else: | |
461 |
|
|
463 | value = item.default | |
462 |
|
|
464 | elif item is not None: | |
463 |
|
|
465 | msg = ("specifying a default value for a registered " | |
464 |
|
|
466 | "config item: '%s.%s' '%s'") | |
465 |
|
|
467 | msg %= (section, name, default) | |
466 |
|
|
468 | self.develwarn(msg, 2, 'warn-config-default') | |
467 |
|
469 | |||
468 |
alternates |
|
470 | for s, n in alternates: | |
469 |
|
471 | candidate = self._data(untrusted).get(s, n, None) | ||
470 | for n in alternates: |
|
|||
471 | candidate = self._data(untrusted).get(section, n, None) |
|
|||
472 | if candidate is not None: |
|
472 | if candidate is not None: | |
473 | value = candidate |
|
473 | value = candidate | |
|
474 | section = s | |||
474 | name = n |
|
475 | name = n | |
475 | break |
|
476 | break | |
476 |
|
477 | |||
477 | if self.debugflag and not untrusted and self._reportuntrusted: |
|
478 | if self.debugflag and not untrusted and self._reportuntrusted: | |
478 | for n in alternates: |
|
479 | for s, n in alternates: | |
479 |
uvalue = self._ucfg.get(s |
|
480 | uvalue = self._ucfg.get(s, n) | |
480 | if uvalue is not None and uvalue != value: |
|
481 | if uvalue is not None and uvalue != value: | |
481 | self.debug("ignoring untrusted configuration option " |
|
482 | self.debug("ignoring untrusted configuration option " | |
482 |
"%s.%s = %s\n" % (s |
|
483 | "%s.%s = %s\n" % (s, n, uvalue)) | |
483 | return value |
|
484 | return value | |
484 |
|
485 | |||
485 | def configsuboptions(self, section, name, default=_unset, untrusted=False): |
|
486 | def configsuboptions(self, section, name, default=_unset, untrusted=False): | |
@@ -744,7 +745,7 b' class ui(object):' | |||||
744 | """ |
|
745 | """ | |
745 | user = encoding.environ.get("HGUSER") |
|
746 | user = encoding.environ.get("HGUSER") | |
746 | if user is None: |
|
747 | if user is None: | |
747 |
user = self.config("ui", |
|
748 | user = self.config("ui", "username") | |
748 | if user is not None: |
|
749 | if user is not None: | |
749 | user = os.path.expandvars(user) |
|
750 | user = os.path.expandvars(user) | |
750 | if user is None: |
|
751 | if user is None: |
@@ -178,3 +178,36 b' config affected by environment variables' | |||||
178 |
|
178 | |||
179 | $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager' |
|
179 | $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager' | |
180 | --config: pager.pager=p2 |
|
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