D10260: path: move handling of "default" (*) suboptions value inside __init__

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Mar 24 08:52:26 UTC 2021


marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  With the introduction of `path://` scheme the handling of default value will need to be subtler. We do simple code movement first to clarify the future changes.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -2190,16 +2190,12 @@
     def __init__(self, ui):
         dict.__init__(self)
 
-        _path, base_sub_options = ui.configsuboptions(b'paths', b'*')
         for name, loc in ui.configitems(b'paths', ignoresub=True):
             # No location is the same as not existing.
             if not loc:
                 continue
-            loc, sub = ui.configsuboptions(b'paths', name)
-            sub_opts = base_sub_options.copy()
-            sub_opts.update(sub)
+            loc, sub_opts = ui.configsuboptions(b'paths', name)
             self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
-        self._default_sub_opts = base_sub_options
 
     def getpath(self, ui, name, default=None):
         """Return a ``path`` from a string, falling back to default.
@@ -2234,9 +2230,7 @@
             # Try to resolve as a local path or URI.
             try:
                 # we pass the ui instance are warning might need to be issued
-                return path(
-                    ui, None, rawloc=name, suboptions=self._default_sub_opts
-                )
+                return path(ui, None, rawloc=name)
             except ValueError:
                 raise error.RepoError(_(b'repository %s does not exist') % name)
 
@@ -2334,17 +2328,19 @@
                 b'repo: %s' % rawloc
             )
 
-        suboptions = suboptions or {}
+        _path, sub_opts = ui.configsuboptions(b'paths', b'*')
+        if suboptions is not None:
+            sub_opts.update(suboptions)
 
         # Now process the sub-options. If a sub-option is registered, its
         # attribute will always be present. The value will be None if there
         # was no valid sub-option.
         for suboption, (attr, func) in pycompat.iteritems(_pathsuboptions):
-            if suboption not in suboptions:
+            if suboption not in sub_opts:
                 setattr(self, attr, None)
                 continue
 
-            value = func(ui, self, suboptions[suboption])
+            value = func(ui, self, sub_opts[suboption])
             setattr(self, attr, value)
 
     def _isvalidlocalpath(self, path):



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list