patch: unify iterhunks() afile/bfile handling
git afile/bfile are extracted twice, once when reading a 'diff --git', and
again when reading a unified hunk. The problem is not all git blocks have
unified hunks (renames just have metadata) and they were not extracted the same
way. This is what this patch unifies.
--- a/mercurial/patch.py Thu May 19 22:44:01 2011 +0200
+++ b/mercurial/patch.py Thu May 19 22:44:01 2011 +0200
@@ -1137,8 +1137,6 @@
gp = changed.get(bfile)
if x.startswith('GIT binary patch'):
h = binhunk(gp, lr)
- afile = 'a/' + afile
- bfile = 'b/' + bfile
else:
if context is None and x.startswith('***************'):
context = True
@@ -1154,15 +1152,16 @@
# check for git diff, scanning the whole patch file if needed
m = gitre.match(x)
if m:
- afile, bfile = m.group(1, 2)
if not git:
git = True
gitpatches = scangitpatch(lr, x)
for gp in gitpatches:
- changed[gp.path] = gp
+ changed['b/' + gp.path] = gp
yield 'git', gitpatches
+ afile = 'a/' + m.group(1)
+ bfile = 'b/' + m.group(2)
+ gp = changed[bfile]
# copy/rename + modify should modify target, not source
- gp = changed[bfile]
if gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') or gp.mode:
afile = bfile
newfile = True