diff mercurial/context.py @ 33038:ce96efec8112

py3: add utility to forward __str__() to __bytes__() It calls unifromlocal() instead of sysstr() because __bytes__() may contain locale-dependent values such as paths.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 24 Jun 2017 13:48:04 +0900
parents daccadd75760
children 873f638fd7db
line wrap: on
line diff
--- a/mercurial/context.py	Sat Jun 24 13:20:30 2017 +0900
+++ b/mercurial/context.py	Sat Jun 24 13:48:04 2017 +0900
@@ -65,15 +65,11 @@
 
         return o
 
-    def __str__(self):
-        r = short(self.node())
-        if pycompat.ispy3:
-            return r.decode('ascii')
-        return r
-
     def __bytes__(self):
         return short(self.node())
 
+    __str__ = encoding.strmethod(__bytes__)
+
     def __int__(self):
         return self.rev()
 
@@ -710,17 +706,13 @@
 
     __bool__ = __nonzero__
 
-    def __str__(self):
+    def __bytes__(self):
         try:
             return "%s@%s" % (self.path(), self._changectx)
         except error.LookupError:
             return "%s@???" % self.path()
 
-    def __bytes__(self):
-        try:
-            return "%s@%s" % (self.path(), self._changectx)
-        except error.LookupError:
-            return "%s@???" % self.path()
+    __str__ = encoding.strmethod(__bytes__)
 
     def __repr__(self):
         return "<%s %s>" % (type(self).__name__, str(self))
@@ -1306,12 +1298,11 @@
         if self._extra['branch'] == '':
             self._extra['branch'] = 'default'
 
-    def __str__(self):
-        return str(self._parents[0]) + r"+"
-
     def __bytes__(self):
         return bytes(self._parents[0]) + "+"
 
+    __str__ = encoding.strmethod(__bytes__)
+
     def __nonzero__(self):
         return True