comparison mercurial/ui.py @ 46824:57218b7ffb2a

path: extract the path validation logic into its own submethod 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/D10261
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 21 Mar 2021 17:52:15 +0100
parents f1f2961d2816
children 4821cb414a5c
comparison
equal deleted inserted replaced
46823:f1f2961d2816 46824:57218b7ffb2a
2318 2318
2319 self.name = name 2319 self.name = name
2320 self.rawloc = rawloc 2320 self.rawloc = rawloc
2321 self.loc = b'%s' % u 2321 self.loc = b'%s' % u
2322 2322
2323 # When given a raw location but not a symbolic name, validate the 2323 self._validate_path()
2324 # location is valid.
2325 if not name and not u.scheme and not self._isvalidlocalpath(self.loc):
2326 raise ValueError(
2327 b'location is not a URL or path to a local '
2328 b'repo: %s' % rawloc
2329 )
2330 2324
2331 _path, sub_opts = ui.configsuboptions(b'paths', b'*') 2325 _path, sub_opts = ui.configsuboptions(b'paths', b'*')
2332 if suboptions is not None: 2326 if suboptions is not None:
2333 sub_opts.update(suboptions) 2327 sub_opts.update(suboptions)
2334 2328
2340 setattr(self, attr, None) 2334 setattr(self, attr, None)
2341 continue 2335 continue
2342 2336
2343 value = func(ui, self, sub_opts[suboption]) 2337 value = func(ui, self, sub_opts[suboption])
2344 setattr(self, attr, value) 2338 setattr(self, attr, value)
2339
2340 def _validate_path(self):
2341 # When given a raw location but not a symbolic name, validate the
2342 # location is valid.
2343 if (
2344 not self.name
2345 and not self.url.scheme
2346 and not self._isvalidlocalpath(self.loc)
2347 ):
2348 raise ValueError(
2349 b'location is not a URL or path to a local '
2350 b'repo: %s' % self.rawloc
2351 )
2345 2352
2346 def _isvalidlocalpath(self, path): 2353 def _isvalidlocalpath(self, path):
2347 """Returns True if the given path is a potentially valid repository. 2354 """Returns True if the given path is a potentially valid repository.
2348 This is its own function so that extensions can change the definition of 2355 This is its own function so that extensions can change the definition of
2349 'valid' in this case (like when pulling from a git repo into a hg 2356 'valid' in this case (like when pulling from a git repo into a hg