[PATCH 10 of 35 V2] context: move __repr__ from changectx

Sean Farley sean.michael.farley at gmail.com
Wed Aug 7 18:51:24 CDT 2013


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1375485848 18000
#      Fri Aug 02 18:24:08 2013 -0500
# Node ID 87f23e37295fe60ad8d1a7faea8621663a897c42
# Parent  01254518b9859d737b30c24db261dd2134db54e0
context: move __repr__ from changectx

We change the hardcoded 'changectx' to instead use type(self).__name__ so that
objects that inherit from context in the future will be able to use the same
representation.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -39,10 +39,13 @@
         return short(self.node())
 
     def __int__(self):
         return self.rev()
 
+    def __repr__(self):
+        return "<%s %s>" % (type(self).__name__, str(self))
+
     def rev(self):
         return self._rev
     def node(self):
         return self._node
     def hex(self):
@@ -151,13 +154,10 @@
         except TypeError:
             pass
         raise error.RepoLookupError(
             _("unknown revision '%s'") % changeid)
 
-    def __repr__(self):
-        return "<changectx %s>" % str(self)
-
     def __hash__(self):
         try:
             return hash(self._rev)
         except AttributeError:
             return id(self)


More information about the Mercurial-devel mailing list