# HG changeset patch # User Pierre-Yves David # Date 2022-12-02 02:50:28 # Node ID f4626b74b9411361072b48c5b09a9b288e6631c6 # Parent 9f249dee8ce8773b7e56cdcb88cae481321dca0e 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. diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py --- a/mercurial/utils/urlutil.py +++ b/mercurial/utils/urlutil.py @@ -542,19 +542,22 @@ def get_unique_push_path(action, repo, u 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 @@ def get_unique_pull_path(action, repo, u 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=()):