Patchwork [5,of,6] patch._applydiff: accept a prefix parameter

login
register
mail settings
Submitter Siddharth Agarwal
Date March 7, 2015, 8:44 a.m.
Message ID <54900e624fe9e04ab32e.1425717887@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7924/
State Accepted
Headers show

Comments

Siddharth Agarwal - March 7, 2015, 8:44 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1425709334 28800
#      Fri Mar 06 22:22:14 2015 -0800
# Node ID 54900e624fe9e04ab32e5edc6d5c7a8729a18132
# Parent  0f2dd88434154fe249607ebe51f6e9a933b38768
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.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -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: