# HG changeset patch # User Siddharth Agarwal # Date 2015-03-07 06:22:14 # Node ID 394a91cb3d4a77b135b72e44f9f52e31c88007d1 # Parent 740a17f885a1c81deaa991a2f3969c0153d60c97 patch._applydiff: accept a prefix parameter This is preparation for upcoming patches that will add support for applying a patch within a subdirectory. We normalize the prefix here because this is the main driver -- all code to apply patches is expected to go through here. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1366,11 +1366,14 @@ def applydiff(ui, fp, backend, store, st return _applydiff(ui, fp, patchfile, backend, store, strip=strip, eolmode=eolmode) -def _applydiff(ui, fp, patcher, backend, store, strip=1, +def _applydiff(ui, fp, patcher, backend, store, strip=1, prefix='', eolmode='strict'): + if prefix: + # clean up double slashes, lack of trailing slashes, etc + prefix = util.normpath(prefix) + '/' def pstrip(p): - return pathtransform(p, strip - 1, '')[1] + return pathtransform(p, strip - 1, prefix)[1] rejects = 0 err = 0 @@ -1393,7 +1396,8 @@ def _applydiff(ui, fp, patcher, backend, if gp.oldpath: gp.oldpath = pstrip(gp.oldpath) else: - gp = makepatchmeta(backend, afile, bfile, first_hunk, strip, '') + gp = makepatchmeta(backend, afile, bfile, first_hunk, strip, + prefix) if gp.op == 'RENAME': backend.unlink(gp.oldpath) if not first_hunk: