Show More
@@ -113,12 +113,12 b' if modulepolicy not in policynocffi:' | |||||
113 | b = ffi.new("struct bdiff_line**") |
|
113 | b = ffi.new("struct bdiff_line**") | |
114 | ac = ffi.new("char[]", sa) |
|
114 | ac = ffi.new("char[]", sa) | |
115 | bc = ffi.new("char[]", sb) |
|
115 | bc = ffi.new("char[]", sb) | |
|
116 | l = ffi.new("struct bdiff_hunk*") | |||
116 | try: |
|
117 | try: | |
117 | an = lib.bdiff_splitlines(ac, len(sa), a) |
|
118 | an = lib.bdiff_splitlines(ac, len(sa), a) | |
118 | bn = lib.bdiff_splitlines(bc, len(sb), b) |
|
119 | bn = lib.bdiff_splitlines(bc, len(sb), b) | |
119 | if not a[0] or not b[0]: |
|
120 | if not a[0] or not b[0]: | |
120 | raise MemoryError |
|
121 | raise MemoryError | |
121 | l = ffi.new("struct bdiff_hunk*") |
|
|||
122 | count = lib.bdiff_diff(a[0], an, b[0], bn, l) |
|
122 | count = lib.bdiff_diff(a[0], an, b[0], bn, l) | |
123 | if count < 0: |
|
123 | if count < 0: | |
124 | raise MemoryError |
|
124 | raise MemoryError | |
@@ -134,3 +134,36 b' if modulepolicy not in policynocffi:' | |||||
134 | lib.free(b[0]) |
|
134 | lib.free(b[0]) | |
135 | lib.bdiff_freehunks(l.next) |
|
135 | lib.bdiff_freehunks(l.next) | |
136 | return rl |
|
136 | return rl | |
|
137 | ||||
|
138 | def bdiff(sa, sb): | |||
|
139 | a = ffi.new("struct bdiff_line**") | |||
|
140 | b = ffi.new("struct bdiff_line**") | |||
|
141 | ac = ffi.new("char[]", sa) | |||
|
142 | bc = ffi.new("char[]", sb) | |||
|
143 | l = ffi.new("struct bdiff_hunk*") | |||
|
144 | try: | |||
|
145 | an = lib.bdiff_splitlines(ac, len(sa), a) | |||
|
146 | bn = lib.bdiff_splitlines(bc, len(sb), b) | |||
|
147 | if not a[0] or not b[0]: | |||
|
148 | raise MemoryError | |||
|
149 | count = lib.bdiff_diff(a[0], an, b[0], bn, l) | |||
|
150 | if count < 0: | |||
|
151 | raise MemoryError | |||
|
152 | rl = [] | |||
|
153 | h = l.next | |||
|
154 | la = lb = 0 | |||
|
155 | while h: | |||
|
156 | if h.a1 != la or h.b1 != lb: | |||
|
157 | lgt = (b[0] + h.b1).l - (b[0] + lb).l | |||
|
158 | rl.append(struct.pack(">lll", (a[0] + la).l - a[0].l, | |||
|
159 | (a[0] + h.a1).l - a[0].l, lgt)) | |||
|
160 | rl.append(str(ffi.buffer((b[0] + lb).l, lgt))) | |||
|
161 | la = h.a2 | |||
|
162 | lb = h.b2 | |||
|
163 | h = h.next | |||
|
164 | ||||
|
165 | finally: | |||
|
166 | lib.free(a[0]) | |||
|
167 | lib.free(b[0]) | |||
|
168 | lib.bdiff_freehunks(l.next) | |||
|
169 | return "".join(rl) |
General Comments 0
You need to be logged in to leave comments.
Login now