Patchwork D7933: config: add a function to insert non-file based, but overridable settings

login
register
mail settings
Submitter phabricator
Date Jan. 17, 2020, 10:47 p.m.
Message ID <differential-rev-PHID-DREV-gvy2k6fzrucjileusr6l-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44509/
State Superseded
Headers show

Comments

phabricator - Jan. 17, 2020, 10:47 p.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will be used in the next patch.
  
  Until relatively recently (473510bf0575 <https://phab.mercurial-scm.org/rHG473510bf05750b4950978ce0c34f47a3af57fda7>), 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7933

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -467,6 +467,25 @@ 
                     raise
                 self.warn(_(b'ignored: %s\n') % stringutil.forcebytestr(inst))
 
+        self._applyconfig(cfg, trusted, root)
+
+    def applyconfig(self, configitems, source=b"", root=None):
+        """Add configitems from a non-file source.  Unlike with ``setconfig()``,
+        they can be overridden by subsequent config file reads.  The items are
+        in the same format as ``configoverride()``, namely a dict of the
+        following structures: {(section, name) : value}
+
+        Typically this is used by extensions that inject themselves into the
+        config file load procedure by monkeypatching ``localrepo.loadhgrc()``.
+        """
+        cfg = config.config()
+
+        for (section, name), value in configitems.items():
+            cfg.set(section, name, value, source)
+
+        self._applyconfig(cfg, True, root)
+
+    def _applyconfig(self, cfg, trusted, root):
         if self.plain():
             for k in (
                 b'debug',