changeset 49722:f4626b74b941

path: introduce a `get_unique_pull_path_obj` function Unlike the previous one, `get_unique_pull_path`, this function return the `path` object, opening more option for the caller. note that this highlight we don't actually need the `repo` argument to `get_pull_paths`, however changing the API would be annoying for third party extensions.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 02 Dec 2022 03:50:28 +0100
parents 9f249dee8ce8
children 970491e630a5
files mercurial/utils/urlutil.py
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/urlutil.py	Fri Dec 02 01:55:05 2022 +0100
+++ b/mercurial/utils/urlutil.py	Fri Dec 02 03:50:28 2022 +0100
@@ -542,19 +542,22 @@
     return dests[0]
 
 
-def get_unique_pull_path(action, repo, ui, source=None, default_branches=()):
-    """return a unique `(url, branch)` or abort if multiple are found
+def get_unique_pull_path_obj(action, ui, source=None):
+    """return a unique `(path, branch)` or abort if multiple are found
 
     This is useful for command and action that does not support multiple
     destination (yet).
 
     The `action` parameter will be used for the error message.
+
+    note: Ideally, this function would be called `get_unique_pull_path` to
+    mirror the `get_unique_push_path`, but the name was already taken.
     """
     sources = []
     if source is not None:
         sources.append(source)
 
-    pull_paths = list(get_pull_paths(repo, ui, sources=sources))
+    pull_paths = list(get_pull_paths(None, ui, sources=sources))
     path_count = len(pull_paths)
     if path_count != 1:
         if source is None:
@@ -566,7 +569,16 @@
             msg = _(b"path points to %d urls while %s only supports one: %s")
             msg %= (path_count, action, source)
         raise error.Abort(msg)
-    return parseurl(pull_paths[0].rawloc, default_branches)
+    return pull_paths[0]
+
+
+def get_unique_pull_path(action, repo, ui, source=None, default_branches=()):
+    """return a unique `(url, branch)` or abort if multiple are found
+
+    See `get_unique_pull_path_obj` for details.
+    """
+    path = get_unique_pull_path_obj(action, ui, source=source)
+    return parseurl(path.rawloc, default_branches)
 
 
 def get_clone_path(ui, source, default_branches=()):