Patchwork D7776: ui: add the ability to apply `defaultrc` configs from resources

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2020, 7:52 p.m.
Message ID <d401f964ed5a874b56c7ccf844b4fc3f@localhost.localdomain>
Download mbox | patch
Permalink /patch/44211/
State Not Applicable
Headers show

Comments

phabricator - Jan. 8, 2020, 7:52 p.m.
Closed by commit rHG1864efbe90d9: ui: add the ability to apply `defaultrc` configs from 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/D7776?vs=19007&id=19105

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

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

AFFECTED FILES
  mercurial/commands.py
  mercurial/rcutil.py
  mercurial/ui.py
  tests/test-config-env.py

CHANGE DETAILS




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

Patch

diff --git a/tests/test-config-env.py b/tests/test-config-env.py
--- a/tests/test-config-env.py
+++ b/tests/test-config-env.py
@@ -37,6 +37,7 @@ 
 
 
 extensions.wrapfunction(rcutil, 'defaultrcpath', lambda orig: [])
+extensions.wrapfunction(rcutil, 'default_rc_resources', lambda orig: [])
 
 rcutil.systemrcpath = systemrcpath
 rcutil.userrcpath = userrcpath
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -308,6 +308,8 @@ 
         for t, f in rcutil.rccomponents():
             if t == b'path':
                 u.readconfig(f, trust=True)
+            elif t == b'resource':
+                u.read_resource_config(f, trust=True)
             elif t == b'items':
                 sections = set()
                 for section, name, value, source in f:
diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py
--- a/mercurial/rcutil.py
+++ b/mercurial/rcutil.py
@@ -67,6 +67,17 @@ 
     return _expandrcpath(defaultpath)
 
 
+def default_rc_resources():
+    """return rc resource IDs in defaultrc"""
+    rsrcs = resourceutil.contents(b'mercurial.defaultrc')
+    return [
+        (b'mercurial.defaultrc', r)
+        for r in sorted(rsrcs)
+        if resourceutil.is_resource(b'mercurial.defaultrc', r)
+        and r.endswith(b'.rc')
+    ]
+
+
 def rccomponents():
     '''return an ordered [(type, obj)] about where to load configs.
 
@@ -75,9 +86,10 @@ 
 
     if a directory is provided, *.rc files under it will be used.
 
-    type could be either 'path' or 'items', if type is 'path', obj is a string,
-    and is the config file path. if type is 'items', obj is a list of (section,
-    name, value, source) that should fill the config directly.
+    type could be either 'path', 'items' or 'resource'. If type is 'path',
+    obj is a string, and is the config file path. if type is 'items', obj is a
+    list of (section, name, value, source) that should fill the config directly.
+    If type is 'resource', obj is a tuple of (package name, resource name).
     '''
     envrc = (b'items', envrcitems())
 
@@ -90,10 +102,12 @@ 
                 continue
             _rccomponents.extend((b'path', p) for p in _expandrcpath(p))
     else:
+        _rccomponents = [(b'resource', r) for r in default_rc_resources()]
+
         normpaths = lambda paths: [
             (b'path', os.path.normpath(p)) for p in paths
         ]
-        _rccomponents = normpaths(defaultrcpath() + systemrcpath())
+        _rccomponents.extend(normpaths(defaultrcpath() + systemrcpath()))
         _rccomponents.append(envrc)
         _rccomponents.extend(normpaths(userrcpath()))
     return _rccomponents
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2223,6 +2223,8 @@ 
     for t, f in rcutil.rccomponents():
         if t == b'path':
             ui.debug(b'read config from: %s\n' % f)
+        elif t == b'resource':
+            ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1]))
         elif t == b'items':
             # Don't print anything for 'items'.
             pass