context: add __int__ and hex methods
authorMatt Mackall <mpm@selenic.com>
Fri, 27 Jun 2008 18:44:43 -0500
changeset 6763 403682f1c678
parent 6762 f67d1468ac50
child 6764 8db64464d136
context: add __int__ and hex methods
mercurial/context.py
--- a/mercurial/context.py	Fri Jun 27 18:28:45 2008 -0500
+++ b/mercurial/context.py	Fri Jun 27 18:44:43 2008 -0500
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-from node import nullid, nullrev, short
+from node import nullid, nullrev, short, hex
 from i18n import _
 import ancestor, bdiff, revlog, util, os, errno
 
@@ -23,6 +23,9 @@
     def __str__(self):
         return short(self.node())
 
+    def __int__(self):
+        return self.rev()
+
     def __repr__(self):
         return "<changectx %s>" % str(self)
 
@@ -79,6 +82,7 @@
 
     def rev(self): return self._rev
     def node(self): return self._node
+    def hex(self): return hex(self._node)
     def user(self): return self._changeset[1]
     def date(self): return self._changeset[2]
     def files(self): return self._changeset[3]
@@ -693,6 +697,9 @@
     def __str__(self):
         return str(self._parents[0]) + "+"
 
+    def __int__(self):
+        return self._rev
+
     def __nonzero__(self):
         return True