From patchwork Fri Jan 2 23:42:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,4] namespaces: add __getitem__ property From: Sean Farley X-Patchwork-Id: 7303 Message-Id: <165fc028b31c989af76a.1420242122@laptop.local> To: mercurial-devel@selenic.com Date: Fri, 02 Jan 2015 15:42:02 -0800 # HG changeset patch # User Sean Farley # 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