[PATCH 3 of 3 hglib] client: add __getitem__ to return a changectx

Idan Kamara idankk86 at gmail.com
Sat Oct 15 14:47:47 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1318708041 -7200
# Node ID 874d53693c8dfd2f245bb58df30dcd31f191c140
# Parent  be88c3cb597f4368903b6641c9e874eb8eb0b6a0
client: add __getitem__ to return a changectx

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -1,5 +1,5 @@
 import subprocess, os, struct, cStringIO, collections, re
-import hglib, error, util, templates, merge
+import hglib, error, util, templates, merge, context
 
 from util import cmdbuilder
 
@@ -1474,3 +1474,6 @@
             self._version = tuple(v)
 
         return self._version
+
+    def __getitem__(self, changeid):
+        return context.changectx(self, changeid)
diff --git a/tests/test-context.py b/tests/test-context.py
--- a/tests/test-context.py
+++ b/tests/test-context.py
@@ -13,7 +13,7 @@
         self.append('c', 'c')
         rev1, node1 = self.client.commit('second', addremove=True)
 
-        ctx = context.changectx(self.client, node0)
+        ctx = self.client[node0]
 
         self.assertEquals(str(ctx), node0[:12])
         self.assertEquals(ctx.node, node0)
@@ -50,4 +50,4 @@
 
         self.client.tag('tag', rev=node0)
         # tags are read on construction
-        self.assertEquals(context.changectx(self.client, node0).tags, ['tag'])
+        self.assertEquals(self.client[node0].tags, ['tag'])


More information about the Mercurial-devel mailing list