[PATCH 1 of 4] namespaces: add __getitem__ property

Sean Farley sean.michael.farley at gmail.com
Fri Jan 2 23:42:02 UTC 2015


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1419198992 28800
#      Sun Dec 21 13:56:32 2014 -0800
# Node ID 165fc028b31c989af76a944c5ecfbbbb19579629
# Parent  42908c3275c63b7d2d6c871094c1e2c8f7ba31c8
namespaces: add __getitem__ property

Since the namespaces object uses an underlying (sorted) dictionary to store the
namespaces, it makes sense to expose this to naturally gain access to those
namespaces.

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -40,10 +40,14 @@ class namespaces(object):
         n = ns("branches", "branch",
                lambda repo, name: tolist(repo.branchtip(name)),
                lambda repo, node: [repo[node].branch()])
         self.addnamespace(n)
 
+    def __getitem__(self, namespace):
+        """returns the namespace object"""
+        return self._names[namespace]
+
     def addnamespace(self, namespace, order=None):
         """register a namespace
 
         namespace: the name to be registered (in plural form)
         order: optional argument to specify the order of namespaces


More information about the Mercurial-devel mailing list