# HG changeset patch # User Siddharth Agarwal # Date 1425709334 28800 # 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 -r 740a17f885a1 -r 394a91cb3d4a mercurial/patch.py --- a/mercurial/patch.py Fri Mar 06 22:19:26 2015 -0800 +++ b/mercurial/patch.py Fri Mar 06 22:22:14 2015 -0800 @@ -1366,11 +1366,14 @@ 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 @@ 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: