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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

marmoute (Pierre-Yves David)
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

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



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel