浏览代码

Fix encode_size

John Carr 16 年之前
父节点
当前提交
99fc97fcbd
共有 1 个文件被更改,包括 12 次插入9 次删除
  1. 12 9
      dulwich/pack.py

+ 12 - 9
dulwich/pack.py

@@ -629,15 +629,18 @@ def create_delta(base_buf, target_buf):
     out_buf = ""
 
     # write delta header
-    def size(l):
-        r = ""
-        while l >= 0x80:
-            r += chr(l | 0x80)
-            l >>= 7
-        r += chr(l)
-        return r
-    out_buf += size(len(base_buf))
-    out_buf += size(len(target_buf))
+    def encode_size(size):
+        ret = ""
+        c = size & 0x7f
+        size >>= 7
+        while size:
+            ret += chr(c | 0x80)
+            c = size & 0x7f
+            size >>= 7
+        ret += chr(c)
+        return ret
+    out_buf += encode_size(len(base_buf))
+    out_buf += encode_size(len(target_buf))
 
     # write out delta opcodes
     seq = difflib.SequenceMatcher(a=base_buf, b=target_buf)