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

login
register
mail settings
Submitter Sean Farley
Date Aug. 7, 2013, 11:51 p.m.
Message ID <87f23e37295fe60ad8d1.1375919484@laptop.local>
Download mbox | patch
Permalink /patch/2063/
State Accepted
Headers show

Comments

Sean Farley - Aug. 7, 2013, 11:51 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@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.

Patch

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)