diff mercurial/pure/bdiff.py @ 32545:0e8b0b9a7acc

cffi: split modules from pure The copyright lines are updated per change history. cffi/osutil.py isn't tested since I have no access to OS X machine right now, sorry.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 02 May 2017 21:15:31 +0900
parents 2dcb3d52ef41
children 5326e4ef1dab
line wrap: on
line diff
--- a/mercurial/pure/bdiff.py	Sun May 28 15:45:52 2017 +0900
+++ b/mercurial/pure/bdiff.py	Tue May 02 21:15:31 2017 +0900
@@ -11,10 +11,6 @@
 import re
 import struct
 
-from .. import policy
-policynocffi = policy.policynocffi
-modulepolicy = policy.policy
-
 def splitnewlines(text):
     '''like str.splitlines, but only split on newlines.'''
     lines = [l + '\n' for l in text.split('\n')]
@@ -93,70 +89,3 @@
         text = re.sub('[ \t\r]+', ' ', text)
         text = text.replace(' \n', '\n')
     return text
-
-if modulepolicy not in policynocffi:
-    try:
-        from ..cffi._bdiff import ffi, lib
-    except ImportError:
-        if modulepolicy == 'cffi': # strict cffi import
-            raise
-    else:
-        def blocks(sa, sb):
-            a = ffi.new("struct bdiff_line**")
-            b = ffi.new("struct bdiff_line**")
-            ac = ffi.new("char[]", str(sa))
-            bc = ffi.new("char[]", str(sb))
-            l = ffi.new("struct bdiff_hunk*")
-            try:
-                an = lib.bdiff_splitlines(ac, len(sa), a)
-                bn = lib.bdiff_splitlines(bc, len(sb), b)
-                if not a[0] or not b[0]:
-                    raise MemoryError
-                count = lib.bdiff_diff(a[0], an, b[0], bn, l)
-                if count < 0:
-                    raise MemoryError
-                rl = [None] * count
-                h = l.next
-                i = 0
-                while h:
-                    rl[i] = (h.a1, h.a2, h.b1, h.b2)
-                    h = h.next
-                    i += 1
-            finally:
-                lib.free(a[0])
-                lib.free(b[0])
-                lib.bdiff_freehunks(l.next)
-            return rl
-
-        def bdiff(sa, sb):
-            a = ffi.new("struct bdiff_line**")
-            b = ffi.new("struct bdiff_line**")
-            ac = ffi.new("char[]", str(sa))
-            bc = ffi.new("char[]", str(sb))
-            l = ffi.new("struct bdiff_hunk*")
-            try:
-                an = lib.bdiff_splitlines(ac, len(sa), a)
-                bn = lib.bdiff_splitlines(bc, len(sb), b)
-                if not a[0] or not b[0]:
-                    raise MemoryError
-                count = lib.bdiff_diff(a[0], an, b[0], bn, l)
-                if count < 0:
-                    raise MemoryError
-                rl = []
-                h = l.next
-                la = lb = 0
-                while h:
-                    if h.a1 != la or h.b1 != lb:
-                        lgt = (b[0] + h.b1).l - (b[0] + lb).l
-                        rl.append(struct.pack(">lll", (a[0] + la).l - a[0].l,
-                            (a[0] + h.a1).l - a[0].l, lgt))
-                        rl.append(str(ffi.buffer((b[0] + lb).l, lgt)))
-                    la = h.a2
-                    lb = h.b2
-                    h = h.next
-
-            finally:
-                lib.free(a[0])
-                lib.free(b[0])
-                lib.bdiff_freehunks(l.next)
-            return "".join(rl)