# HG changeset patch # User Patrick Mezard # Date 2011-05-19 20:44:01 # Node ID 9d59c596eb9e2e1f115c3f54584860607cb28b9b # Parent 1bd52cb12a5521ee0f05854d0cdda31039c16adb patch: construct and parse binary hunks at the same time diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -960,10 +960,11 @@ class hunk(object): 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 @@ class binhunk: 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 @@ def iterhunks(fp): 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: