[PATCH 6 of 6 hglib] client: add a convenience method __getitem__ to return a changectx

Idan Kamara idankk86 at gmail.com
Thu Dec 22 11:18:45 CST 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1324573967 -7200
# Node ID bd23bc72e6620cb6fc25df6567bad6ee6a2e1ab2
# Parent  4da6bb8abfcc1b47c50fd24bd65a886ed657674f
client: add a convenience method __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, re
-import hglib, error, util, templates, merge
+import hglib, error, util, templates, merge, context
 
 from util import cmdbuilder
 
@@ -1520,3 +1520,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(ctx.description(), 'first')
         self.assertEquals(str(ctx), node0[:12])
@@ -52,7 +52,7 @@
 
         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'])
 
     def test_construction(self):
         self.append('a', 'a')


More information about the Mercurial-devel mailing list