Mercurial > hg
comparison hgext/schemes.py @ 49689:1863584f2fba
scheme: move the drive letter checking in its own function
This help the readability of the main function as is was taking much more room
than the main logic.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 30 Nov 2022 12:22:02 +0100 |
parents | f73f02ef8cb6 |
children | be3fcd9e5e52 |
comparison
equal
deleted
inserted
replaced
49688:f73f02ef8cb6 | 49689:1863584f2fba |
---|---|
117 b'gcode': b'https://{1}.googlecode.com/hg/', | 117 b'gcode': b'https://{1}.googlecode.com/hg/', |
118 b'kiln': b'https://{1}.kilnhg.com/Repo/', | 118 b'kiln': b'https://{1}.kilnhg.com/Repo/', |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 def _check_drive_letter(scheme): | |
123 """check if a scheme conflict with a Windows drive letter""" | |
124 if ( | |
125 pycompat.iswindows | |
126 and len(scheme) == 1 | |
127 and scheme.isalpha() | |
128 and os.path.exists(b'%s:\\' % scheme) | |
129 ): | |
130 msg = _(b'custom scheme %s:// conflicts with drive letter %s:\\\n') | |
131 msg %= (scheme, scheme.upper()) | |
132 raise error.Abort(msg) | |
133 | |
134 | |
122 def extsetup(ui): | 135 def extsetup(ui): |
123 schemes.update(dict(ui.configitems(b'schemes'))) | 136 schemes.update(dict(ui.configitems(b'schemes'))) |
124 t = templater.engine(templater.parse) | 137 t = templater.engine(templater.parse) |
125 for scheme, url in schemes.items(): | 138 for scheme, url in schemes.items(): |
126 if ( | 139 _check_drive_letter(schemes) |
127 pycompat.iswindows | |
128 and len(scheme) == 1 | |
129 and scheme.isalpha() | |
130 and os.path.exists(b'%s:\\' % scheme) | |
131 ): | |
132 raise error.Abort( | |
133 _( | |
134 b'custom scheme %s:// conflicts with drive ' | |
135 b'letter %s:\\\n' | |
136 ) | |
137 % (scheme, scheme.upper()) | |
138 ) | |
139 url_scheme = urlutil.url(url).scheme | 140 url_scheme = urlutil.url(url).scheme |
140 if url_scheme in hg.peer_schemes: | 141 if url_scheme in hg.peer_schemes: |
141 hg.peer_schemes[scheme] = ShortRepository(url, scheme, t) | 142 hg.peer_schemes[scheme] = ShortRepository(url, scheme, t) |
142 else: | 143 else: |
143 hg.repo_schemes[scheme] = ShortRepository(url, scheme, t) | 144 hg.repo_schemes[scheme] = ShortRepository(url, scheme, t) |