Use line length field when extracting git binary patches
authorBrendan Cully <brendan@kublai.com>
Thu, 12 Oct 2006 13:39:14 -0700
changeset 3374 fd43ff3b4442
parent 3373 9851f46d6ecc
child 3375 58202386deb7
Use line length field when extracting git binary patches
mercurial/patch.py
--- a/mercurial/patch.py	Thu Oct 12 13:24:09 2006 -0700
+++ b/mercurial/patch.py	Thu Oct 12 13:39:14 2006 -0700
@@ -191,18 +191,22 @@
 def dogitpatch(patchname, gitpatches, cwd=None):
     """Preprocess git patch so that vanilla patch can handle it"""
     def extractbin(fp):
-        line = fp.readline()
+        line = fp.readline().rstrip()
         while line and not line.startswith('literal '):
-            line = fp.readline()
+            line = fp.readline().rstrip()
         if not line:
             return
-        size = int(line[8:].rstrip())
+        size = int(line[8:])
         dec = []
-        line = fp.readline()
+        line = fp.readline().rstrip()
         while line:
-            line = line[1:-1]
-            dec.append(base85.b85decode(line))
-            line = fp.readline()
+            l = line[0]
+            if l <= 'Z' and l >= 'A':
+                l = ord(l) - ord('A') + 1
+            else:
+                l = ord(l) - ord('a') + 27
+            dec.append(base85.b85decode(line[1:])[:l])
+            line = fp.readline().rstrip()
         text = zlib.decompress(''.join(dec))
         if len(text) != size:
             raise util.Abort(_('binary patch is %d bytes, not %d') %