comparison 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
comparison
equal deleted inserted replaced
46824:57218b7ffb2a 46825:4821cb414a5c
2321 self.loc = b'%s' % u 2321 self.loc = b'%s' % u
2322 2322
2323 self._validate_path() 2323 self._validate_path()
2324 2324
2325 _path, sub_opts = ui.configsuboptions(b'paths', b'*') 2325 _path, sub_opts = ui.configsuboptions(b'paths', b'*')
2326 self._own_sub_opts = {}
2326 if suboptions is not None: 2327 if suboptions is not None:
2328 self._own_sub_opts = suboptions.copy()
2327 sub_opts.update(suboptions) 2329 sub_opts.update(suboptions)
2328 2330 self._all_sub_opts = sub_opts.copy()
2329 # Now process the sub-options. If a sub-option is registered, its 2331
2330 # attribute will always be present. The value will be None if there 2332 self._apply_suboptions(ui, sub_opts)
2331 # was no valid sub-option.
2332 for suboption, (attr, func) in pycompat.iteritems(_pathsuboptions):
2333 if suboption not in sub_opts:
2334 setattr(self, attr, None)
2335 continue
2336
2337 value = func(ui, self, sub_opts[suboption])
2338 setattr(self, attr, value)
2339 2333
2340 def _validate_path(self): 2334 def _validate_path(self):
2341 # When given a raw location but not a symbolic name, validate the 2335 # When given a raw location but not a symbolic name, validate the
2342 # location is valid. 2336 # location is valid.
2343 if ( 2337 if (
2347 ): 2341 ):
2348 raise ValueError( 2342 raise ValueError(
2349 b'location is not a URL or path to a local ' 2343 b'location is not a URL or path to a local '
2350 b'repo: %s' % self.rawloc 2344 b'repo: %s' % self.rawloc
2351 ) 2345 )
2346
2347 def _apply_suboptions(self, ui, sub_options):
2348 # Now process the sub-options. If a sub-option is registered, its
2349 # attribute will always be present. The value will be None if there
2350 # was no valid sub-option.
2351 for suboption, (attr, func) in pycompat.iteritems(_pathsuboptions):
2352 if suboption not in sub_options:
2353 setattr(self, attr, None)
2354 continue
2355
2356 value = func(ui, self, sub_options[suboption])
2357 setattr(self, attr, value)
2352 2358
2353 def _isvalidlocalpath(self, path): 2359 def _isvalidlocalpath(self, path):
2354 """Returns True if the given path is a potentially valid repository. 2360 """Returns True if the given path is a potentially valid repository.
2355 This is its own function so that extensions can change the definition of 2361 This is its own function so that extensions can change the definition of
2356 'valid' in this case (like when pulling from a git repo into a hg 2362 'valid' in this case (like when pulling from a git repo into a hg