Patchwork D10262: path: extract sub-option logic into its own method

login
register
mail settings
Submitter phabricator
Date March 24, 2021, 8:52 a.m.
Message ID <differential-rev-PHID-DREV-63udf7v42vpfdwbz3vlp-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48577/
State Superseded
Headers show

Comments

phabricator - March 24, 2021, 8:52 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We will need to re-use this logic for `path://` so we first extract it into its own method.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -2323,19 +2323,13 @@ 
         self._validate_path()
 
         _path, sub_opts = ui.configsuboptions(b'paths', b'*')
+        self._own_sub_opts = {}
         if suboptions is not None:
+            self._own_sub_opts = suboptions.copy()
             sub_opts.update(suboptions)
+        self._all_sub_opts = sub_opts.copy()
 
-        # 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 sub_opts:
-                setattr(self, attr, None)
-                continue
-
-            value = func(ui, self, sub_opts[suboption])
-            setattr(self, attr, value)
+        self._apply_suboptions(ui, sub_opts)
 
     def _validate_path(self):
         # When given a raw location but not a symbolic name, validate the
@@ -2350,6 +2344,18 @@ 
                 b'repo: %s' % self.rawloc
             )
 
+    def _apply_suboptions(self, ui, sub_options):
+        # 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 sub_options:
+                setattr(self, attr, None)
+                continue
+
+            value = func(ui, self, sub_options[suboption])
+            setattr(self, attr, value)
+
     def _isvalidlocalpath(self, path):
         """Returns True if the given path is a potentially valid repository.
         This is its own function so that extensions can change the definition of