comparison mercurial/utils/urlutil.py @ 50401:9d4a2ea3dcb9 stable

paths: add an argument to format the suboption display We will use it in the next function to the delta policy display. It could also be use to deal with the other special case in the command code, but that is unnecessary churn for stable so that part will go on default.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 15 Jun 2023 09:50:46 +0200
parents f35cf52acabd
children c96fd53c0e2d
comparison
equal deleted inserted replaced
50400:ba602ddcb296 50401:9d4a2ea3dcb9
656 new_paths.extend(_chain_path(p, ui, self)) 656 new_paths.extend(_chain_path(p, ui, self))
657 self[name] = new_paths 657 self[name] = new_paths
658 658
659 659
660 _pathsuboptions = {} 660 _pathsuboptions = {}
661 661 # a dictionnary of methods that can be used to format a sub-option value
662 662 path_suboptions_display = {}
663 def pathsuboption(option, attr): 663
664
665 def pathsuboption(option, attr, display=pycompat.bytestr):
664 """Decorator used to declare a path sub-option. 666 """Decorator used to declare a path sub-option.
665 667
666 Arguments are the sub-option name and the attribute it should set on 668 Arguments are the sub-option name and the attribute it should set on
667 ``path`` instances. 669 ``path`` instances.
668 670
669 The decorated function will receive as arguments a ``ui`` instance, 671 The decorated function will receive as arguments a ``ui`` instance,
670 ``path`` instance, and the string value of this option from the config. 672 ``path`` instance, and the string value of this option from the config.
671 The function should return the value that will be set on the ``path`` 673 The function should return the value that will be set on the ``path``
672 instance. 674 instance.
673 675
676 The optional `display` argument is a function that can be used to format
677 the value when displayed to the user (like in `hg paths` for example).
678
674 This decorator can be used to perform additional verification of 679 This decorator can be used to perform additional verification of
675 sub-options and to change the type of sub-options. 680 sub-options and to change the type of sub-options.
676 """ 681 """
677 682
678 def register(func): 683 def register(func):
679 _pathsuboptions[option] = (attr, func) 684 _pathsuboptions[option] = (attr, func)
685 path_suboptions_display[option] = display
680 return func 686 return func
681 687
682 return register 688 return register
683 689
684 690