Mercurial > hg-stable
changeset 14392:bb5cbc16349e
patch: fast-path git case in selectfile()
We avoid a lot of complicated heuristics in git cases, where these heurestics
may even be broken when copies are involved.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 19 May 2011 22:55:13 +0200 |
parents | 1e64e1e12195 |
children | bdf44e63a94c |
files | mercurial/patch.py |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Thu May 19 22:49:43 2011 +0200 +++ b/mercurial/patch.py Thu May 19 22:55:13 2011 +0200 @@ -1025,7 +1025,13 @@ count -= 1 return path[:i].lstrip(), path[i:].rstrip() -def selectfile(backend, afile_orig, bfile_orig, hunk, strip): +def selectfile(backend, afile_orig, bfile_orig, hunk, strip, gp): + if gp: + # Git patches do not play games. Excluding copies from the + # following heuristic avoids a lot of confusion + fname = pathstrip(gp.path, strip - 1)[1] + missing = not hunk.createfile() and not backend.exists(fname) + return fname, missing nulla = afile_orig == "/dev/null" nullb = bfile_orig == "/dev/null" abase, afile = pathstrip(afile_orig, strip) @@ -1255,7 +1261,7 @@ try: mode = gp and gp.mode or None current_file, missing = selectfile(backend, afile, bfile, - first_hunk, strip) + first_hunk, strip, gp) current_file = patcher(ui, current_file, backend, mode, missing=missing, eolmode=eolmode) except PatchError, inst: @@ -1391,7 +1397,7 @@ if not first_hunk: continue current_file, missing = selectfile(backend, afile, bfile, - first_hunk, strip) + first_hunk, strip, gp) changed.add(current_file) elif state not in ('hunk', 'git'): raise util.Abort(_('unsupported parser state: %s') % state)