Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/urlutil.py @ 49851:ffe8dd945f19
path: simplify the implementation of `get_clone_path`
We can simply use the logic from `get_unique_pull_path_obj` now.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 02 Dec 2022 03:56:23 +0100 |
parents | afcf59039b5d |
children | 53ad92b20556 |
comparison
equal
deleted
inserted
replaced
49850:afcf59039b5d | 49851:ffe8dd945f19 |
---|---|
579 """ | 579 """ |
580 path = get_unique_pull_path_obj(action, ui, source=source) | 580 path = get_unique_pull_path_obj(action, ui, source=source) |
581 return parseurl(path.rawloc, default_branches) | 581 return parseurl(path.rawloc, default_branches) |
582 | 582 |
583 | 583 |
584 def get_clone_path(ui, source, default_branches=()): | 584 def get_clone_path(ui, source, default_branches=None): |
585 """return the `(origsource, url, branch)` selected as clone source""" | 585 """return the `(origsource, url, branch)` selected as clone source""" |
586 urls = [] | 586 if default_branches is None: |
587 if source is None: | 587 default_branches = [] |
588 if b'default' in ui.paths: | 588 if source == b'': |
589 urls.extend(p.rawloc for p in ui.paths[b'default']) | 589 return (b'', b'', (None, default_branches)) |
590 else: | 590 path = get_unique_pull_path_obj(b'clone', ui, source=source) |
591 # XXX this is the historical default behavior, but that is not | 591 branches = (path.branch, default_branches) |
592 # great, consider breaking BC on this. | 592 return path.rawloc, path.loc, branches |
593 urls.append(b'default') | |
594 else: | |
595 if source in ui.paths: | |
596 urls.extend(p.rawloc for p in ui.paths[source]) | |
597 else: | |
598 # Try to resolve as a local path or URI. | |
599 path = try_path(ui, source) | |
600 if path is not None: | |
601 urls.append(path.rawloc) | |
602 else: | |
603 urls.append(source) | |
604 if len(urls) != 1: | |
605 if source is None: | |
606 msg = _( | |
607 b"default path points to %d urls while only one is supported" | |
608 ) | |
609 msg %= len(urls) | |
610 else: | |
611 msg = _(b"path points to %d urls while only one is supported: %s") | |
612 msg %= (len(urls), source) | |
613 raise error.Abort(msg) | |
614 url = urls[0] | |
615 clone_path, branch = parseurl(url, default_branches) | |
616 return url, clone_path, branch | |
617 | 593 |
618 | 594 |
619 def parseurl(path, branches=None): | 595 def parseurl(path, branches=None): |
620 '''parse url#branch, returning (url, (branch, branches))''' | 596 '''parse url#branch, returning (url, (branch, branches))''' |
621 u = url(path) | 597 u = url(path) |