Mercurial > hg
diff mercurial/ui.py @ 46825:4821cb414a5c
path: extract sub-option logic into its own method
We will need to re-use this logic for `path://` so we first extract it into its own method.
Differential Revision: https://phab.mercurial-scm.org/D10262
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 21 Mar 2021 16:31:42 +0100 |
parents | 57218b7ffb2a |
children | 83b0a5c0dfec |
line wrap: on
line diff
--- a/mercurial/ui.py Sun Mar 21 17:52:15 2021 +0100 +++ b/mercurial/ui.py Sun Mar 21 16:31:42 2021 +0100 @@ -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