urlutil: introduce a new `list_paths` function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 15 Apr 2021 11:46:31 +0200
changeset 47071 c2b5365aa827
parent 47070 9ea75ea23534
child 47072 820fe29d0fd8
urlutil: introduce a new `list_paths` function This function will be useful for command and template that wants to display path related information. Differential Revision: https://phab.mercurial-scm.org/D10440
mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py	Thu Apr 15 10:05:51 2021 +0200
+++ b/mercurial/utils/urlutil.py	Thu Apr 15 11:46:31 2021 +0200
@@ -445,6 +445,18 @@
     return bytes(u)
 
 
+def list_paths(ui, target_path=None):
+    """list all the (name, paths) in the passed ui"""
+    if target_path is None:
+        return sorted(pycompat.iteritems(ui.paths))
+    else:
+        path = ui.paths.get(target_path)
+        if path is None:
+            return []
+        else:
+            return [(target_path, path)]
+
+
 def try_path(ui, url):
     """try to build a path from a url