[PATCH 2 of 7 path-configs] ui.paths: teach paths how to iterate

Gregory Szorc gregory.szorc at gmail.com
Sat Feb 7 19:13:38 CST 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1423341730 28800
#      Sat Feb 07 12:42:10 2015 -0800
# Node ID 492682e13efa98be4640530ceed58e1f0b2adf75
# Parent  425462525dc5c44de575084d1516417286c43f51
ui.paths: teach paths how to iterate

paths instances can now iterate over available paths as path
instances.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -937,8 +937,16 @@ class paths(object):
     @property
     def ui(self):
         return self._uiref()
 
+    def __iter__(self):
+        """Iterate all available paths, as ``path`` instances."""
+        for name, loc in self.ui.configitems('paths'):
+            # No URL is the same as not existing.
+            if not loc:
+                continue
+            yield path(name, url=loc)
+
     def getpath(self, name, default=None):
         """Return a ``path`` for the specified name.
 
         Returns None if the specified path or the default path was not


More information about the Mercurial-devel mailing list