diff -r c2ef8cc50748 -r e1b4a7a7263a mercurial/patch.py --- a/mercurial/patch.py Thu May 19 22:44:01 2011 +0200 +++ b/mercurial/patch.py Thu May 19 22:44:01 2011 +0200 @@ -1149,22 +1149,23 @@ yield 'file', (afile, bfile, h, gp and gp.mode or None) yield 'hunk', h elif x.startswith('diff --git'): - # check for git diff, scanning the whole patch file if needed m = gitre.match(x) - if m: - if not git: - git = True - gitpatches = scangitpatch(lr, x) - for gp in gitpatches: - 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 - if gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') or gp.mode: - afile = bfile - newfile = True + if not m: + continue + if not git: + # scan whole input for git metadata + git = True + gitpatches = scangitpatch(lr, x) + for gp in gitpatches: + 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 + if gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') or gp.mode: + afile = bfile + newfile = True elif x.startswith('---'): # check for a unified diff l2 = lr.readline()