[PATCH 09 of 11] py3: do not pass a memoryview to bdiff.bdiff()

Yuya Nishihara yuya at tcha.org
Sat Mar 3 08:27:42 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1520079865 18000
#      Sat Mar 03 07:24:25 2018 -0500
# Node ID 5e6c27a228b656f730cf0afd70e864ec96fc29c2
# Parent  d02adc818848486b23894e5fea4f632fb56b5aa4
py3: do not pass a memoryview to bdiff.bdiff()

This doesn't look nice, but I don't know how to make a zero-copy slice of
bytes which is compatible with the buffer protocol.

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -30,9 +30,17 @@ blocks = bdiff.blocks
 fixws = bdiff.fixws
 patches = mpatch.patches
 patchedsize = mpatch.patchedsize
-textdiff = bdiff.bdiff
+_textdiff = bdiff.bdiff
 splitnewlines = bdiff.splitnewlines
 
+# On Python 3, util.buffer() creates a memoryview, which appears not
+# supporting the buffer protocol
+if pycompat.ispy3:
+    def textdiff(a, b):
+        return _textdiff(bytes(a), bytes(b))
+else:
+    textdiff = _textdiff
+
 class diffopts(object):
     '''context is the number of context lines
     text treats all files as text


More information about the Mercurial-devel mailing list