comparison mercurial/cffi/mpatch.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 521ac0d7047f
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
16 16
17 17
18 @ffi.def_extern() 18 @ffi.def_extern()
19 def cffi_get_next_item(arg, pos): 19 def cffi_get_next_item(arg, pos):
20 all, bins = ffi.from_handle(arg) 20 all, bins = ffi.from_handle(arg)
21 container = ffi.new("struct mpatch_flist*[1]") 21 container = ffi.new(b"struct mpatch_flist*[1]")
22 to_pass = ffi.new("char[]", str(bins[pos])) 22 to_pass = ffi.new(b"char[]", str(bins[pos]))
23 all.append(to_pass) 23 all.append(to_pass)
24 r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container) 24 r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container)
25 if r < 0: 25 if r < 0:
26 return ffi.NULL 26 return ffi.NULL
27 return container[0] 27 return container[0]
33 if not lgt: 33 if not lgt:
34 return text 34 return text
35 arg = (all, bins) 35 arg = (all, bins)
36 patch = lib.mpatch_fold(ffi.new_handle(arg), lib.cffi_get_next_item, 0, lgt) 36 patch = lib.mpatch_fold(ffi.new_handle(arg), lib.cffi_get_next_item, 0, lgt)
37 if not patch: 37 if not patch:
38 raise mpatchError("cannot decode chunk") 38 raise mpatchError(b"cannot decode chunk")
39 outlen = lib.mpatch_calcsize(len(text), patch) 39 outlen = lib.mpatch_calcsize(len(text), patch)
40 if outlen < 0: 40 if outlen < 0:
41 lib.mpatch_lfree(patch) 41 lib.mpatch_lfree(patch)
42 raise mpatchError("inconsistency detected") 42 raise mpatchError(b"inconsistency detected")
43 buf = ffi.new("char[]", outlen) 43 buf = ffi.new(b"char[]", outlen)
44 if lib.mpatch_apply(buf, text, len(text), patch) < 0: 44 if lib.mpatch_apply(buf, text, len(text), patch) < 0:
45 lib.mpatch_lfree(patch) 45 lib.mpatch_lfree(patch)
46 raise mpatchError("error applying patches") 46 raise mpatchError(b"error applying patches")
47 res = ffi.buffer(buf, outlen)[:] 47 res = ffi.buffer(buf, outlen)[:]
48 lib.mpatch_lfree(patch) 48 lib.mpatch_lfree(patch)
49 return res 49 return res