Patchwork [1,of,4] namespaces: add __getitem__ property

login
register
mail settings
Submitter Sean Farley
Date Jan. 2, 2015, 11:42 p.m.
Message ID <165fc028b31c989af76a.1420242122@laptop.local>
Download mbox | patch
Permalink /patch/7303/
State Accepted
Commit d7324c242c3fd509c7c8dbc8cfca6534ea2251ec
Headers show

Comments

Sean Farley - Jan. 2, 2015, 11:42 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@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.

Patch

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