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