urlutil: add a `get_clone_path` function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 14 Apr 2021 10:35:40 +0200
changeset 46934 ebb13f9a9ba8
parent 46933 9519312ecd81
child 46935 ae4c0f279282
urlutil: add a `get_clone_path` function We add a new function with a semantic focussed on `clone` operation (so without an existing repository). I am not certain the return type is the best, but this is what we need for now. Once all caller are migrated we might start thinking about that the API should be. For now that will do. Differential Revision: https://phab.mercurial-scm.org/D10401
mercurial/hg.py
mercurial/utils/urlutil.py
--- a/mercurial/hg.py	Sun Apr 11 19:18:54 2021 +0200
+++ b/mercurial/hg.py	Wed Apr 14 10:35:40 2021 +0200
@@ -672,8 +672,8 @@
     """
 
     if isinstance(source, bytes):
-        origsource = ui.expandpath(source)
-        source, branches = urlutil.parseurl(origsource, branch)
+        src = urlutil.get_clone_path(ui, source, branch)
+        origsource, source, branches = src
         srcpeer = peer(ui, peeropts, source)
     else:
         srcpeer = source.peer()  # in case we were called with a localrepo
--- a/mercurial/utils/urlutil.py	Sun Apr 11 19:18:54 2021 +0200
+++ b/mercurial/utils/urlutil.py	Wed Apr 14 10:35:40 2021 +0200
@@ -471,6 +471,13 @@
         yield parseurl(url, default_branches)
 
 
+def get_clone_path(ui, source, default_branches=()):
+    """return the `(origsource, path, branch)` selected as clone source"""
+    url = ui.expandpath(source)
+    path, branch = parseurl(url, default_branches)
+    return url, path, branch
+
+
 def parseurl(path, branches=None):
     '''parse url#branch, returning (url, (branch, branches))'''
     u = url(path)