Patchwork D10440: urlutil: introduce a new `list_paths` function

login
register
mail settings
Submitter phabricator
Date April 16, 2021, 12:03 a.m.
Message ID <differential-rev-PHID-DREV-gxlnouc4j4vuc2x4t5ck-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48757/
State Superseded
Headers show

Comments

phabricator - April 16, 2021, 12:03 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This function will be useful for command and template that wants to display path
  related information.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10440

AFFECTED FILES
  mercurial/utils/urlutil.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py
+++ b/mercurial/utils/urlutil.py
@@ -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