# HG changeset patch # User Pierre-Yves David # Date 2023-06-15 07:50:46 # Node ID 9d4a2ea3dcb961ea7d30aca3e09d01c9678a1116 # Parent ba602ddcb29667ae00c64507b850f3e8622a145b 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5219,7 +5219,9 @@ def paths(ui, repo, search=None, **opts) value = b'yes' else: value = b'no' - fm.condwrite(showsubopts, subopt, b'%s\n', pycompat.bytestr(value)) + display = urlutil.path_suboptions_display[subopt] + value = display(value) + fm.condwrite(showsubopts, subopt, b'%s\n', value) fm.end() diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py --- a/mercurial/utils/urlutil.py +++ b/mercurial/utils/urlutil.py @@ -658,9 +658,11 @@ class paths(dict): _pathsuboptions = {} +# a dictionnary of methods that can be used to format a sub-option value +path_suboptions_display = {} -def pathsuboption(option, attr): +def pathsuboption(option, attr, display=pycompat.bytestr): """Decorator used to declare a path sub-option. Arguments are the sub-option name and the attribute it should set on @@ -671,12 +673,16 @@ def pathsuboption(option, attr): The function should return the value that will be set on the ``path`` instance. + The optional `display` argument is a function that can be used to format + the value when displayed to the user (like in `hg paths` for example). + This decorator can be used to perform additional verification of sub-options and to change the type of sub-options. """ def register(func): _pathsuboptions[option] = (attr, func) + path_suboptions_display[option] = display return func return register