comparison mercurial/utils/urlutil.py @ 47284:834f4e9d1af2

multi-urls: add a boolean suboption that unlock path specification as list When this option is set, a list of patch can be specifed as value for `[paths]` entries. For the command who support it, this behave the same as providing multiple destination of the command line. Differential Revision: https://phab.mercurial-scm.org/D10452
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 16 Apr 2021 00:16:47 +0200
parents a671832a8e41
children 9cc9b4a25248
comparison
equal deleted inserted replaced
47283:a671832a8e41 47284:834f4e9d1af2
16 from .. import ( 16 from .. import (
17 encoding, 17 encoding,
18 error, 18 error,
19 pycompat, 19 pycompat,
20 urllibcompat, 20 urllibcompat,
21 )
22
23 from . import (
24 stringutil,
21 ) 25 )
22 26
23 27
24 if pycompat.TYPE_CHECKING: 28 if pycompat.TYPE_CHECKING:
25 from typing import ( 29 from typing import (
637 def __init__(self, ui): 641 def __init__(self, ui):
638 dict.__init__(self) 642 dict.__init__(self)
639 643
640 home_path = os.path.expanduser(b'~') 644 home_path = os.path.expanduser(b'~')
641 645
642 for name, loc in ui.configitems(b'paths', ignoresub=True): 646 for name, value in ui.configitems(b'paths', ignoresub=True):
643 # No location is the same as not existing. 647 # No location is the same as not existing.
644 if not loc: 648 if not value:
645 continue 649 continue
646 _value, sub_opts = ui.configsuboptions(b'paths', name) 650 _value, sub_opts = ui.configsuboptions(b'paths', name)
647 s = ui.configsource(b'paths', name) 651 s = ui.configsource(b'paths', name)
648 root_key = (name, loc, s) 652 root_key = (name, value, s)
649 root = ui._path_to_root.get(root_key, home_path) 653 root = ui._path_to_root.get(root_key, home_path)
650 loc = os.path.expandvars(loc) 654
651 loc = os.path.expanduser(loc) 655 multi_url = sub_opts.get(b'multi-urls')
652 if not hasscheme(loc) and not os.path.isabs(loc): 656 if multi_url is not None and stringutil.parsebool(multi_url):
653 loc = os.path.normpath(os.path.join(root, loc)) 657 base_locs = stringutil.parselist(value)
654 self[name] = [path(ui, name, rawloc=loc, suboptions=sub_opts)] 658 else:
659 base_locs = [value]
660
661 paths = []
662 for loc in base_locs:
663 loc = os.path.expandvars(loc)
664 loc = os.path.expanduser(loc)
665 if not hasscheme(loc) and not os.path.isabs(loc):
666 loc = os.path.normpath(os.path.join(root, loc))
667 p = path(ui, name, rawloc=loc, suboptions=sub_opts)
668 paths.append(p)
669 self[name] = paths
655 670
656 for name, old_paths in sorted(self.items()): 671 for name, old_paths in sorted(self.items()):
657 new_paths = [] 672 new_paths = []
658 for p in old_paths: 673 for p in old_paths:
659 new_paths.extend(_chain_path(p, ui, self)) 674 new_paths.extend(_chain_path(p, ui, self))
746 761
747 762
748 @pathsuboption(b'pushrev', b'pushrev') 763 @pathsuboption(b'pushrev', b'pushrev')
749 def pushrevpathoption(ui, path, value): 764 def pushrevpathoption(ui, path, value):
750 return value 765 return value
766
767
768 @pathsuboption(b'multi-urls', b'multi_urls')
769 def multiurls_pathoption(ui, path, value):
770 res = stringutil.parsebool(value)
771 if res is None:
772 ui.warn(
773 _(b'(paths.%s:multi-urls not a boolean; ignoring)\n') % path.name
774 )
775 res = False
776 return res
751 777
752 778
753 def _chain_path(base_path, ui, paths): 779 def _chain_path(base_path, ui, paths):
754 """return the result of "path://" logic applied on a given path""" 780 """return the result of "path://" logic applied on a given path"""
755 new_paths = [] 781 new_paths = []