changeset 49739:ffe8dd945f19

path: simplify the implementation of `get_clone_path` We can simply use the logic from `get_unique_pull_path_obj` now.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 02 Dec 2022 03:56:23 +0100
parents afcf59039b5d
children 53ad92b20556
files mercurial/utils/urlutil.py
diffstat 1 files changed, 8 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/urlutil.py	Fri Dec 02 03:51:27 2022 +0100
+++ b/mercurial/utils/urlutil.py	Fri Dec 02 03:56:23 2022 +0100
@@ -581,39 +581,15 @@
     return parseurl(path.rawloc, default_branches)
 
 
-def get_clone_path(ui, source, default_branches=()):
+def get_clone_path(ui, source, default_branches=None):
     """return the `(origsource, url, branch)` selected as clone source"""
-    urls = []
-    if source is None:
-        if b'default' in ui.paths:
-            urls.extend(p.rawloc for p in ui.paths[b'default'])
-        else:
-            # XXX this is the historical default behavior, but that is not
-            # great, consider breaking BC on this.
-            urls.append(b'default')
-    else:
-        if source in ui.paths:
-            urls.extend(p.rawloc for p in ui.paths[source])
-        else:
-            # Try to resolve as a local path or URI.
-            path = try_path(ui, source)
-            if path is not None:
-                urls.append(path.rawloc)
-            else:
-                urls.append(source)
-    if len(urls) != 1:
-        if source is None:
-            msg = _(
-                b"default path points to %d urls while only one is supported"
-            )
-            msg %= len(urls)
-        else:
-            msg = _(b"path points to %d urls while only one is supported: %s")
-            msg %= (len(urls), source)
-        raise error.Abort(msg)
-    url = urls[0]
-    clone_path, branch = parseurl(url, default_branches)
-    return url, clone_path, branch
+    if default_branches is None:
+        default_branches = []
+    if source == b'':
+        return (b'', b'', (None, default_branches))
+    path = get_unique_pull_path_obj(b'clone', ui, source=source)
+    branches = (path.branch, default_branches)
+    return path.rawloc, path.loc, branches
 
 
 def parseurl(path, branches=None):