comparison mercurial/hg.py @ 41484:7f366dd3df1f

hg: raise Abort on invalid path Currently, some os.path functions when opening repositories may raise an uncaught TypeError or ValueError if the path is invalid. Let's catch these exceptions and turn them into an Abort for convenience. Differential Revision: https://phab.mercurial-scm.org/D5772
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 30 Jan 2019 17:22:07 -0800
parents bc843e251134
children 2a3c0106ded9
comparison
equal deleted inserted replaced
41483:46ab0c6b28dc 41484:7f366dd3df1f
36 logexchange, 36 logexchange,
37 merge as mergemod, 37 merge as mergemod,
38 narrowspec, 38 narrowspec,
39 node, 39 node,
40 phases, 40 phases,
41 pycompat,
41 repository as repositorymod, 42 repository as repositorymod,
42 scmutil, 43 scmutil,
43 sshpeer, 44 sshpeer,
44 statichttprepo, 45 statichttprepo,
45 ui as uimod, 46 ui as uimod,
55 # shared features 56 # shared features
56 sharedbookmarks = 'bookmarks' 57 sharedbookmarks = 'bookmarks'
57 58
58 def _local(path): 59 def _local(path):
59 path = util.expandpath(util.urllocalpath(path)) 60 path = util.expandpath(util.urllocalpath(path))
60 return (os.path.isfile(path) and bundlerepo or localrepo) 61
62 try:
63 isfile = os.path.isfile(path)
64 # Python 2 raises TypeError, Python 3 ValueError.
65 except (TypeError, ValueError) as e:
66 raise error.Abort(_('invalid path %s: %s') % (
67 path, pycompat.bytestr(e)))
68
69 return isfile and bundlerepo or localrepo
61 70
62 def addbranchrevs(lrepo, other, branches, revs): 71 def addbranchrevs(lrepo, other, branches, revs):
63 peer = other.peer() # a courtesy to callers using a localrepo for other 72 peer = other.peer() # a courtesy to callers using a localrepo for other
64 hashbranch, branches = branches 73 hashbranch, branches = branches
65 if not hashbranch and not branches: 74 if not hashbranch and not branches: