path: simplify the `get_unique_pull_path` function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 02 Dec 2022 01:55:05 +0100
changeset 49721 9f249dee8ce8
parent 49720 bcb172e360d0
child 49722 f4626b74b941
path: simplify the `get_unique_pull_path` function Simply delegate the search to `get_pull_paths` and check how many we got.
mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py	Fri Dec 02 01:41:27 2022 +0100
+++ b/mercurial/utils/urlutil.py	Fri Dec 02 01:55:05 2022 +0100
@@ -550,35 +550,23 @@
 
     The `action` parameter will be used for the error message.
     """
-    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:
+    sources = []
+    if source is not None:
+        sources.append(source)
+
+    pull_paths = list(get_pull_paths(repo, ui, sources=sources))
+    path_count = len(pull_paths)
+    if path_count != 1:
         if source is None:
             msg = _(
                 b"default path points to %d urls while %s only supports one"
             )
-            msg %= (len(urls), action)
+            msg %= (path_count, action)
         else:
             msg = _(b"path points to %d urls while %s only supports one: %s")
-            msg %= (len(urls), action, source)
+            msg %= (path_count, action, source)
         raise error.Abort(msg)
-    return parseurl(urls[0], default_branches)
+    return parseurl(pull_paths[0].rawloc, default_branches)
 
 
 def get_clone_path(ui, source, default_branches=()):