changeset 50692: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 ba602ddcb296
children c96fd53c0e2d
files mercurial/commands.py mercurial/utils/urlutil.py
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Jun 09 14:32:09 2023 +0100
+++ b/mercurial/commands.py	Thu Jun 15 09:50:46 2023 +0200
@@ -5219,7 +5219,9 @@
                     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()
 
--- a/mercurial/utils/urlutil.py	Fri Jun 09 14:32:09 2023 +0100
+++ b/mercurial/utils/urlutil.py	Thu Jun 15 09:50:46 2023 +0200
@@ -658,9 +658,11 @@
 
 
 _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 @@
     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