Patchwork D7628: config: move reading of defaultrc/ files from ui to rcutil

login
register
mail settings
Submitter phabricator
Date Dec. 12, 2019, 11:44 p.m.
Message ID <differential-rev-PHID-DREV-3wwo56iuhu4supwuas2j-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43767/
State Superseded
Headers show

Comments

phabricator - Dec. 12, 2019, 11:44 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  For PyOxidizer, we'll need to read the default configs using the
  `resources` module. This prepares for putting that call in rcutil.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/rcutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Dec. 23, 2019, 5:28 p.m.
indygreg added a comment.


  The patch seems functionally correct. But I have a question about whether this is the desired approach. See inline comment.

INLINE COMMENTS

> rcutil.py:102
> +                    default_entries.append((section, name, value, source))
> +        _rccomponents = [(b'items', default_entries)]
> +

Do you think it would be better to change the return type to expose a `resource` type, which the caller can resolve accordingly? Or maybe do away with leaving it up to the caller to open and read paths? It just feels weird for some I/O to be performed in this function while some I/O is deferred to the caller.

But I don't have this code paged in, so maybe my comment is off base.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers
Cc: indygreg, mercurial-devel
phabricator - Jan. 23, 2020, 10:04 p.m.
martinvonz added a comment.
martinvonz abandoned this revision.


  This was probably also obsoleted by D7629 <https://phab.mercurial-scm.org/D7629>

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py
--- a/mercurial/rcutil.py
+++ b/mercurial/rcutil.py
@@ -10,6 +10,7 @@ 
 import os
 
 from . import (
+    config,
     encoding,
     pycompat,
     util,
@@ -90,10 +91,20 @@ 
                 continue
             _rccomponents.extend((b'path', p) for p in _expandrcpath(p))
     else:
+        default_entries = []
+        for path in defaultrcpath():
+            cfg = config.config()
+            cfg.read(path)
+            for section in cfg:
+                for name, value in cfg.items(section):
+                    source = cfg.source(section, name)
+                    default_entries.append((section, name, value, source))
+        _rccomponents = [(b'items', default_entries)]
+
         normpaths = lambda paths: [
             (b'path', os.path.normpath(p)) for p in paths
         ]
-        _rccomponents = normpaths(defaultrcpath() + systemrcpath())
+        _rccomponents.extend(normpaths(systemrcpath()))
         _rccomponents.append(envrc)
         _rccomponents.extend(normpaths(userrcpath()))
     return _rccomponents