diff hgext/schemes.py @ 49688:f73f02ef8cb6

peer-or-repo: split the scheme between repo and peer Some of the scheme will always produce a peer and some will always produce a repository. So lets use different mapping to reduce the ambiguity.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 29 Nov 2022 21:48:08 +0100
parents 642e31cb55f0
children 1863584f2fba
line wrap: on
line diff
--- a/hgext/schemes.py	Wed Nov 30 13:55:15 2022 +0100
+++ b/hgext/schemes.py	Tue Nov 29 21:48:08 2022 +0100
@@ -136,7 +136,11 @@
                 )
                 % (scheme, scheme.upper())
             )
-        hg.schemes[scheme] = ShortRepository(url, scheme, t)
+        url_scheme = urlutil.url(url).scheme
+        if url_scheme in hg.peer_schemes:
+            hg.peer_schemes[scheme] = ShortRepository(url, scheme, t)
+        else:
+            hg.repo_schemes[scheme] = ShortRepository(url, scheme, t)
 
     extensions.wrapfunction(urlutil, b'hasdriveletter', hasdriveletter)
 
@@ -144,7 +148,11 @@
 @command(b'debugexpandscheme', norepo=True)
 def expandscheme(ui, url, **opts):
     """given a repo path, provide the scheme-expanded path"""
-    repo = hg._peerlookup(url)
-    if isinstance(repo, ShortRepository):
-        url = repo.resolve(url)
+    scheme = urlutil.url(url).scheme
+    if scheme in hg.peer_schemes:
+        cls = hg.peer_schemes[scheme]
+    else:
+        cls = hg.repo_schemes.get(scheme)
+    if cls is not None and isinstance(cls, ShortRepository):
+        url = cls.resolve(url)
     ui.write(url + b'\n')