D7775: ui: refactor `readconfig()` into a form that can consume resources

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Wed Jan 8 14:52:01 EST 2020


Closed by commit rHG5ac0e6f19eb4: ui: refactor `readconfig()` into a form that can consume resources (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7775?vs=19006&id=19104

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7775/new/

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

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -45,6 +45,7 @@
 from .utils import (
     dateutil,
     procutil,
+    resourceutil,
     stringutil,
 )
 
@@ -424,6 +425,20 @@
             )
         return False
 
+    def read_resource_config(
+        self, name, root=None, trust=False, sections=None, remap=None
+    ):
+        try:
+            fp = resourceutil.open_resource(name[0], name[1])
+        except IOError:
+            if not sections:  # ignore unless we were looking for something
+                return
+            raise
+
+        self._readconfig(
+            b'resource:%s.%s' % name, fp, root, trust, sections, remap
+        )
+
     def readconfig(
         self, filename, root=None, trust=False, sections=None, remap=None
     ):
@@ -434,6 +449,11 @@
                 return
             raise
 
+        self._readconfig(filename, fp, root, trust, sections, remap)
+
+    def _readconfig(
+        self, filename, fp, root=None, trust=False, sections=None, remap=None
+    ):
         with fp:
             cfg = config.config()
             trusted = sections or trust or self._trusted(fp, filename)



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


More information about the Mercurial-devel mailing list