comparison mercurial/mdiff.py @ 36655:68026dd7c4f9

cext: accept arguments as Py_buffer The s*/y* value formatters receive a Py_buffer instead of a char *. This value format is more flexible in the types that it allows. We change bdiff() to accept any object that conforms to the buffer protocol. We validate the buffers are contiguous and have a single dimension. This allows memoryview instances to be handled by the function, so we revert a recent change to cast arguments to bytes before calling this function. Differential Revision: https://phab.mercurial-scm.org/D2587
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 03 Mar 2018 11:26:30 -0500
parents edd3974bd500
children c6a61298ac32
comparison
equal deleted inserted replaced
36654:b864f4536ca8 36655:68026dd7c4f9
28 28
29 blocks = bdiff.blocks 29 blocks = bdiff.blocks
30 fixws = bdiff.fixws 30 fixws = bdiff.fixws
31 patches = mpatch.patches 31 patches = mpatch.patches
32 patchedsize = mpatch.patchedsize 32 patchedsize = mpatch.patchedsize
33 _textdiff = bdiff.bdiff 33 textdiff = bdiff.bdiff
34 splitnewlines = bdiff.splitnewlines 34 splitnewlines = bdiff.splitnewlines
35
36 # On Python 3, util.buffer() creates a memoryview, which appears not
37 # supporting the buffer protocol
38 if pycompat.ispy3:
39 def textdiff(a, b):
40 return _textdiff(bytes(a), bytes(b))
41 else:
42 textdiff = _textdiff
43 35
44 class diffopts(object): 36 class diffopts(object):
45 '''context is the number of context lines 37 '''context is the number of context lines
46 text treats all files as text 38 text treats all files as text
47 showfunc enables diff -p output 39 showfunc enables diff -p output