|
@@ -648,7 +648,6 @@ def create_delta(base_buf, target_buf):
|
|
|
assert isinstance(base_buf, str)
|
|
|
assert isinstance(target_buf, str)
|
|
|
out_buf = ""
|
|
|
-
|
|
|
|
|
|
def encode_size(size):
|
|
|
ret = ""
|
|
@@ -662,36 +661,29 @@ def create_delta(base_buf, target_buf):
|
|
|
return ret
|
|
|
out_buf += encode_size(len(base_buf))
|
|
|
out_buf += encode_size(len(target_buf))
|
|
|
-
|
|
|
|
|
|
seq = difflib.SequenceMatcher(a=base_buf, b=target_buf)
|
|
|
for opcode, i1, i2, j1, j2 in seq.get_opcodes():
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
if opcode == "equal":
|
|
|
|
|
|
|
|
|
scratch = ""
|
|
|
op = 0x80
|
|
|
-
|
|
|
o = i1
|
|
|
for i in range(4):
|
|
|
if o & 0xff << i*8:
|
|
|
scratch += chr(o >> i)
|
|
|
op |= 1 << i
|
|
|
-
|
|
|
s = i2 - i1
|
|
|
for i in range(2):
|
|
|
if s & 0xff << i*8:
|
|
|
scratch += chr(s >> i)
|
|
|
op |= 1 << (4+i)
|
|
|
-
|
|
|
out_buf += chr(op)
|
|
|
out_buf += scratch
|
|
|
-
|
|
|
-
|
|
|
if opcode == "replace" or opcode == "insert":
|
|
|
|
|
|
|
|
@@ -704,7 +696,6 @@ def create_delta(base_buf, target_buf):
|
|
|
o += 127
|
|
|
out_buf += chr(s)
|
|
|
out_buf += target_buf[o:o+s]
|
|
|
-
|
|
|
return out_buf
|
|
|
|
|
|
|