comparison mercurial/ui.py @ 44126:e2278581b1c6

config: add a function to insert non-file based, but overridable settings This will be used in the next patch. Until relatively recently (473510bf0575), there was no official way for extensions to inject per-repo config data, so it probably makes sense that `ui.setconfig()` items are sticky, and not affected by loading more config files. But that makes it cumbersome if the extension wants to allow the data it might add to be overridden by any data in the local hgrc file. The only thing I could get to work was to load the local hgrc first, and then check if the source for the config item that should be overridden was *not* the local hgrc file name. But that's brittle because in addition to the file name, the source contains the line number, there are the usual '\' vs '/' platform differences, etc. Differential Revision: https://phab.mercurial-scm.org/D7933
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 17 Jan 2020 13:29:47 -0500
parents 1864efbe90d9
children df2162672d24 c23877cb25a5
comparison
equal deleted inserted replaced
44125:a5e3f38407cb 44126:e2278581b1c6
465 except error.ParseError as inst: 465 except error.ParseError as inst:
466 if trusted: 466 if trusted:
467 raise 467 raise
468 self.warn(_(b'ignored: %s\n') % stringutil.forcebytestr(inst)) 468 self.warn(_(b'ignored: %s\n') % stringutil.forcebytestr(inst))
469 469
470 self._applyconfig(cfg, trusted, root)
471
472 def applyconfig(self, configitems, source=b"", root=None):
473 """Add configitems from a non-file source. Unlike with ``setconfig()``,
474 they can be overridden by subsequent config file reads. The items are
475 in the same format as ``configoverride()``, namely a dict of the
476 following structures: {(section, name) : value}
477
478 Typically this is used by extensions that inject themselves into the
479 config file load procedure by monkeypatching ``localrepo.loadhgrc()``.
480 """
481 cfg = config.config()
482
483 for (section, name), value in configitems.items():
484 cfg.set(section, name, value, source)
485
486 self._applyconfig(cfg, True, root)
487
488 def _applyconfig(self, cfg, trusted, root):
470 if self.plain(): 489 if self.plain():
471 for k in ( 490 for k in (
472 b'debug', 491 b'debug',
473 b'fallbackencoding', 492 b'fallbackencoding',
474 b'quiet', 493 b'quiet',