diff mercurial/patch.py @ 14384:9d59c596eb9e

patch: construct and parse binary hunks at the same time
author Patrick Mezard <pmezard@gmail.com>
date Thu, 19 May 2011 22:44:01 +0200
parents 1bd52cb12a55
children 7709cc983025
line wrap: on
line diff
--- a/mercurial/patch.py	Thu May 19 22:44:01 2011 +0200
+++ b/mercurial/patch.py	Thu May 19 22:44:01 2011 +0200
@@ -960,10 +960,11 @@
 
 class binhunk:
     'A binary patch file. Only understands literals so far.'
-    def __init__(self, gitpatch):
+    def __init__(self, gitpatch, lr):
         self.gitpatch = gitpatch
         self.text = None
         self.hunk = ['GIT binary patch\n']
+        self._read(lr)
 
     def createfile(self):
         return self.gitpatch.op == 'ADD'
@@ -977,7 +978,7 @@
     def new(self):
         return [self.text]
 
-    def extract(self, lr):
+    def _read(self, lr):
         line = lr.readline()
         self.hunk.append(line)
         while line and not line.startswith('literal '):
@@ -1135,8 +1136,7 @@
             or x.startswith('GIT binary patch')):
             gp = changed.get(bfile)
             if x.startswith('GIT binary patch'):
-                h = binhunk(gp)
-                h.extract(lr)
+                h = binhunk(gp, lr)
                 afile = 'a/' + afile
                 bfile = 'b/' + bfile
             else: