patch._applydiff: accept a prefix parameter
authorSiddharth Agarwal <sid0@fb.com>
Fri, 06 Mar 2015 22:22:14 -0800
changeset 24246 394a91cb3d4a
parent 24245 740a17f885a1
child 24247 6e19516094a3
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.
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: