Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/urlutil.py @ 49834: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 | afcf59039b5d |
comparison
equal
deleted
inserted
replaced
49833:9f249dee8ce8 | 49834:f4626b74b941 |
---|---|
540 msg %= (len(dests), action, dest) | 540 msg %= (len(dests), action, dest) |
541 raise error.Abort(msg) | 541 raise error.Abort(msg) |
542 return dests[0] | 542 return dests[0] |
543 | 543 |
544 | 544 |
545 def get_unique_pull_path(action, repo, ui, source=None, default_branches=()): | 545 def get_unique_pull_path_obj(action, ui, source=None): |
546 """return a unique `(url, branch)` or abort if multiple are found | 546 """return a unique `(path, branch)` or abort if multiple are found |
547 | 547 |
548 This is useful for command and action that does not support multiple | 548 This is useful for command and action that does not support multiple |
549 destination (yet). | 549 destination (yet). |
550 | 550 |
551 The `action` parameter will be used for the error message. | 551 The `action` parameter will be used for the error message. |
552 | |
553 note: Ideally, this function would be called `get_unique_pull_path` to | |
554 mirror the `get_unique_push_path`, but the name was already taken. | |
552 """ | 555 """ |
553 sources = [] | 556 sources = [] |
554 if source is not None: | 557 if source is not None: |
555 sources.append(source) | 558 sources.append(source) |
556 | 559 |
557 pull_paths = list(get_pull_paths(repo, ui, sources=sources)) | 560 pull_paths = list(get_pull_paths(None, ui, sources=sources)) |
558 path_count = len(pull_paths) | 561 path_count = len(pull_paths) |
559 if path_count != 1: | 562 if path_count != 1: |
560 if source is None: | 563 if source is None: |
561 msg = _( | 564 msg = _( |
562 b"default path points to %d urls while %s only supports one" | 565 b"default path points to %d urls while %s only supports one" |
564 msg %= (path_count, action) | 567 msg %= (path_count, action) |
565 else: | 568 else: |
566 msg = _(b"path points to %d urls while %s only supports one: %s") | 569 msg = _(b"path points to %d urls while %s only supports one: %s") |
567 msg %= (path_count, action, source) | 570 msg %= (path_count, action, source) |
568 raise error.Abort(msg) | 571 raise error.Abort(msg) |
569 return parseurl(pull_paths[0].rawloc, default_branches) | 572 return pull_paths[0] |
573 | |
574 | |
575 def get_unique_pull_path(action, repo, ui, source=None, default_branches=()): | |
576 """return a unique `(url, branch)` or abort if multiple are found | |
577 | |
578 See `get_unique_pull_path_obj` for details. | |
579 """ | |
580 path = get_unique_pull_path_obj(action, ui, source=source) | |
581 return parseurl(path.rawloc, default_branches) | |
570 | 582 |
571 | 583 |
572 def get_clone_path(ui, source, default_branches=()): | 584 def get_clone_path(ui, source, default_branches=()): |
573 """return the `(origsource, path, branch)` selected as clone source""" | 585 """return the `(origsource, path, branch)` selected as clone source""" |
574 urls = [] | 586 urls = [] |