# HG changeset patch # User Patrick Mezard # Date 1224366346 -7200 # Node ID 353141d74ca87258361ee8c3e6c970efe8d06b5f # Parent f0055cec8446ac2eb5ee8b64dbac8019da60c52f patch: pass linereader to binaryhunk.extract() instead of wrapped fp It unifies input patch file access methods diff -r f0055cec8446 -r 353141d74ca8 mercurial/patch.py --- a/mercurial/patch.py Sat Oct 18 23:45:46 2008 +0200 +++ b/mercurial/patch.py Sat Oct 18 23:45:46 2008 +0200 @@ -669,17 +669,17 @@ def new(self): return [self.text] - def extract(self, fp): - line = fp.readline() + def extract(self, lr): + line = lr.readline() self.hunk.append(line) while line and not line.startswith('literal '): - line = fp.readline() + line = lr.readline() self.hunk.append(line) if not line: raise PatchError(_('could not extract binary patch')) size = int(line[8:].rstrip()) dec = [] - line = fp.readline() + line = lr.readline() self.hunk.append(line) while len(line) > 1: l = line[0] @@ -688,7 +688,7 @@ else: l = ord(l) - ord('a') + 27 dec.append(base85.b85decode(line[1:-1])[:l]) - line = fp.readline() + line = lr.readline() self.hunk.append(line) text = zlib.decompress(''.join(dec)) if len(text) != size: @@ -806,7 +806,7 @@ gitlr.push(firstline) (dopatch, gitpatches) = readgitpatch(gitlr) fp.seek(pos) - return fp, dopatch, gitpatches + return dopatch, gitpatches def iterhunks(ui, fp, sourcefile=None): """Read a patch and yield the following events: @@ -871,7 +871,7 @@ if emitfile: emitfile = False yield 'file', (afile, bfile, current_hunk) - current_hunk.extract(fp) + current_hunk.extract(lr) elif x.startswith('diff --git'): # check for git diff, scanning the whole patch file if needed m = gitre.match(x) @@ -879,7 +879,7 @@ afile, bfile = m.group(1, 2) if not git: git = True - fp, dopatch, gitpatches = scangitpatch(lr, x) + dopatch, gitpatches = scangitpatch(lr, x) yield 'git', gitpatches for gp in gitpatches: changed[gp.path] = gp