comparison mercurial/utils/urlutil.py @ 50715:0ab3956540a6

branching: merge stable into default
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 22 Jun 2023 11:28:17 +0200
parents 9e69d9d6f4cf e9c676ad18f1
children 6ca865080479
comparison
equal deleted inserted replaced
50711:e5c1e7aec973 50715:0ab3956540a6
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
689
690
691 def display_bool(value):
692 """display a boolean suboption back to the user"""
693 return b'yes' if value else b'no'
683 694
684 695
685 @pathsuboption(b'pushurl', b'_pushloc') 696 @pathsuboption(b'pushurl', b'_pushloc')
686 def pushurlpathoption(ui, path, value): 697 def pushurlpathoption(ui, path, value):
687 u = url(value) 698 u = url(value)
738 b'default': None, 749 b'default': None,
739 b'try-base': revlog_constants.DELTA_BASE_REUSE_TRY, 750 b'try-base': revlog_constants.DELTA_BASE_REUSE_TRY,
740 b'no-reuse': revlog_constants.DELTA_BASE_REUSE_NO, 751 b'no-reuse': revlog_constants.DELTA_BASE_REUSE_NO,
741 b'forced': revlog_constants.DELTA_BASE_REUSE_FORCE, 752 b'forced': revlog_constants.DELTA_BASE_REUSE_FORCE,
742 } 753 }
743 754 DELTA_REUSE_POLICIES_NAME = dict(i[::-1] for i in DELTA_REUSE_POLICIES.items())
744 755
745 @pathsuboption(b'pulled-delta-reuse-policy', b'delta_reuse_policy') 756
757 @pathsuboption(
758 b'pulled-delta-reuse-policy',
759 b'delta_reuse_policy',
760 display=DELTA_REUSE_POLICIES_NAME.get,
761 )
746 def delta_reuse_policy(ui, path, value): 762 def delta_reuse_policy(ui, path, value):
747 if value not in DELTA_REUSE_POLICIES: 763 if value not in DELTA_REUSE_POLICIES:
748 path_name = path.name 764 path_name = path.name
749 if path_name is None: 765 if path_name is None:
750 # this is an "anonymous" path, config comes from the global one 766 # this is an "anonymous" path, config comes from the global one
755 msg %= (path_name, value) 771 msg %= (path_name, value)
756 ui.warn(msg) 772 ui.warn(msg)
757 return DELTA_REUSE_POLICIES.get(value) 773 return DELTA_REUSE_POLICIES.get(value)
758 774
759 775
760 @pathsuboption(b'multi-urls', b'multi_urls') 776 @pathsuboption(b'multi-urls', b'multi_urls', display=display_bool)
761 def multiurls_pathoption(ui, path, value): 777 def multiurls_pathoption(ui, path, value):
762 res = stringutil.parsebool(value) 778 res = stringutil.parsebool(value)
763 if res is None: 779 if res is None:
764 ui.warn( 780 ui.warn(
765 _(b'(paths.%s:multi-urls not a boolean; ignoring)\n') % path.name 781 _(b'(paths.%s:multi-urls not a boolean; ignoring)\n') % path.name