changeset 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 0d5b2e010614
children 1863584f2fba
files hgext/schemes.py mercurial/hg.py
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
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')
--- a/mercurial/hg.py	Wed Nov 30 13:55:15 2022 +0100
+++ b/mercurial/hg.py	Tue Nov 29 21:48:08 2022 +0100
@@ -143,22 +143,28 @@
         return cls.instance(ui, path, *args, **kwargs)
 
 
-schemes = {
+repo_schemes = {
     b'bundle': bundlerepo,
     b'union': unionrepo,
     b'file': LocalFactory,
+    b'static-http': statichttprepo,
+}
+
+peer_schemes = {
     b'http': httppeer,
     b'https': httppeer,
     b'ssh': sshpeer,
-    b'static-http': statichttprepo,
 }
 
 
 def _peerlookup(path):
     u = urlutil.url(path)
     scheme = u.scheme or b'file'
-    thing = schemes.get(scheme) or schemes[b'file']
-    return thing
+    if scheme in peer_schemes:
+        return peer_schemes[scheme]
+    if scheme in repo_schemes:
+        return repo_schemes[scheme]
+    return LocalFactory
 
 
 def islocal(repo):