[PATCH 08 of 10] py3: implement __bytes__ for committablectx

Pulkit Goyal 7895pulkit at gmail.com
Wed May 31 17:47:04 EDT 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1496264118 -19800
#      Thu Jun 01 02:25:18 2017 +0530
# Node ID a5498ec51c800ca99be644710b13b0e78a4997b6
# Parent  25320a995bedaaabc4e7a7f40651d07a9bfb4803
py3: implement __bytes__ for committablectx

Before this method, calling bytes on workingctx or memctx calls
basectx.__bytes__ since the magic method was not defined for this class. When it
calls the method from basectx class, it returns TypeError because None is passed
into it.

After this commit `hg update -C` works on Python 3 if eol is not enabled.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -47,7 +47,7 @@
         last, lrev = bin(last), int(lrev)
         filteredhash = None
         if len(cachekey) > 2:
-            filteredhash = bin(cachekey[2])
+            filteredhash = bin(cachekey[2:3][0])
         partial = branchcache(tipnode=last, tiprev=lrev,
                               filteredhash=filteredhash)
         if not partial.validfor(repo):
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1408,6 +1408,9 @@
     def __str__(self):
         return str(self._parents[0]) + r"+"
 
+    def __bytes__(self):
+        return bytes(self._parents[0]) + "+"
+
     def __nonzero__(self):
         return True
 
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -97,7 +97,7 @@
                          (hname, exc.args[0]))
         else:
             ui.warn(_('error: %s hook raised an exception: '
-                           '%s\n') % (hname, exc))
+                           '%s\n') % (hname, pycompat.sysbytes(str(exc))))
         if throw:
             raise
         if not ui.tracebackflag:
diff --git a/tests/test-py3-commands.t b/tests/test-py3-commands.t
--- a/tests/test-py3-commands.t
+++ b/tests/test-py3-commands.t
@@ -118,6 +118,7 @@
   $ $PYTHON3 $HGBIN add iota
   $ $PYTHON3 $HGBIN status
   A iota
+  $ $PYTHON3 $HGBIN diff --nodates
   $ $PYTHON3 $HGBIN commit --message 'commit performed in Python 3'
   $ $PYTHON3 $HGBIN status
 


More information about the Mercurial-devel mailing list