changeset 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 c37287340c00
files hgext/schemes.py
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/schemes.py	Tue Nov 29 21:48:08 2022 +0100
+++ b/hgext/schemes.py	Wed Nov 30 12:22:02 2022 +0100
@@ -119,23 +119,24 @@
 }
 
 
+def _check_drive_letter(scheme):
+    """check if a scheme conflict with a Windows drive letter"""
+    if (
+        pycompat.iswindows
+        and len(scheme) == 1
+        and scheme.isalpha()
+        and os.path.exists(b'%s:\\' % scheme)
+    ):
+        msg = _(b'custom scheme %s:// conflicts with drive letter %s:\\\n')
+        msg %= (scheme, scheme.upper())
+        raise error.Abort(msg)
+
+
 def extsetup(ui):
     schemes.update(dict(ui.configitems(b'schemes')))
     t = templater.engine(templater.parse)
     for scheme, url in schemes.items():
-        if (
-            pycompat.iswindows
-            and len(scheme) == 1
-            and scheme.isalpha()
-            and os.path.exists(b'%s:\\' % scheme)
-        ):
-            raise error.Abort(
-                _(
-                    b'custom scheme %s:// conflicts with drive '
-                    b'letter %s:\\\n'
-                )
-                % (scheme, scheme.upper())
-            )
+        _check_drive_letter(schemes)
         url_scheme = urlutil.url(url).scheme
         if url_scheme in hg.peer_schemes:
             hg.peer_schemes[scheme] = ShortRepository(url, scheme, t)