# HG changeset patch # User Pierre-Yves David # Date 1618394240 -7200 # Node ID 368294967c9532721c9b448fbe419bdb832e9d88 # Parent b133154f1e7ba2fbb5a07df6cc1a4671dac1e275 urlutil: add a new `get_unique_push_path` This function is dedicated to call that needs a single destination. Currently most caller actually need that since few actually support multiple destinations (the most importants `hg push` and `hg outgoing` do). So having a clear API point for that will be important when the time comes to have a single `[paths]` alias resolving to multiple urls. Differential Revision: https://phab.mercurial-scm.org/D10407 diff -r b133154f1e7b -r 368294967c95 mercurial/utils/urlutil.py --- a/mercurial/utils/urlutil.py Wed Apr 14 11:38:10 2021 +0200 +++ b/mercurial/utils/urlutil.py Wed Apr 14 11:57:20 2021 +0200 @@ -471,6 +471,25 @@ yield parseurl(url, default_branches) +def get_unique_push_path(action, repo, ui, dest=None): + """return a unique `path` or abort if multiple are found + + This is useful for command and action that does not support multiple + destination (yet). + + Note that for now, we cannot get multiple destination so this function is "trivial". + + The `action` parameter will be used for the error message. + """ + if dest is None: + dests = [] + else: + dests = [dest] + dests = list(get_push_paths(repo, ui, dests)) + assert len(dests) == 1 + return dests[0] + + def get_unique_pull_path(action, repo, ui, source=None, default_branches=()): """return a unique `(path, branch)` or abort if multiple are found